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");
82 points = g_array_new (FALSE, TRUE, sizeof (Point));
90 r = getline (&buffer, &len, file);
92 rect.x = strtol (buffer, &next, 0);
93 rect.y = strtol (next+1, &next, 0);
94 strtol (next, &next, 0);
95 while (isspace (*next)) next++;
96 rect.name = g_strdup (next);
98 InsertLine (points, &last, &rect);
99 g_array_append_val (points, rect);
108 drop_dup_frames (GArray *points, int n)
119 frames = g_array_new (FALSE, TRUE, sizeof (Point));
120 for (i = 0; i < points->len;)
123 point = next = &(g_array_index (points, Point, j));
124 while (next->name == NULL && j < points->len)
127 next = &(g_array_index (points, Point, j));
131 g_array_append_val (frames, g_array_index (points, Point, i));
138 g_array_append_val (frames, g_array_index (points, Point, i));
151 scales = g_array_new (FALSE, TRUE, sizeof (double));
152 factor = pow (4.0, 1.0/((double) n/2));
154 for (scale = 4.00; scale > 1.0 && scales->len < n/2; scale *= factor)
155 scales = g_array_append_val (scales, scale);
157 for (scale = 1.0; scale < 4.0 && scales->len < n; scale *= factor)
158 scales = g_array_append_val (scales, scale);
163 rescale_points (GArray *points, GArray *scales)
168 for (i = 0; i < points->len; i++)
170 point = &(g_array_index (points, Point, i));
171 scale = g_array_index (scales, double, (i % scales->len));
174 point->x *= point->rx;
175 point->y *= point->ry;