-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewer.c
50 lines (38 loc) · 1.01 KB
/
viewer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <malloc.h>
#include <SDL/SDL.h>
#include "imgproc.h"
Viewer * viewOpen(unsigned int width, unsigned int height, const char * title)
{
// set up the view
Viewer * view = malloc(sizeof(*view));
if(view == NULL){
fprintf(stderr, "Could not allocate memory for view\n");
return NULL;
}
// initialise the screen surface
view->screen = SDL_SetVideoMode(width, height, 24, SDL_SWSURFACE);
if(view == NULL){
fprintf(stderr, "Failed to open screen surface\n");
free(view);
return NULL;
}
// set the window title
SDL_WM_SetCaption(title, 0);
// return the completed view object
return view;
}
void viewClose(Viewer * view)
{
// free the screen surface
SDL_FreeSurface(view->screen);
// free the view container
free(view);
}
// take an image and display it on the view
void viewDisplayImage(Viewer * view, Image * img)
{
// Blit the image to the window surface
SDL_BlitSurface(img->sdl_surface, NULL, view->screen, NULL);
// Flip the screen to display the changes
SDL_Flip(view->screen);
}