summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-20 08:26:01 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-20 08:26:01 -0300
commitd54fbc13c607d3605449d3a460b69970fe6392c9 (patch)
tree8d7428c8038d1152ba2919b1e6d3f7f926c1738d /gfx
parent7129587854a9eecdf7733a76f02f4081d294c7b9 (diff)
downloadeeshow-d54fbc13c607d3605449d3a460b69970fe6392c9.tar.gz
eeshow-d54fbc13c607d3605449d3a460b69970fe6392c9.tar.bz2
eeshow-d54fbc13c607d3605449d3a460b69970fe6392c9.zip
eeshow/gfx/diff.c: export area creation and freeing
Diffstat (limited to 'gfx')
-rw-r--r--gfx/diff.c63
-rw-r--r--gfx/diff.h4
2 files changed, 42 insertions, 25 deletions
diff --git a/gfx/diff.c b/gfx/diff.c
index c44f02c..05f4f18 100644
--- a/gfx/diff.c
+++ b/gfx/diff.c
@@ -182,34 +182,47 @@ fail_open:
}
+void add_area(struct area **areas, int xa, int ya, int xb, int yb,
+ uint32_t color)
+{
+ struct area *area;
+
+ area = alloc_type(struct area);
+
+ area->xa = xa;
+ area->ya = ya;
+ area->xb = xb;
+ area->yb = yb;
+ area->color = color;
+
+ area->next = *areas;
+ *areas = area;
+}
+
+
static void mark_area(struct diff *diff, int x, int y)
{
struct area *area;
+ int xa = x - diff->frame_radius;
+ int ya = y - diff->frame_radius;
+ int xb = x + diff->frame_radius;
+ int yb = y + diff->frame_radius;
for (area = diff->areas; area; area = area->next)
if (x >= area->xa && x <= area->xb &&
y >= area->ya && y <= area->yb) {
- if (area->xa > x - diff->frame_radius)
- area->xa = x - diff->frame_radius;
- if (area->xb < x + diff->frame_radius)
- area->xb = x + diff->frame_radius;
- if (area->ya > y - diff->frame_radius)
- area->ya = y - diff->frame_radius;
- if (area->yb < y + diff->frame_radius)
- area->yb = y + diff->frame_radius;
+ if (area->xa > xa)
+ area->xa = xa;
+ if (area->xb < xb)
+ area->xb = xb;
+ if (area->ya > ya)
+ area->ya = ya;
+ if (area->yb < yb)
+ area->yb = yb;
return;
}
- area = alloc_type(struct area);
-
- area->xa = x - diff->frame_radius;
- area->xb = x + diff->frame_radius;
- area->ya = y - diff->frame_radius;
- area->yb = y + diff->frame_radius;
- area->color = AREA_FILL;
-
- area->next = diff->areas;
- diff->areas = area;
+ add_area(&diff->areas, xa, ya, xb, yb, AREA_FILL);
}
@@ -264,14 +277,14 @@ static void show_areas(struct diff *diff, uint32_t *a)
}
-static void free_areas(struct diff *diff)
+void free_areas(struct area **areas)
{
struct area *next;
- while (diff->areas) {
- next = diff->areas->next;
- free(diff->areas);
- diff->areas = next;
+ while (*areas) {
+ next = (*areas)->next;
+ free(*areas);
+ *areas = next;
}
}
@@ -288,7 +301,7 @@ static void diff_end(void *ctx)
differences(diff, old_img, diff->new_img);
show_areas(diff, old_img);
- free_areas(diff);
+ free_areas(&diff->areas);
cro_img_write(diff->cr_ctx, diff->output_name);
}
@@ -374,7 +387,7 @@ void diff_to_canvas(cairo_t *cr, int cx, int cy, float scale,
cairo_surface_flush(s);
differences(&diff, img_old, img_new);
show_areas(&diff, img_old);
- free_areas(&diff);
+ free_areas(&diff.areas);
if (areas) {
diff.areas = (struct area *) areas;
show_areas(&diff, img_old);
diff --git a/gfx/diff.h b/gfx/diff.h
index 5d7be8e..26bc062 100644
--- a/gfx/diff.h
+++ b/gfx/diff.h
@@ -32,6 +32,10 @@ struct area {
};
+void add_area(struct area **areas, int xa, int ya, int xb, int yb,
+ uint32_t color);
+void free_areas(struct area **areas);
+
void diff_to_canvas(cairo_t *cr, int cx, int cy, float scale,
struct cro_ctx *old, struct cro_ctx *new,
const struct area *areas);