2 * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #define FRAME_INTERVAL (1000/FPS)
29 #include <SDL_image.h>
31 #define SWAP(x, y) do { \
32 x ^= y; y ^= x; x ^= y; \
35 #define IS_CENTER(cx, cy, x, y) \
36 ((x + WIDTH/2 == cx) && (y + HEIGHT/2 == cy))
42 InsertLine (GArray *points, SDL_Rect *src, SDL_Rect *dst)
45 int inc, err, thre, swap;
58 if (ABS (inc) > ABS (thre))
65 for (y = y1, x = x1; (x2 < x1) ? (x >= x2) : (x <= x2); (x2 < x1) ? x-- : x++)
67 rect.x = (swap ? y : x);
68 rect.y = (swap ? x : y);
69 g_array_append_val (points, rect);
71 if (err >= ABS (thre))
74 y += (inc < 0) ? -1 : 1;
80 ReadPoints (char *filename)
90 file = fopen (filename, "r");
91 points = g_array_new (FALSE, TRUE, sizeof (SDL_Rect));
92 names = g_ptr_array_new ();
95 rect.x = rect.y = rect.w = rect.h = 0;
99 r = getline (&buffer, &len, file);
100 buffer[r - 1] = '\0';
101 rect.x = strtol (buffer, &next, 0);
102 rect.y = strtol (next+1, &next, 0);
103 strtol (next, &next, 0);
105 InsertLine (points, &last, &rect);
106 while (isspace (*next)) next++;
107 g_ptr_array_add (names, strdup (next));
115 ShowPoint (SDL_Surface *screen, SDL_Surface *image, SDL_Rect center, double scale)
117 center.x = (center.x * scale) - WIDTH/2;
118 center.y = (center.y * scale) - HEIGHT/2;
121 SDL_BlitSurface (image, ¢er, screen, NULL);
122 SDL_UpdateRect (screen, 0, 0, 0, 0);
128 main (int argc, char **argv)
132 SDL_Surface *scaled_image;
135 Uint32 last, now, deslast, start;
137 ReadPoints ("pro-gnu");
138 SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
139 screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
140 image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
141 scaled_image = CairoScale (image, SCALE);
142 start = deslast = last = SDL_GetTicks ();
146 if (SDL_PollEvent (&event))
148 if (event.type == SDL_KEYDOWN)
151 now = SDL_GetTicks ();
153 while (now > last + FRAME_INTERVAL)
155 last += FRAME_INTERVAL;
159 if (now > deslast + 1000)
161 printf ("%f %f %d\n", (double) des / (double) (now - start) * 1000, (double) (des - desl) / (double) (now - deslast) * 1000, i - des);
170 rect = g_array_index (points, SDL_Rect, i);
171 ShowPoint (screen, scaled_image, rect, SCALE);
172 SDL_Delay (FRAME_INTERVAL - (now - last));
176 SDL_FreeSurface (image);
178 g_array_free (points, TRUE);
179 for (i = 0; i < names->len; i++)
180 free (g_ptr_array_index (names, i));
181 g_ptr_array_free (names, TRUE);