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.
25 #include <SDL_image.h>
27 #define SWAP(x, y) do { \
28 x ^= y; y ^= x; x ^= y; \
31 #define ABS(x) ((x) < 0 ? -(x) : (x))
33 #define IS_CENTER(cx, cy, x, y) \
34 ((x + WIDTH/2 == cx) && (y + HEIGHT/2 == cy))
40 ReadPoints (char *filename)
47 file = fopen (filename, "r");
48 fscanf (file, "%d\n", &psize);
49 points = malloc (sizeof (SDL_Rect) * psize);
54 for (i = 0; i < psize; i++)
56 getline (&buffer, &len, file);
57 points[i].x = strtol (buffer, &next, 0);
58 points[i].y = strtol (next+1, NULL, 0);
66 static SDL_Rect rect = {0, 0, WIDTH, HEIGHT};
68 static int inc, err, thre, swap;
69 static int x1, y1, x2, y2;
72 next = (cur + 1) % psize;
73 if ((points[next].x == rect.x && points[next].y == rect.y) || cur == -1)
76 next = (cur + 1) % psize;
85 if (ABS (inc) > ABS (thre))
95 rect.x = (swap ? y : x);
96 rect.y = (swap ? x : y);
97 (x2 < x1) ? x-- : x++;
99 if (err >= ABS (thre))
102 y += (inc < 0) ? -1 : 1;
108 ShowPoint (SDL_Surface *screen, SDL_Surface *image)
110 SDL_BlitSurface (image, NULL, screen, NULL);
111 SDL_UpdateRect (screen, 0, 0, 0, 0);
115 GetNextImage (SDL_Surface *image)
119 center = GetNextPoint (), GetNextPoint (), GetNextPoint ();
120 slice = SDL_CreateRGBSurface (SDL_SWSURFACE, WIDTH, HEIGHT,
121 image->format->BitsPerPixel,
122 image->format->Rmask,
123 image->format->Gmask,
124 image->format->Bmask,
125 image->format->Amask);
127 center.y -= HEIGHT/2;
128 SDL_BlitSurface (image, ¢er, slice, NULL);
129 SDL_UpdateRect (slice, 0, 0, 0, 0);
134 ShowNext (Uint32 interval, void *data)
137 event.type = SDL_USEREVENT;
139 SDL_PushEvent ((SDL_Event *) &event);
144 main (int argc, char **argv)
150 ReadPoints ("pro-gnu");
151 SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
152 screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
153 image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
154 SDL_AddTimer (0, ShowNext, NULL);
155 while (SDL_WaitEvent (&event))
157 if (event.type == SDL_KEYDOWN)
159 else if (event.type == SDL_USEREVENT)
161 slice = GetNextImage (image);
162 ShowPoint (screen, slice);
163 SDL_FreeSurface (slice);
166 SDL_FreeSurface (image);