Change scale to four, since the new picture requires it
[cascardo/movie.git] / movie.c
diff --git a/movie.c b/movie.c
index 71fb01d..22a9f92 100644 (file)
--- a/movie.c
+++ b/movie.c
@@ -21,8 +21,9 @@
 #define HBORDER 32
 #define VBORDER 8
 
-#define STOP_INTERVAL (5*1000)
-#define FPS (4)
+#define STOP_INTERVAL (2*1000)
+#define FPS (100)
+#define FRAME_INTERVAL (1000/(FPS))
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -165,7 +166,7 @@ CairoTarget (SDL_Surface *image)
     surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32,
                                                   WIDTH, HEIGHT, WIDTH * 4);
     ctx = cairo_create (surface);
-    cairo_scale (ctx, 2, 2);
+    cairo_scale (ctx, 4, 4);
   }
   source = CairoFromSDL (image);
   cairo_set_source_surface (ctx, source, 0, 0);
@@ -183,14 +184,14 @@ GetNextImage (SDL_Surface *image)
   SDL_Surface *text;
   SDL_Rect box;
   SDL_Color Yellow = { 255, 255, 0, 0};
-  center = GetNextPoint (), GetNextPoint (), GetNextPoint ();
-  slice = SDL_CreateRGBSurface (SDL_SWSURFACE, WIDTH/2, HEIGHT/2,
+  center = GetNextPoint ();
+  slice = SDL_CreateRGBSurface (SDL_SWSURFACE, WIDTH/4, HEIGHT/4,
                                 32,
                                0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
-  center.x -= (WIDTH/2) / 2;
-  center.y -= (HEIGHT/2) / 2;
-  center.w /= 2;
-  center.h /= 2;
+  center.x -= (WIDTH/2) / 4;
+  center.y -= (HEIGHT/2) / 4;
+  center.w /= 4;
+  center.h /= 4;
   SDL_BlitSurface (image, &center, slice, NULL);
   SDL_UpdateRect (slice, 0, 0, 0, 0);
   scale = CairoTarget (slice);
@@ -214,28 +215,13 @@ GetNextImage (SDL_Surface *image)
   return scale;
 }
 
-Uint32
-ShowNext (Uint32 interval, void *data)
-{
-  SDL_UserEvent event;
-  event.type = SDL_USEREVENT;
-  event.code = 0;
-  SDL_PushEvent ((SDL_Event *) &event);
-  if (stop)
-  {
-    stop = 0;
-    return STOP_INTERVAL;
-  }
-  return 1000/FPS;
-}
-
 int
 main (int argc, char **argv)
 {
   SDL_Surface *screen;
   SDL_Surface *image;
   SDL_Surface *slice;
-  SDL_Event event;
+  Uint32 now, last;
   int i;
   ReadPoints ("pro-gnu");
   SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
@@ -243,16 +229,28 @@ main (int argc, char **argv)
   font = TTF_OpenFont ("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", 48);
   screen = SDL_SetVideoMode (WIDTH, HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
   image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
-  SDL_AddTimer (0, ShowNext, NULL);
-  while (SDL_WaitEvent (&event))
+  last = SDL_GetTicks ();
+  while (1)
   {
-    if (event.type == SDL_KEYDOWN)
-      break;
-    else if (event.type == SDL_USEREVENT)
+    now = SDL_GetTicks ();
+    /* skip */
+    while (!stop && now > last + FRAME_INTERVAL)
+    {
+      last += FRAME_INTERVAL;
+      GetNextPoint ();
+    }
+    slice = GetNextImage (image);
+    ShowPoint (screen, slice);
+    SDL_FreeSurface (slice);
+    if (stop)
+    {
+      stop = 0;
+      SDL_Delay (STOP_INTERVAL);
+      last = SDL_GetTicks ();
+    }
+    else
     {
-      slice = GetNextImage (image);
-      ShowPoint (screen, slice);
-      SDL_FreeSurface (slice);
+      SDL_Delay (FRAME_INTERVAL - (now - last));
     }
   }
   SDL_FreeSurface (image);