Added Point struct and cleaned up line generation
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 16 Aug 2008 12:03:49 +0000 (09:03 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 16 Aug 2008 12:03:49 +0000 (09:03 -0300)
movie.c
point.h [new file with mode: 0644]

diff --git a/movie.c b/movie.c
index 448341a..6c48c1a 100644 (file)
--- a/movie.c
+++ b/movie.c
  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define WIDTH 800
-#define HEIGHT 600
-#define FPS (25)
-#define FRAME_INTERVAL (1000/FPS)
-
 #include <glib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <SDL.h>
-#include <SDL_image.h>
+
+#include "point.h"
 
 #define SWAP(x, y) do { \
        x ^= y; y ^= x; x ^= y; \
        } while (0)
 
-#define IS_CENTER(cx, cy, x, y) \
-       ((x + WIDTH/2 == cx) && (y + HEIGHT/2 == cy))
-
-GArray *points;
-GPtrArray *names;
-
 void
-InsertLine (GArray *points, SDL_Rect *src, SDL_Rect *dst)
+InsertLine (GArray *points, Point *src, Point *dst)
 {
-  SDL_Rect rect;
+  Point rect;
   int inc, err, thre, swap;
   int x1, y1, x2, y2;
   int x, y;
-  rect.w = WIDTH;
-  rect.h = HEIGHT;
+  rect.name = src->name;
   err = 0;
   swap = 0;
   x1 = src->x;
@@ -76,23 +64,25 @@ InsertLine (GArray *points, SDL_Rect *src, SDL_Rect *dst)
   }
 }
 
-void
+GArray *
 ReadPoints (char *filename)
 {
+  GArray *points;
   FILE *file;
   char *buffer;
   char *next;
   size_t len;
   ssize_t r;
   int i = 0;
-  SDL_Rect last;
-  SDL_Rect rect;
+  Point last;
+  Point rect;
   file = fopen (filename, "r");
   points = g_array_new (FALSE, TRUE, sizeof (SDL_Rect));
   names = g_ptr_array_new ();
   buffer = NULL;
   len = 0;
-  rect.x = rect.y = rect.w = rect.h = 0;
+  rect.x = rect.y = 0;
+  rect.name = NULL;
   last = rect;
   while (!feof (file))
   {
@@ -104,80 +94,10 @@ ReadPoints (char *filename)
     if (i > 0)
       InsertLine (points, &last, &rect);
     while (isspace (*next)) next++;
-    g_ptr_array_add (names, strdup (next));
+    rect.name = g_strdup (next);
     last = rect;
     i++;
   }
   fclose (file);
-}
-
-void
-ShowPoint (SDL_Surface *screen, SDL_Surface *image, SDL_Rect center, double scale)
-{
-  center.x = (center.x * scale) - WIDTH/2;
-  center.y = (center.y * scale) - HEIGHT/2;
-  center.w = WIDTH;
-  center.h = HEIGHT;
-  SDL_BlitSurface (image, &center, screen, NULL);
-  SDL_UpdateRect (screen, 0, 0, 0, 0);
-}
-
-#define SCALE 2.0
-
-int
-main (int argc, char **argv)
-{
-  SDL_Surface *screen;
-  SDL_Surface *image;
-  SDL_Surface *scaled_image;
-  SDL_Rect rect;
-  SDL_Event event;
-  Uint32 last, now, deslast, start;
-  int i, des, desl;
-  ReadPoints ("pro-gnu");
-  SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
-  screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
-  image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
-  scaled_image = CairoScale (image, SCALE);
-  start = deslast = last = SDL_GetTicks ();
-  desl = des = i = 0;
-  while (1)
-  {
-    if (SDL_PollEvent (&event))
-    {
-      if (event.type == SDL_KEYDOWN)
-        break;
-    }
-    now = SDL_GetTicks ();
-    /* skip */
-    while (now > last + FRAME_INTERVAL)
-    {
-      last += FRAME_INTERVAL;
-      i++;
-    }
-    last = now;
-    if (now > deslast + 1000)
-    {
-      printf ("%f %f %d\n", (double) des / (double) (now - start) * 1000, (double) (des - desl) / (double) (now - deslast) * 1000, i - des);
-      desl = des;
-      deslast = now;
-    }
-    if (i > points->len)
-    {
-      des -= i;
-      i = 0;
-    }
-    rect = g_array_index (points, SDL_Rect, i);
-    ShowPoint (screen, scaled_image, rect, SCALE);
-    SDL_Delay (FRAME_INTERVAL - (now - last));
-    i++;
-    des++;
-  }
-  SDL_FreeSurface (image);
-  SDL_Quit ();
-  g_array_free (points, TRUE);
-  for (i = 0; i < names->len; i++)
-    free (g_ptr_array_index (names, i));
-  g_ptr_array_free (names, TRUE);
-  return 0;
+  return points;
 }
diff --git a/point.h b/point.h
new file mode 100644 (file)
index 0000000..5b13e26
--- /dev/null
+++ b/point.h
@@ -0,0 +1,29 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#ifndef POINTS_H
+#define POINTS_H
+
+typedef struct
+{
+  int x, y;
+  char *name;
+} Point;
+
+#endif