diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-06-25 13:15:50 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-07-05 15:32:34 +0200 |
commit | 4a99615a609eec2b84bb2341d74fac46a5998137 (patch) | |
tree | 486eacff07448e4c655df1fa1bcb20df709dd8df /source/fitz/draw-paint.c | |
parent | 2aa62902447760764e7a763dea322145d9c4808c (diff) | |
download | mupdf-4a99615a609eec2b84bb2341d74fac46a5998137.tar.xz |
Pass rect and matrix by value in geometry functions.
Several things irk me about passing values as const pointers:
* They can be NULL, which is not a valid value.
* They require explicit temporary variables for storage.
* They don't compose easily in a legible manner, requiring
weird pointer passing semantics where the variable being assigned
is hidden as an argument in the innermost function call.
* We can't change the value through the pointer, requiring yet more
local variables to hold copies of the input value.
In the device interface where we pass a matrix to a function, we often
find ourselves making a local copy of the matrix so we can concatenate
other transforms to it. This copying is a lot of unnecessary busywork
that I hope to eventually avoid by laying the groundwork with this
commit.
This is a rather large API change, so I apologize for the inconvenience,
but I hope the end result and gain in legibility will be worth the pain.
Diffstat (limited to 'source/fitz/draw-paint.c')
-rw-r--r-- | source/fitz/draw-paint.c | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/source/fitz/draw-paint.c b/source/fitz/draw-paint.c index 9485565d..027fe538 100644 --- a/source/fitz/draw-paint.c +++ b/source/fitz/draw-paint.c @@ -2171,7 +2171,6 @@ fz_paint_pixmap_with_bbox(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_REST const unsigned char *sp; unsigned char *dp; int x, y, w, h, n, da, sa; - fz_irect bbox2; fz_span_painter_t *fn; assert(dst->n - dst->alpha == src->n - src->alpha); @@ -2179,10 +2178,8 @@ fz_paint_pixmap_with_bbox(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_REST if (alpha == 0) return; - fz_pixmap_bbox_no_ctx(dst, &bbox2); - fz_intersect_irect(&bbox, &bbox2); - fz_pixmap_bbox_no_ctx(src, &bbox2); - fz_intersect_irect(&bbox, &bbox2); + bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(dst)); + bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(src)); x = bbox.x0; y = bbox.y0; @@ -2217,7 +2214,6 @@ fz_paint_pixmap(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT src, const unsigned char *sp; unsigned char *dp; fz_irect bbox; - fz_irect bbox2; int x, y, w, h, n, da, sa; fz_span_painter_t *fn; @@ -2231,10 +2227,7 @@ fz_paint_pixmap(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT src, } assert(dst->n - dst->alpha == src->n - src->alpha); - fz_pixmap_bbox_no_ctx(dst, &bbox); - fz_pixmap_bbox_no_ctx(src, &bbox2); - fz_intersect_irect(&bbox, &bbox2); - + bbox = fz_intersect_irect(fz_pixmap_bbox_no_ctx(src), fz_pixmap_bbox_no_ctx(dst)); x = bbox.x0; y = bbox.y0; w = bbox.x1 - bbox.x0; @@ -2300,7 +2293,6 @@ fz_paint_pixmap_alpha(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT const unsigned char *sp; unsigned char *dp; fz_irect bbox; - fz_irect bbox2; int x, y, w, h, n; if (alpha == 0) @@ -2308,10 +2300,7 @@ fz_paint_pixmap_alpha(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_RESTRICT assert(dst->n == 1 && dst->alpha == 1 && src->n >= 1 && src->alpha == 1); - fz_pixmap_bbox_no_ctx(dst, &bbox); - fz_pixmap_bbox_no_ctx(src, &bbox2); - fz_intersect_irect(&bbox, &bbox2); - + bbox = fz_intersect_irect(fz_pixmap_bbox_no_ctx(src), fz_pixmap_bbox_no_ctx(dst)); x = bbox.x0; y = bbox.y0; w = bbox.x1 - bbox.x0; @@ -2349,7 +2338,6 @@ fz_paint_pixmap_with_overprint(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ const unsigned char *sp; unsigned char *dp; fz_irect bbox; - fz_irect bbox2; int x, y, w, h, n, da, sa; fz_span_painter_t *fn; @@ -2360,10 +2348,7 @@ fz_paint_pixmap_with_overprint(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ } assert(dst->n - dst->alpha == src->n - src->alpha); - fz_pixmap_bbox_no_ctx(dst, &bbox); - fz_pixmap_bbox_no_ctx(src, &bbox2); - fz_intersect_irect(&bbox, &bbox2); - + bbox = fz_intersect_irect(fz_pixmap_bbox_no_ctx(src), fz_pixmap_bbox_no_ctx(dst)); x = bbox.x0; y = bbox.y0; w = bbox.x1 - bbox.x0; @@ -2396,18 +2381,16 @@ fz_paint_pixmap_with_mask(fz_pixmap * FZ_RESTRICT dst, const fz_pixmap * FZ_REST { const unsigned char *sp, *mp; unsigned char *dp; - fz_irect bbox, bbox2; + fz_irect bbox; int x, y, w, h, n, sa, da; fz_span_mask_painter_t *fn; assert(dst->n == src->n); assert(msk->n == 1); - fz_pixmap_bbox_no_ctx(dst, &bbox); - fz_pixmap_bbox_no_ctx(src, &bbox2); - fz_intersect_irect(&bbox, &bbox2); - fz_pixmap_bbox_no_ctx(msk, &bbox2); - fz_intersect_irect(&bbox, &bbox2); + bbox = fz_pixmap_bbox_no_ctx(dst); + bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(src)); + bbox = fz_intersect_irect(bbox, fz_pixmap_bbox_no_ctx(msk)); x = bbox.x0; y = bbox.y0; |