From 629b9356e2476f2c79fe3be99787348903e8238d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 9 Aug 2016 12:10:53 -0300 Subject: [PATCH] eeshow/: fix offset calculation and also get rid of rounding artefacts --- eeshow/cro.c | 13 +++++++++---- eeshow/cro.h | 1 + eeshow/diff.c | 30 ++++++++++++++++++++---------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/eeshow/cro.c b/eeshow/cro.c index da4bed7..6070287 100644 --- a/eeshow/cro.c +++ b/eeshow/cro.c @@ -43,7 +43,8 @@ struct cro_ctx { struct record record; /* must be first */ - int xo, yo; + int xo, yo; /* offset in target (e.g., canvas) coord */ + int xe, ye; /* additional offset in eeschema coord */ float scale; cairo_t *cr; @@ -66,19 +67,19 @@ static inline int cd(const struct cro_ctx *cc, int x) static inline int cx(const struct cro_ctx *cc, int x) { - return cc->xo + x * cc->scale; + return cc->xo + (x + cc->xe) * cc->scale; } static inline int xc(const struct cro_ctx *cc, int x) { - return (x - cc->xo) / cc->scale; + return (x - cc->xe) / cc->scale - cc->xe; } static inline int cy(const struct cro_ctx *cc, int y) { - return cc->yo + y * cc->scale; + return cc->yo + (y + cc->ye) * cc->scale; } @@ -261,6 +262,7 @@ static struct cro_ctx *new_cc(void) cc = alloc_type(struct cro_ctx); cc->xo = cc->yo = 0; + cc->xe = cc->ye = 0; cc->scale = DEFAULT_SCALE; cc->sheets = NULL; @@ -532,6 +534,7 @@ void cro_canvas_draw(struct cro_ctx *cc, cairo_t *cr, int xo, int yo, uint32_t *cro_img(struct cro_ctx *ctx, int xo, int yo, int w, int h, + int xe, int ye, float scale, cairo_t **res_cr, int *res_stride) { int stride; @@ -558,6 +561,8 @@ uint32_t *cro_img(struct cro_ctx *ctx, int xo, int yo, int w, int h, ctx->s = s; ctx->xo = xo; ctx->yo = yo; + ctx->xe = xe; + ctx->ye = ye; ctx->scale = scale; ctx->color_override = COLOR_NONE; diff --git a/eeshow/cro.h b/eeshow/cro.h index 227efc3..8c3fd97 100644 --- a/eeshow/cro.h +++ b/eeshow/cro.h @@ -44,6 +44,7 @@ void cro_canvas_draw(struct cro_ctx *cc, cairo_t *cr, int x, int y, float scale); uint32_t *cro_img(struct cro_ctx *ctx, int x0, int yo, int w, int h, + int xe, int ye, float scale, cairo_t **res_cr, int *res_stride); #endif /* !CRO_H */ diff --git a/eeshow/diff.c b/eeshow/diff.c index 7770b36..114a5bf 100644 --- a/eeshow/diff.c +++ b/eeshow/diff.c @@ -337,19 +337,29 @@ void diff_to_canvas(cairo_t *cr, int cx, int cy, float scale, merge_coord(old_ymin, new_ymin, old_h, new_h, &ymin, &h); /* - * @@@ we should handle offset differences (xmin - old_xmin, et al.) - * before scaling. Else we risk rounding differences to lead to - * single-pixel differences, which the differences algorithm will - * be eager to mark with big yellow boxes. + * We use two sets of offset differences: one applied to eeschema + * coordinates (the xe, ye pair), and one applied to canvas coordinates + * (the xo, yo pair). + * + * This is to prevent different offsets from leading to rounding + * differences, resulting in single-pixel differences, which in turn + * the differences algorithm will be eager to mark with big yellow + * boxes. */ img_old = cro_img(old, - sw / 2.0 - (cx + 2 * xmin - old_xmin) * scale, - sh / 2.0 - (cy + 2 * ymin - old_ymin) * scale, - sw, sh, scale, &old_cr, &stride); + sw / 2.0 - (cx + xmin) * scale, + sh / 2.0 - (cy + ymin) * scale, + sw, sh, + xmin - old_xmin, + ymin - old_ymin, + scale, &old_cr, &stride); img_new = cro_img(new, - sw / 2.0 - (cx + 2 * xmin - new_xmin) * scale, - sh / 2.0 - (cy + 2 * ymin - new_ymin) * scale, - sw, sh, scale, NULL, NULL); + sw / 2.0 - (cx + xmin) * scale, + sh / 2.0 - (cy + ymin) * scale, + sw, sh, + xmin - new_xmin, + ymin - new_ymin, + scale, NULL, NULL); struct diff diff = { .w = sw,