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.
28 #define SWAP(x, y) do { \
29 x ^= y; y ^= x; x ^= y; \
33 InsertLine (GArray *points, Point *src, Point *dst)
36 int inc, err, thre, swap;
48 if (ABS (inc) > ABS (thre))
55 for (y = y1, x = x1; (x2 < x1) ? (x >= x2) : (x <= x2); (x2 < x1) ? x-- : x++)
57 rect.x = (swap ? y : x);
58 rect.y = (swap ? x : y);
59 g_array_append_val (points, rect);
61 if (err >= ABS (thre))
64 y += (inc < 0) ? -1 : 1;
70 ReadPoints (char *filename)
81 file = fopen (filename, "r");
84 fprintf (stderr, "Could not open file %s\n", filename);
87 points = g_array_new (FALSE, TRUE, sizeof (Point));
95 r = getline (&buffer, &len, file);
97 rect.x = strtol (buffer, &next, 0);
98 rect.y = strtol (next+1, &next, 0);
99 strtol (next, &next, 0);
100 while (isspace (*next)) next++;
101 rect.name = g_strdup (next);
103 InsertLine (points, &last, &rect);
104 g_array_append_val (points, rect);
113 drop_dup_frames (GArray *points, int n)
124 frames = g_array_new (FALSE, TRUE, sizeof (Point));
125 for (i = 0; i < points->len;)
128 point = next = &(g_array_index (points, Point, j));
129 while (next->name == NULL && j < points->len)
132 next = &(g_array_index (points, Point, j));
136 g_array_append_val (frames, g_array_index (points, Point, i));
143 g_array_append_val (frames, g_array_index (points, Point, i));
156 scales = g_array_new (FALSE, TRUE, sizeof (double));
157 factor = pow (4.0, 1.0/((double) n/2));
159 for (scale = 4.00; scale > 1.0 && scales->len < n/2; scale *= factor)
160 scales = g_array_append_val (scales, scale);
162 for (scale = 1.0; scale < 4.0 && scales->len < n; scale *= factor)
163 scales = g_array_append_val (scales, scale);
168 rescale_points (GArray *points, GArray *scales)
173 for (i = 0; i < points->len; i++)
175 point = &(g_array_index (points, Point, i));
176 scale = g_array_index (scales, double, (i % scales->len));
179 point->x *= point->rx;
180 point->y *= point->ry;