Implement a new function to get a new image based on the original
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 12 Aug 2008 09:02:37 +0000 (06:02 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 12 Aug 2008 09:02:37 +0000 (06:02 -0300)
This function will make it easier to simply overload it with a function
that scales the slices.

movie.c

diff --git a/movie.c b/movie.c
index f5ef008..9a0d883 100644 (file)
--- 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 &rect;
+  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, &center, 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 ();