X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fmovie.git;a=blobdiff_plain;f=movie.c;h=4ff67dbea27ce6b665e8ab68066236d16e320da8;hp=8bba5ac5566d65423520c744f6c6ccd033bc01ca;hb=9946d0d51bfa0fb3a00aaf4cea0bc9845d7e12f1;hpb=1e56e1dc756f1b11bddb89be5a8ac554fe001b33 diff --git a/movie.c b/movie.c index 8bba5ac..4ff67db 100644 --- a/movie.c +++ b/movie.c @@ -16,27 +16,104 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _GNU_SOURCE +#include +#include +#include +#include -#include -#include +#include "point.h" -int -main (int argc, char **argv) +#define SWAP(x, y) do { \ + x ^= y; y ^= x; x ^= y; \ + } while (0) + +void +InsertLine (GArray *points, Point *src, Point *dst) { - SDL_Surface *image; - SDL_Surface *screen; - SDL_Event event; - SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER); - screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); - image = IMG_Load ("/home/cascardo/fotos/debconf.jpg"); - SDL_BlitSurface (image, NULL, screen, NULL); - SDL_UpdateRect (screen, 0, 0, 0, 0); - while (SDL_WaitEvent (&event)) + Point rect; + int inc, err, thre, swap; + int x1, y1, x2, y2; + int x, y; + rect.name = NULL; + err = 0; + swap = 0; + x1 = src->x; + y1 = src->y; + x2 = dst->x; + y2 = dst->y; + inc = y2 - y1; + thre = x2 - x1; + if (ABS (inc) > ABS (thre)) + { + SWAP (inc, thre); + SWAP (x1, y1); + SWAP (x2, y2); + swap = 1; + } + for (y = y1, x = x1; (x2 < x1) ? (x >= x2) : (x <= x2); (x2 < x1) ? x-- : x++) { - if (event.type == SDL_KEYDOWN) - break; + rect.x = (swap ? y : x); + rect.y = (swap ? x : y); + g_array_append_val (points, rect); + err += ABS (inc); + if (err >= ABS (thre)) + { + err -= ABS (thre); + y += (inc < 0) ? -1 : 1; + } } - SDL_FreeSurface (image); - SDL_Quit (); - return 0; +} + +GArray * +ReadPoints (char *filename) +{ + GArray *points; + FILE *file; + char *buffer; + char *next; + size_t len; + ssize_t r; + int i = 0; + Point last; + Point rect; + file = fopen (filename, "r"); + points = g_array_new (FALSE, TRUE, sizeof (Point)); + buffer = NULL; + len = 0; + rect.x = rect.y = 0; + rect.name = NULL; + last = rect; + while (!feof (file)) + { + r = getline (&buffer, &len, file); + buffer[r - 1] = '\0'; + rect.x = strtol (buffer, &next, 0); + rect.y = strtol (next+1, &next, 0); + strtol (next, &next, 0); + while (isspace (*next)) next++; + rect.name = g_strdup (next); + if (i > 0) + InsertLine (points, &last, &rect); + g_array_append_val (points, rect); + last = rect; + i++; + } + fclose (file); + return points; +} + +void +rescale_points (GArray *points) +{ + Point *point; + int i; + for (i = 0; i < points->len; i++) + { + point = &(g_array_index (points, Point, i)); + point->rx = 4.0; + point->ry = 4.0; + point->x *= point->rx; + point->y *= point->ry; + } }