1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-29 20:15:54 +02:00

eeshow/: fix offset calculation and also get rid of rounding artefacts

This commit is contained in:
Werner Almesberger 2016-08-09 12:10:53 -03:00
parent cc3befe110
commit 629b9356e2
3 changed files with 30 additions and 14 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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,