From: Thadeu Lima de Souza Cascardo Date: Tue, 12 Aug 2008 09:02:37 +0000 (-0300) Subject: Implement a new function to get a new image based on the original X-Git-Tag: cairo~1 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fmovie.git;a=commitdiff_plain;h=ad00f749d05eb4c54d160df40121aa5e263999d5 Implement a new function to get a new image based on the original This function will make it easier to simply overload it with a function that scales the slices. --- diff --git a/movie.c b/movie.c index f5ef008..9a0d883 100644 --- a/movie.c +++ b/movie.c @@ -60,7 +60,7 @@ ReadPoints (char *filename) fclose (file); } -SDL_Rect * +SDL_Rect GetNextPoint (void) { static SDL_Rect rect = {0, 0, WIDTH, HEIGHT}; @@ -101,16 +101,35 @@ GetNextPoint (void) err -= ABS (thre); y += (inc < 0) ? -1 : 1; } - return ▭ + return rect; } void -ShowPoint (SDL_Surface *screen, SDL_Surface *image, SDL_Rect *rect) +ShowPoint (SDL_Surface *screen, SDL_Surface *image) { - SDL_BlitSurface (image, rect, screen, NULL); + SDL_BlitSurface (image, NULL, screen, NULL); SDL_UpdateRect (screen, 0, 0, 0, 0); } +SDL_Surface * +GetNextImage (SDL_Surface *image) +{ + SDL_Surface *slice; + SDL_Rect center; + center = GetNextPoint (), GetNextPoint (), GetNextPoint (); + slice = SDL_CreateRGBSurface (SDL_SWSURFACE, WIDTH, HEIGHT, + image->format->BitsPerPixel, + image->format->Rmask, + image->format->Gmask, + image->format->Bmask, + image->format->Amask); + center.x -= WIDTH/2; + center.y -= HEIGHT/2; + SDL_BlitSurface (image, ¢er, slice, NULL); + SDL_UpdateRect (slice, 0, 0, 0, 0); + return slice; +} + Uint32 ShowNext (Uint32 interval, void *data) { @@ -126,6 +145,7 @@ main (int argc, char **argv) { SDL_Surface *screen; SDL_Surface *image; + SDL_Surface *slice; SDL_Event event; ReadPoints ("pro-gnu"); SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER); @@ -137,7 +157,11 @@ main (int argc, char **argv) if (event.type == SDL_KEYDOWN) break; else if (event.type == SDL_USEREVENT) - ShowPoint (screen, image, GetNextPoint ()); + { + slice = GetNextImage (image); + ShowPoint (screen, slice); + SDL_FreeSurface (slice); + } } SDL_FreeSurface (image); SDL_Quit ();