summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2010-11-07 01:55:52 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2010-11-07 01:55:52 -0400
commit942d027a9dd49d881ca95a65c9f0187ce9d86882 (patch)
tree6388a59ed7c4f423995164fd83fa2a66b059ed40
parent3abaea037dfeaf6fdaeae0b09728622448dc7785 (diff)
cleanups
-rw-r--r--region-iter.c82
1 files changed, 23 insertions, 59 deletions
diff --git a/region-iter.c b/region-iter.c
index 9008242..bf1751c 100644
--- a/region-iter.c
+++ b/region-iter.c
@@ -401,7 +401,6 @@ dump_region (const char *title, pixman_region32_t *region)
}
typedef struct corner_t corner_t;
-typedef struct active_t active_t;
struct corner_t
{
@@ -411,26 +410,16 @@ struct corner_t
int next;
};
-struct active_t
+static int *
+add_active (int *actives, int *n_actives, int corner)
{
- int corner;
-};
-
-static active_t *
-add_active (active_t *actives, int *n_actives, int active)
-{
- active_t a;
-
- a.corner = active;
+ int idx = (*n_actives)++;
- *n_actives += 1;
+ actives = realloc (actives, next_power (*n_actives) * sizeof (int));
- actives = realloc (actives, *n_actives * sizeof (active_t));
-
- actives[*n_actives - 1] = a;
+ actives[idx] = corner;
return actives;
-
}
static corner_t *
@@ -439,7 +428,7 @@ add_corners (corner_t *corners, int *n_corners, int *new1, int *new2)
*new1 = (*n_corners)++;
*new2 = (*n_corners)++;
- return realloc (corners, (*(n_corners)) * sizeof (corner_t));
+ return realloc (corners, next_power (*n_corners) * sizeof (corner_t));
}
static corner_t *
@@ -448,7 +437,7 @@ region_path (pixman_region32_t *region, int *n)
region_iter_t iter;
row_t row1, row2;
corner_t *corners = NULL;
- active_t *active = NULL;
+ int *active = NULL;
int n_corners = 0;
int n_active = 0;
@@ -467,58 +456,43 @@ region_path (pixman_region32_t *region, int *n)
segment_type_t type;
int x1, x2;
- active_t *old_active;
+ int *old_active;
int old_n_active;
int current;
- int c1, c2, p1, p2;
old_active = active;
old_n_active = n_active;
active = NULL;
n_active = 0;
-
current = 0;
region_iter_get_row (&iter, &row2);
- printf ("row: %d %d %d %d\n", row1.y1, row1.y2, row2.y1, row2.y2);
-
segment_iter_init (&seg_iter, &row1, &row2);
while (segment_iter_get_segment (&seg_iter, &x1, &x2, &type))
{
- switch (type)
+ if (type == ROW1 || type == ROW2)
{
- case ROW1:
- case ROW2:
- corners = add_corners (corners, &n_corners, &c1, &c2);
+ int p1 = -1;
+ int p2 = -1;
+ int c1, c2;
- p1 = p2 = -1;
-
- printf ("segment %s (%d %d)\n", type == ROW1? "row1" : "row2", x1, x2);
-
- while (current < old_n_active && corners[old_active[current].corner].x <= x2)
+ while (current < old_n_active &&
+ corners[old_active[current]].x <= x2)
{
- if (corners[old_active[current].corner].x == x1)
- {
- p1 = old_active[current].corner;
-
- printf ("found p1: %d (%d %d)\n", p1, corners[p1].x, corners[p1].y);
- }
- else if (corners[old_active[current].corner].x == x2)
- {
- p2 = old_active[current].corner;
-
- printf ("found p2: %d (%d %d)\n", p2, corners[p2].x, corners[p2].y);
- }
+ int c = old_active[current];
+
+ if (corners[c].x == x1)
+ p1 = c;
+ else if (corners[c].x == x2)
+ p2 = c;
else
- {
- active = add_active (
- active, &n_active, old_active[current].corner);
- }
+ active = add_active (active, &n_active, c);
current++;
}
+ corners = add_corners (corners, &n_corners, &c1, &c2);
corners[c1].x = x1;
corners[c1].y = row1.y2;
corners[c2].x = x2;
@@ -552,21 +526,11 @@ region_path (pixman_region32_t *region, int *n)
corners[c1].next = c2;
else
corners[c2].next = c1;
- break;
-
- case BOTH:
- printf ("segment BOTH (%d %d)\n", x1, x2);
- break;
}
}
while (current < old_n_active)
- {
- active = add_active (
- active, &n_active, old_active[current].corner);
-
- ++current;
- }
+ active = add_active (active, &n_active, old_active[current++]);
free (old_active);