diff options
-rw-r--r-- | source/fitz/draw-edge.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/source/fitz/draw-edge.c b/source/fitz/draw-edge.c index 43394fcb..bffb86d3 100644 --- a/source/fitz/draw-edge.c +++ b/source/fitz/draw-edge.c @@ -10,6 +10,12 @@ static inline int fz_idiv(int a, int b) return a < 0 ? (a - b + 1) / b : a / b; } +/* divide and ceil towards inf */ +static inline int fz_idiv_up(int a, int b) +{ + return a < 0 ? a / b : (a + b - 1) / b; +} + /* If AA_BITS is defined, then we assume constant N bits of antialiasing. We * will attempt to provide at least that number of bits of accuracy in the * antialiasing (to a maximum of 8). If it is defined to be 0 then no @@ -353,8 +359,8 @@ fz_bound_gel(fz_context *ctx, const fz_gel *gel, fz_irect *bbox) { bbox->x0 = fz_idiv(gel->bbox.x0, hscale); bbox->y0 = fz_idiv(gel->bbox.y0, vscale); - bbox->x1 = fz_idiv(gel->bbox.x1, hscale) + 1; - bbox->y1 = fz_idiv(gel->bbox.y1, vscale) + 1; + bbox->x1 = fz_idiv_up(gel->bbox.x1, hscale); + bbox->y1 = fz_idiv_up(gel->bbox.y1, vscale); } return bbox; } @@ -875,7 +881,7 @@ fz_scan_convert_aa(fz_context *ctx, fz_gel *gel, int eofill, const fz_irect *cli const int vscale = fz_aa_vscale; int xmin = fz_idiv(gel->bbox.x0, hscale); - int xmax = fz_idiv(gel->bbox.x1, hscale) + 1; + int xmax = fz_idiv_up(gel->bbox.x1, hscale); int xofs = xmin * hscale; @@ -885,11 +891,12 @@ fz_scan_convert_aa(fz_context *ctx, fz_gel *gel, int eofill, const fz_irect *cli if (gel->len == 0) return; + assert(xmin < xmax); assert(clip->x0 >= xmin); assert(clip->x1 <= xmax); alphas = fz_malloc_no_throw(ctx, xmax - xmin + 1); - deltas = fz_malloc_no_throw(ctx, (xmax - xmin + 1) * sizeof(int)); + deltas = fz_malloc_no_throw(ctx, (xmax - xmin + 2) * sizeof(int)); if (alphas == NULL || deltas == NULL) { fz_free(ctx, alphas); |