1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 06:02:48 +02:00

eeshow/gfx/diff.c: export area creation and freeing

This commit is contained in:
Werner Almesberger 2016-08-20 08:26:01 -03:00
parent 169e34d50f
commit 13fcf8ce3a
2 changed files with 42 additions and 25 deletions

View File

@ -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) static void mark_area(struct diff *diff, int x, int y)
{ {
struct area *area; 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) for (area = diff->areas; area; area = area->next)
if (x >= area->xa && x <= area->xb && if (x >= area->xa && x <= area->xb &&
y >= area->ya && y <= area->yb) { y >= area->ya && y <= area->yb) {
if (area->xa > x - diff->frame_radius) if (area->xa > xa)
area->xa = x - diff->frame_radius; area->xa = xa;
if (area->xb < x + diff->frame_radius) if (area->xb < xb)
area->xb = x + diff->frame_radius; area->xb = xb;
if (area->ya > y - diff->frame_radius) if (area->ya > ya)
area->ya = y - diff->frame_radius; area->ya = ya;
if (area->yb < y + diff->frame_radius) if (area->yb < yb)
area->yb = y + diff->frame_radius; area->yb = yb;
return; return;
} }
area = alloc_type(struct area); add_area(&diff->areas, xa, ya, xb, yb, AREA_FILL);
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;
} }
@ -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; struct area *next;
while (diff->areas) { while (*areas) {
next = diff->areas->next; next = (*areas)->next;
free(diff->areas); free(*areas);
diff->areas = next; *areas = next;
} }
} }
@ -288,7 +301,7 @@ static void diff_end(void *ctx)
differences(diff, old_img, diff->new_img); differences(diff, old_img, diff->new_img);
show_areas(diff, old_img); show_areas(diff, old_img);
free_areas(diff); free_areas(&diff->areas);
cro_img_write(diff->cr_ctx, diff->output_name); 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); cairo_surface_flush(s);
differences(&diff, img_old, img_new); differences(&diff, img_old, img_new);
show_areas(&diff, img_old); show_areas(&diff, img_old);
free_areas(&diff); free_areas(&diff.areas);
if (areas) { if (areas) {
diff.areas = (struct area *) areas; diff.areas = (struct area *) areas;
show_areas(&diff, img_old); show_areas(&diff, img_old);

View File

@ -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, void diff_to_canvas(cairo_t *cr, int cx, int cy, float scale,
struct cro_ctx *old, struct cro_ctx *new, struct cro_ctx *old, struct cro_ctx *new,
const struct area *areas); const struct area *areas);