summaryrefslogtreecommitdiff
path: root/draw
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-01-25 19:24:49 +0000
committerRobin Watts <robin.watts@artifex.com>2013-02-06 19:24:12 +0000
commitd3aa37962470253083714b5092a1ba759f674d47 (patch)
treeec60a0857cd3d44d3db5bc0c95aa69335b6b2d47 /draw
parentc42dac496e0994c4253eb50ce67ceaec864ed379 (diff)
downloadmupdf-d3aa37962470253083714b5092a1ba759f674d47.tar.xz
Change to pass structures by reference rather than value.
This is faster on ARM in particular. The primary changes involve fz_matrix, fz_rect and fz_bbox. Rather than passing 'fz_rect r' into a function, we now consistently pass 'const fz_rect *r'. Where a rect is passed in and modified, we miss the 'const' off. Where possible, we return the pointer to the modified structure to allow 'chaining' of expressions. The basic upshot of this work is that we do far fewer copies of rectangle/matrix structures, and all the copies we do are explicit. This has opened the way to other optimisations, also performed in this commit. Rather than using expressions like: fz_concat(fz_scale(sx, sy), fz_translate(tx, ty)) we now have fz_pre_{scale,translate,rotate} functions. These can be implemented much more efficiently than doing the fully fledged matrix multiplication that fz_concat requires. We add fz_rect_{min,max} functions to return pointers to the min/max points of a rect. These can be used to in transformations to directly manipulate values. With a little casting in the path transformation code we can avoid more needless copying. We rename fz_widget_bbox to the more consistent fz_bound_widget.
Diffstat (limited to 'draw')
-rw-r--r--draw/draw_affine.c184
-rw-r--r--draw/draw_blend.c6
-rw-r--r--draw/draw_device.c353
-rw-r--r--draw/draw_edge.c78
-rw-r--r--draw/draw_glyph.c25
-rw-r--r--draw/draw_mesh.c19
-rw-r--r--draw/draw_paint.c23
-rw-r--r--draw/draw_path.c28
-rw-r--r--draw/draw_scale.c2
-rw-r--r--draw/draw_simple_scale.c2
10 files changed, 379 insertions, 341 deletions
diff --git a/draw/draw_affine.c b/draw/draw_affine.c
index 64234bf5..8943214f 100644
--- a/draw/draw_affine.c
+++ b/draw/draw_affine.c
@@ -463,175 +463,176 @@ fz_paint_affine_color_near(byte *dp, byte *sp, int sw, int sh, int u, int v, int
*/
#define MY_EPSILON 0.001
-fz_matrix
-fz_gridfit_matrix(fz_matrix m)
+void
+fz_gridfit_matrix(fz_matrix *m)
{
- if (fabsf(m.b) < FLT_EPSILON && fabsf(m.c) < FLT_EPSILON)
+ if (fabsf(m->b) < FLT_EPSILON && fabsf(m->c) < FLT_EPSILON)
{
- if (m.a > 0)
+ if (m->a > 0)
{
float f;
/* Adjust left hand side onto pixel boundary */
- f = (float)(int)(m.e);
- if (f - m.e > MY_EPSILON)
+ f = (float)(int)(m->e);
+ if (f - m->e > MY_EPSILON)
f -= 1.0; /* Ensure it moves left */
- m.a += m.e - f; /* width gets wider as f <= m.e */
- m.e = f;
+ m->a += m->e - f; /* width gets wider as f <= m.e */
+ m->e = f;
/* Adjust right hand side onto pixel boundary */
- f = (float)(int)(m.a);
- if (m.a - f > MY_EPSILON)
+ f = (float)(int)(m->a);
+ if (m->a - f > MY_EPSILON)
f += 1.0; /* Ensure it moves right */
- m.a = f;
+ m->a = f;
}
- else if (m.a < 0)
+ else if (m->a < 0)
{
float f;
/* Adjust right hand side onto pixel boundary */
- f = (float)(int)(m.e);
- if (m.e - f > MY_EPSILON)
+ f = (float)(int)(m->e);
+ if (m->e - f > MY_EPSILON)
f += 1.0; /* Ensure it moves right */
- m.a += m.e - f; /* width gets wider (more -ve) */
- m.e = f;
+ m->a += m->e - f; /* width gets wider (more -ve) */
+ m->e = f;
/* Adjust left hand side onto pixel boundary */
- f = (float)(int)(m.a);
- if (f - m.a > MY_EPSILON)
+ f = (float)(int)(m->a);
+ if (f - m->a > MY_EPSILON)
f -= 1.0; /* Ensure it moves left */
- m.a = f;
+ m->a = f;
}
- if (m.d > 0)
+ if (m->d > 0)
{
float f;
/* Adjust top onto pixel boundary */
- f = (float)(int)(m.f);
- if (f - m.f > MY_EPSILON)
+ f = (float)(int)(m->f);
+ if (f - m->f > MY_EPSILON)
f -= 1.0; /* Ensure it moves upwards */
- m.d += m.f - f; /* width gets wider as f <= m.f */
- m.f = f;
+ m->d += m->f - f; /* width gets wider as f <= m.f */
+ m->f = f;
/* Adjust bottom onto pixel boundary */
- f = (float)(int)(m.d);
- if (m.d - f > MY_EPSILON)
+ f = (float)(int)(m->d);
+ if (m->d - f > MY_EPSILON)
f += 1.0; /* Ensure it moves down */
- m.d = f;
+ m->d = f;
}
- else if (m.d < 0)
+ else if (m->d < 0)
{
float f;
/* Adjust bottom onto pixel boundary */
- f = (float)(int)(m.f);
- if (m.f - f > MY_EPSILON)
+ f = (float)(int)(m->f);
+ if (m->f - f > MY_EPSILON)
f += 1.0; /* Ensure it moves down */
- m.d += m.f - f; /* width gets wider (more -ve) */
- m.f = f;
+ m->d += m->f - f; /* width gets wider (more -ve) */
+ m->f = f;
/* Adjust top onto pixel boundary */
- f = (float)(int)(m.d);
- if (f - m.d > MY_EPSILON)
+ f = (float)(int)(m->d);
+ if (f - m->d > MY_EPSILON)
f -= 1.0; /* Ensure it moves up */
- m.d = f;
+ m->d = f;
}
}
- else if (fabsf(m.a) < FLT_EPSILON && fabsf(m.d) < FLT_EPSILON)
+ else if (fabsf(m->a) < FLT_EPSILON && fabsf(m->d) < FLT_EPSILON)
{
- if (m.b > 0)
+ if (m->b > 0)
{
float f;
/* Adjust left hand side onto pixel boundary */
- f = (float)(int)(m.f);
- if (f - m.f > MY_EPSILON)
+ f = (float)(int)(m->f);
+ if (f - m->f > MY_EPSILON)
f -= 1.0; /* Ensure it moves left */
- m.b += m.f - f; /* width gets wider as f <= m.f */
- m.f = f;
+ m->b += m->f - f; /* width gets wider as f <= m.f */
+ m->f = f;
/* Adjust right hand side onto pixel boundary */
- f = (float)(int)(m.b);
- if (m.b - f > MY_EPSILON)
+ f = (float)(int)(m->b);
+ if (m->b - f > MY_EPSILON)
f += 1.0; /* Ensure it moves right */
- m.b = f;
+ m->b = f;
}
- else if (m.b < 0)
+ else if (m->b < 0)
{
float f;
/* Adjust right hand side onto pixel boundary */
- f = (float)(int)(m.f);
- if (m.f - f > MY_EPSILON)
+ f = (float)(int)(m->f);
+ if (m->f - f > MY_EPSILON)
f += 1.0; /* Ensure it moves right */
- m.b += m.f - f; /* width gets wider (more -ve) */
- m.f = f;
+ m->b += m->f - f; /* width gets wider (more -ve) */
+ m->f = f;
/* Adjust left hand side onto pixel boundary */
- f = (float)(int)(m.b);
- if (f - m.b > MY_EPSILON)
+ f = (float)(int)(m->b);
+ if (f - m->b > MY_EPSILON)
f -= 1.0; /* Ensure it moves left */
- m.b = f;
+ m->b = f;
}
- if (m.c > 0)
+ if (m->c > 0)
{
float f;
/* Adjust top onto pixel boundary */
- f = (float)(int)(m.e);
- if (f - m.e > MY_EPSILON)
+ f = (float)(int)(m->e);
+ if (f - m->e > MY_EPSILON)
f -= 1.0; /* Ensure it moves upwards */
- m.c += m.e - f; /* width gets wider as f <= m.e */
- m.e = f;
+ m->c += m->e - f; /* width gets wider as f <= m.e */
+ m->e = f;
/* Adjust bottom onto pixel boundary */
- f = (float)(int)(m.c);
- if (m.c - f > MY_EPSILON)
+ f = (float)(int)(m->c);
+ if (m->c - f > MY_EPSILON)
f += 1.0; /* Ensure it moves down */
- m.c = f;
+ m->c = f;
}
- else if (m.c < 0)
+ else if (m->c < 0)
{
float f;
/* Adjust bottom onto pixel boundary */
- f = (float)(int)(m.e);
- if (m.e - f > MY_EPSILON)
+ f = (float)(int)(m->e);
+ if (m->e - f > MY_EPSILON)
f += 1.0; /* Ensure it moves down */
- m.c += m.e - f; /* width gets wider (more -ve) */
- m.e = f;
+ m->c += m->e - f; /* width gets wider (more -ve) */
+ m->e = f;
/* Adjust top onto pixel boundary */
- f = (float)(int)(m.c);
- if (f - m.c > MY_EPSILON)
+ f = (float)(int)(m->c);
+ if (f - m->c > MY_EPSILON)
f -= 1.0; /* Ensure it moves up */
- m.c = f;
+ m->c = f;
}
}
- return m;
}
/* Draw an image with an affine transform on destination */
static void
-fz_paint_image_imp(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *shape, fz_pixmap *img, fz_matrix ctm, byte *color, int alpha)
+fz_paint_image_imp(fz_pixmap *dst, const fz_bbox *scissor, fz_pixmap *shape, fz_pixmap *img, const fz_matrix *ctm, byte *color, int alpha)
{
byte *dp, *sp, *hp;
int u, v, fa, fb, fc, fd;
int x, y, w, h;
int sw, sh, n, hw;
- fz_matrix inv;
fz_bbox bbox;
int dolerp;
void (*paintfn)(byte *dp, byte *sp, int sw, int sh, int u, int v, int fa, int fb, int w, int n, int alpha, byte *color, byte *hp);
+ fz_matrix local_ctm = *ctm;
+ fz_rect rect;
/* grid fit the image */
- ctm = fz_gridfit_matrix(ctm);
+ fz_gridfit_matrix(&local_ctm);
/* turn on interpolation for upscaled and non-rectilinear transforms */
dolerp = 0;
- if (!fz_is_rectilinear(ctm))
+ if (!fz_is_rectilinear(&local_ctm))
dolerp = 1;
- if (sqrtf(ctm.a * ctm.a + ctm.b * ctm.b) > img->w)
+ if (sqrtf(local_ctm.a * local_ctm.a + local_ctm.b * local_ctm.b) > img->w)
dolerp = 1;
- if (sqrtf(ctm.c * ctm.c + ctm.d * ctm.d) > img->h)
+ if (sqrtf(local_ctm.c * local_ctm.c + local_ctm.d * local_ctm.d) > img->h)
dolerp = 1;
/* except when we shouldn't, at large magnifications */
if (!img->interpolate)
{
- if (sqrtf(ctm.a * ctm.a + ctm.b * ctm.b) > img->w * 2)
+ if (sqrtf(local_ctm.a * local_ctm.a + local_ctm.b * local_ctm.b) > img->w * 2)
dolerp = 0;
- if (sqrtf(ctm.c * ctm.c + ctm.d * ctm.d) > img->h * 2)
+ if (sqrtf(local_ctm.c * local_ctm.c + local_ctm.d * local_ctm.d) > img->h * 2)
dolerp = 0;
}
- bbox = fz_bbox_from_rect(fz_transform_rect(ctm, fz_unit_rect));
- bbox = fz_intersect_bbox(bbox, scissor);
+ rect = fz_unit_rect;
+ fz_bbox_from_rect(&bbox, fz_transform_rect(&rect, &local_ctm));
+ fz_intersect_bbox(&bbox, scissor);
x = bbox.x0;
if (shape && shape->x > x)
@@ -651,22 +652,21 @@ fz_paint_image_imp(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *shape, fz_pixmap
return;
/* map from screen space (x,y) to image space (u,v) */
- inv = fz_scale(1.0f / img->w, 1.0f / img->h);
- inv = fz_concat(inv, ctm);
- inv = fz_invert_matrix(inv);
+ fz_pre_scale(&local_ctm, 1.0f / img->w, 1.0f / img->h);
+ fz_invert_matrix(&local_ctm, &local_ctm);
- fa = (int)(inv.a *= 65536.0f);
- fb = (int)(inv.b *= 65536.0f);
- fc = (int)(inv.c *= 65536.0f);
- fd = (int)(inv.d *= 65536.0f);
- inv.e *= 65536.0f;
- inv.f *= 65536.0f;
+ fa = (int)(local_ctm.a *= 65536.0f);
+ fb = (int)(local_ctm.b *= 65536.0f);
+ fc = (int)(local_ctm.c *= 65536.0f);
+ fd = (int)(local_ctm.d *= 65536.0f);
+ local_ctm.e *= 65536.0f;
+ local_ctm.f *= 65536.0f;
/* Calculate initial texture positions. Do a half step to start. */
/* Bug 693021: Keep calculation in float for as long as possible to
* avoid overflow. */
- u = (int)((inv.a * x) + (inv.c * y) + inv.e + ((inv.a + inv.c) * .5f));
- v = (int)((inv.b * x) + (inv.d * y) + inv.f + ((inv.b + inv.d) * .5f));
+ u = (int)((local_ctm.a * x) + (local_ctm.c * y) + local_ctm.e + ((local_ctm.a + local_ctm.c) * .5f));
+ v = (int)((local_ctm.b * x) + (local_ctm.d * y) + local_ctm.f + ((local_ctm.b + local_ctm.d) * .5f));
/* RJW: The following is voodoo. No idea why it works, but it gives
* the best match between scaled/unscaled/interpolated/non-interpolated
@@ -731,14 +731,14 @@ fz_paint_image_imp(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *shape, fz_pixmap
}
void
-fz_paint_image_with_color(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *shape, fz_pixmap *img, fz_matrix ctm, byte *color)
+fz_paint_image_with_color(fz_pixmap *dst, const fz_bbox *scissor, fz_pixmap *shape, fz_pixmap *img, const fz_matrix *ctm, byte *color)
{
assert(img->n == 1);
fz_paint_image_imp(dst, scissor, shape, img, ctm, color, 255);
}
void
-fz_paint_image(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *shape, fz_pixmap *img, fz_matrix ctm, int alpha)
+fz_paint_image(fz_pixmap *dst, const fz_bbox *scissor, fz_pixmap *shape, fz_pixmap *img, const fz_matrix *ctm, int alpha)
{
assert(dst->n == img->n || (dst->n == 4 && img->n == 2));
fz_paint_image_imp(dst, scissor, shape, img, ctm, NULL, alpha);
diff --git a/draw/draw_blend.c b/draw/draw_blend.c
index e70699d4..1bbf1dd5 100644
--- a/draw/draw_blend.c
+++ b/draw/draw_blend.c
@@ -575,6 +575,7 @@ fz_blend_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha, int blendmode, int is
{
unsigned char *sp, *dp;
fz_bbox bbox;
+ fz_bbox bbox2;
int x, y, w, h, n;
/* TODO: fix this hack! */
@@ -589,8 +590,9 @@ fz_blend_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha, int blendmode, int is
}
}
- bbox = fz_pixmap_bbox_no_ctx(dst);
- bbox = fz_intersect_bbox(bbox, fz_pixmap_bbox_no_ctx(src));
+ fz_pixmap_bbox_no_ctx(dst, &bbox);
+ fz_pixmap_bbox_no_ctx(src, &bbox2);
+ fz_intersect_bbox(&bbox, &bbox2);
x = bbox.x0;
y = bbox.y0;
diff --git a/draw/draw_device.c b/draw/draw_device.c
index e631e472..21fe71db 100644
--- a/draw/draw_device.c
+++ b/draw/draw_device.c
@@ -137,9 +137,9 @@ fz_knockout_begin(fz_draw_device *dev)
state = push_stack(dev);
- bbox = fz_pixmap_bbox(dev->ctx, state->dest);
- bbox = fz_intersect_bbox(bbox, state->scissor);
- dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, bbox);
+ fz_pixmap_bbox(dev->ctx, state->dest, &bbox);
+ fz_intersect_bbox(&bbox, &state->scissor);
+ dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, &bbox);
if (isolated)
{
@@ -157,7 +157,7 @@ fz_knockout_begin(fz_draw_device *dev)
break;
}
if (prev)
- fz_copy_pixmap_rect(ctx, dest, prev, bbox);
+ fz_copy_pixmap_rect(ctx, dest, prev, &bbox);
else
fz_clear_pixmap(ctx, dest);
}
@@ -170,7 +170,7 @@ fz_knockout_begin(fz_draw_device *dev)
}
else
{
- shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, shape);
}
#ifdef DUMP_GROUP_BLENDS
@@ -238,7 +238,7 @@ static void fz_knockout_end(fz_draw_device *dev)
}
static void
-fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, fz_matrix ctm,
+fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
fz_draw_device *dev = devp->user;
@@ -254,14 +254,13 @@ fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, fz_matrix ctm,
if (model == NULL)
model = fz_device_gray;
- fz_reset_gel(dev->gel, state->scissor);
+ fz_reset_gel(dev->gel, &state->scissor);
fz_flatten_fill_path(dev->gel, path, ctm, flatness);
fz_sort_gel(dev->gel);
- bbox = fz_bound_gel(dev->gel);
- bbox = fz_intersect_bbox(bbox, state->scissor);
+ fz_intersect_bbox(fz_bound_gel(dev->gel, &bbox), &state->scissor);
- if (fz_is_empty_rect(bbox))
+ if (fz_is_empty_rect(&bbox))
return;
if (state->blendmode & FZ_BLEND_KNOCKOUT)
@@ -272,15 +271,15 @@ fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, fz_matrix ctm,
colorbv[i] = colorfv[i] * 255;
colorbv[i] = alpha * 255;
- fz_scan_convert(dev->gel, even_odd, bbox, state->dest, colorbv);
+ fz_scan_convert(dev->gel, even_odd, &bbox, state->dest, colorbv);
if (state->shape)
{
- fz_reset_gel(dev->gel, state->scissor);
+ fz_reset_gel(dev->gel, &state->scissor);
fz_flatten_fill_path(dev->gel, path, ctm, flatness);
fz_sort_gel(dev->gel);
colorbv[0] = alpha * 255;
- fz_scan_convert(dev->gel, even_odd, bbox, state->shape, colorbv);
+ fz_scan_convert(dev->gel, even_odd, &bbox, state->shape, colorbv);
}
if (state->blendmode & FZ_BLEND_KNOCKOUT)
@@ -288,7 +287,7 @@ fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, fz_matrix ctm,
}
static void
-fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm,
+fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
fz_draw_device *dev = devp->user;
@@ -308,17 +307,16 @@ fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, fz_
if (linewidth * expansion < 0.1f)
linewidth = 1 / expansion;
- fz_reset_gel(dev->gel, state->scissor);
+ fz_reset_gel(dev->gel, &state->scissor);
if (stroke->dash_len > 0)
fz_flatten_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth);
else
fz_flatten_stroke_path(dev->gel, path, stroke, ctm, flatness, linewidth);
fz_sort_gel(dev->gel);
- bbox = fz_bound_gel(dev->gel);
- bbox = fz_intersect_bbox(bbox, state->scissor);
+ fz_intersect_bbox(fz_bound_gel(dev->gel, &bbox), &state->scissor);
- if (fz_is_empty_rect(bbox))
+ if (fz_is_empty_rect(&bbox))
return;
if (state->blendmode & FZ_BLEND_KNOCKOUT)
@@ -329,10 +327,10 @@ fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, fz_
colorbv[i] = colorfv[i] * 255;
colorbv[i] = alpha * 255;
- fz_scan_convert(dev->gel, 0, bbox, state->dest, colorbv);
+ fz_scan_convert(dev->gel, 0, &bbox, state->dest, colorbv);
if (state->shape)
{
- fz_reset_gel(dev->gel, state->scissor);
+ fz_reset_gel(dev->gel, &state->scissor);
if (stroke->dash_len > 0)
fz_flatten_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth);
else
@@ -340,7 +338,7 @@ fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, fz_
fz_sort_gel(dev->gel);
colorbv[0] = 255;
- fz_scan_convert(dev->gel, 0, bbox, state->shape, colorbv);
+ fz_scan_convert(dev->gel, 0, &bbox, state->shape, colorbv);
}
if (state->blendmode & FZ_BLEND_KNOCKOUT)
@@ -348,7 +346,7 @@ fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, fz_
}
static void
-fz_draw_clip_path(fz_device *devp, fz_path *path, fz_rect rect, int even_odd, fz_matrix ctm)
+fz_draw_clip_path(fz_device *devp, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
{
fz_draw_device *dev = devp->user;
float expansion = fz_matrix_expansion(ctm);
@@ -358,18 +356,21 @@ fz_draw_clip_path(fz_device *devp, fz_path *path, fz_rect rect, int even_odd, fz
fz_colorspace *model;
fz_context *ctx = dev->ctx;
- fz_reset_gel(dev->gel, state->scissor);
+ fz_reset_gel(dev->gel, &state->scissor);
fz_flatten_fill_path(dev->gel, path, ctm, flatness);
fz_sort_gel(dev->gel);
state = push_stack(dev);
model = state->dest->colorspace;
- bbox = fz_bound_gel(dev->gel);
- bbox = fz_intersect_bbox(bbox, state->scissor);
- bbox = fz_intersect_bbox(bbox, fz_bbox_from_rect(rect));
+ fz_intersect_bbox(fz_bound_gel(dev->gel, &bbox), &state->scissor);
+ if (rect)
+ {
+ fz_bbox bbox2;
+ fz_intersect_bbox(&bbox, fz_bbox_from_rect(&bbox2, rect));
+ }
- if (fz_is_empty_rect(bbox) || fz_is_rect_gel(dev->gel))
+ if (fz_is_empty_rect(&bbox) || fz_is_rect_gel(dev->gel))
{
state[1].scissor = bbox;
state[1].mask = NULL;
@@ -381,17 +382,17 @@ fz_draw_clip_path(fz_device *devp, fz_path *path, fz_rect rect, int even_odd, fz
fz_try(ctx)
{
- state[1].mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, state[1].mask);
- state[1].dest = fz_new_pixmap_with_bbox(dev->ctx, model, bbox);
+ state[1].dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox);
fz_clear_pixmap(dev->ctx, state[1].dest);
if (state[1].shape)
{
- state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, state[1].shape);
}
- fz_scan_convert(dev->gel, even_odd, bbox, state[1].mask, NULL);
+ fz_scan_convert(dev->gel, even_odd, &bbox, state[1].mask, NULL);
state[1].blendmode |= FZ_BLEND_ISOLATED;
state[1].scissor = bbox;
@@ -406,7 +407,7 @@ fz_draw_clip_path(fz_device *devp, fz_path *path, fz_rect rect, int even_odd, fz
}
static void
-fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, fz_rect rect, fz_stroke_state *stroke, fz_matrix ctm)
+fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm)
{
fz_draw_device *dev = devp->user;
float expansion = fz_matrix_expansion(ctm);
@@ -420,7 +421,7 @@ fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, fz_rect rect, fz_stroke
if (linewidth * expansion < 0.1f)
linewidth = 1 / expansion;
- fz_reset_gel(dev->gel, state->scissor);
+ fz_reset_gel(dev->gel, &state->scissor);
if (stroke->dash_len > 0)
fz_flatten_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth);
else
@@ -430,24 +431,27 @@ fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, fz_rect rect, fz_stroke
state = push_stack(dev);
model = state->dest->colorspace;
- bbox = fz_bound_gel(dev->gel);
- bbox = fz_intersect_bbox(bbox, state->scissor);
- bbox = fz_intersect_bbox(bbox, fz_bbox_from_rect(rect));
+ fz_intersect_bbox(fz_bound_gel(dev->gel, &bbox), &state->scissor);
+ if (rect)
+ {
+ fz_bbox bbox2;
+ fz_intersect_bbox(&bbox, fz_bbox_from_rect(&bbox2, rect));
+ }
fz_try(ctx)
{
- state[1].mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, state[1].mask);
- state[1].dest = fz_new_pixmap_with_bbox(dev->ctx, model, bbox);
+ state[1].dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox);
fz_clear_pixmap(dev->ctx, state[1].dest);
if (state->shape)
{
- state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, state[1].shape);
}
- if (!fz_is_empty_rect(bbox))
- fz_scan_convert(dev->gel, 0, bbox, state[1].mask, NULL);
+ if (!fz_is_empty_rect(&bbox))
+ fz_scan_convert(dev->gel, 0, &bbox, state[1].mask, NULL);
state[1].blendmode |= FZ_BLEND_ISOLATED;
state[1].scissor = bbox;
@@ -463,15 +467,15 @@ fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, fz_rect rect, fz_stroke
static void
draw_glyph(unsigned char *colorbv, fz_pixmap *dst, fz_pixmap *msk,
- int xorig, int yorig, fz_bbox scissor)
+ int xorig, int yorig, const fz_bbox *scissor)
{
unsigned char *dp, *mp;
fz_bbox bbox;
int x, y, w, h;
- bbox = fz_pixmap_bbox_no_ctx(msk);
- bbox = fz_translate_bbox(bbox, xorig, yorig);
- bbox = fz_intersect_bbox(bbox, scissor); /* scissor < dst */
+ fz_pixmap_bbox_no_ctx(msk, &bbox);
+ fz_translate_bbox(&bbox, xorig, yorig);
+ fz_intersect_bbox(&bbox, scissor); /* scissor < dst */
x = bbox.x0;
y = bbox.y0;
w = bbox.x1 - bbox.x0;
@@ -494,7 +498,7 @@ draw_glyph(unsigned char *colorbv, fz_pixmap *dst, fz_pixmap *msk,
}
static void
-fz_draw_fill_text(fz_device *devp, fz_text *text, fz_matrix ctm,
+fz_draw_fill_text(fz_device *devp, fz_text *text, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
fz_draw_device *dev = devp->user;
@@ -527,7 +531,7 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, fz_matrix ctm,
tm.e = text->items[i].x;
tm.f = text->items[i].y;
- trm = fz_concat(tm, ctm);
+ fz_concat(&trm, &tm, ctm);
x = floorf(trm.e);
y = floorf(trm.f);
@@ -538,28 +542,28 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, fz_matrix ctm,
scissor.x0 -= x; scissor.x1 -= x;
scissor.y0 -= y; scissor.y1 -= y;
- glyph = fz_render_glyph(dev->ctx, text->font, gid, trunc_trm, model, scissor);
+ glyph = fz_render_glyph(dev->ctx, text->font, gid, &trunc_trm, model, scissor);
if (glyph)
{
if (glyph->n == 1)
{
- draw_glyph(colorbv, state->dest, glyph, x, y, state->scissor);
+ draw_glyph(colorbv, state->dest, glyph, x, y, &state->scissor);
if (state->shape)
- draw_glyph(&shapebv, state->shape, glyph, x, y, state->scissor);
+ draw_glyph(&shapebv, state->shape, glyph, x, y, &state->scissor);
}
else
{
- fz_matrix ctm = {glyph->w, 0.0, 0.0, glyph->h, x + glyph->x, y + glyph->y};
- fz_paint_image(state->dest, state->scissor, state->shape, glyph, ctm, alpha * 255);
+ fz_matrix tm = {glyph->w, 0.0, 0.0, glyph->h, x + glyph->x, y + glyph->y};
+ fz_paint_image(state->dest, &state->scissor, state->shape, glyph, &tm, alpha * 255);
}
fz_drop_pixmap(dev->ctx, glyph);
}
else
{
- fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, trm);
+ fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, &trm);
if (path)
{
- fz_draw_fill_path(devp, path, 0, fz_identity, colorspace, color, alpha);
+ fz_draw_fill_path(devp, path, 0, &fz_identity, colorspace, color, alpha);
fz_free_path(dev->ctx, path);
}
else
@@ -574,8 +578,9 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, fz_matrix ctm,
}
static void
-fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm,
- fz_colorspace *colorspace, float *color, float alpha)
+fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke,
+ const fz_matrix *ctm, fz_colorspace *colorspace,
+ float *color, float alpha)
{
fz_draw_device *dev = devp->user;
unsigned char colorbv[FZ_MAX_COLORS + 1];
@@ -605,7 +610,7 @@ fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_
tm.e = text->items[i].x;
tm.f = text->items[i].y;
- trm = fz_concat(tm, ctm);
+ fz_concat(&trm, &tm, ctm);
x = floorf(trm.e);
y = floorf(trm.f);
@@ -616,20 +621,20 @@ fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_
scissor.x0 -= x; scissor.x1 -= x;
scissor.y0 -= y; scissor.y1 -= y;
- glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, trunc_trm, ctm, stroke, scissor);
+ glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, &trunc_trm, ctm, stroke, scissor);
if (glyph)
{
- draw_glyph(colorbv, state->dest, glyph, x, y, state->scissor);
+ draw_glyph(colorbv, state->dest, glyph, x, y, &state->scissor);
if (state->shape)
- draw_glyph(colorbv, state->shape, glyph, x, y, state->scissor);
+ draw_glyph(colorbv, state->shape, glyph, x, y, &state->scissor);
fz_drop_pixmap(dev->ctx, glyph);
}
else
{
- fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, trm);
+ fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, &trm);
if (path)
{
- fz_draw_stroke_path(devp, path, stroke, fz_identity, colorspace, color, alpha);
+ fz_draw_stroke_path(devp, path, stroke, &fz_identity, colorspace, color, alpha);
fz_free_path(dev->ctx, path);
}
else
@@ -644,7 +649,7 @@ fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_
}
static void
-fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
+fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accumulate)
{
fz_draw_device *dev = devp->user;
fz_context *ctx = dev->ctx;
@@ -666,8 +671,10 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
if (accumulate == 0)
{
/* make the mask the exact size needed */
- bbox = fz_bbox_from_rect(fz_bound_text(dev->ctx, text, ctm));
- bbox = fz_intersect_bbox(bbox, state->scissor);
+ fz_rect rect;
+
+ fz_bbox_from_rect(&bbox, fz_bound_text(dev->ctx, text, ctm, &rect));
+ fz_intersect_bbox(&bbox, &state->scissor);
}
else
{
@@ -679,13 +686,13 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
{
if (accumulate == 0 || accumulate == 1)
{
- mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, mask);
- dest = fz_new_pixmap_with_bbox(dev->ctx, model, bbox);
+ dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox);
fz_clear_pixmap(dev->ctx, dest);
if (state->shape)
{
- shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, shape);
}
else
@@ -706,7 +713,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
dev->top--;
}
- if (!fz_is_empty_rect(bbox) && mask)
+ if (!fz_is_empty_rect(&bbox) && mask)
{
tm = text->trm;
@@ -718,7 +725,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
tm.e = text->items[i].x;
tm.f = text->items[i].y;
- trm = fz_concat(tm, ctm);
+ fz_concat(&trm, &tm, ctm);
x = floorf(trm.e);
y = floorf(trm.f);
@@ -726,17 +733,17 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
trunc_trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX);
trunc_trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX);
- glyph = fz_render_glyph(dev->ctx, text->font, gid, trunc_trm, model, bbox);
+ glyph = fz_render_glyph(dev->ctx, text->font, gid, &trunc_trm, model, bbox);
if (glyph)
{
- draw_glyph(NULL, mask, glyph, x, y, bbox);
+ draw_glyph(NULL, mask, glyph, x, y, &bbox);
if (state[1].shape)
- draw_glyph(NULL, state[1].shape, glyph, x, y, bbox);
+ draw_glyph(NULL, state[1].shape, glyph, x, y, &bbox);
fz_drop_pixmap(dev->ctx, glyph);
}
else
{
- fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, trm);
+ fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, &trm);
if (path)
{
fz_pixmap *old_dest;
@@ -748,7 +755,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
state[0].mask = NULL;
fz_try(ctx)
{
- fz_draw_fill_path(devp, path, 0, fz_identity, fz_device_gray, &white, 1);
+ fz_draw_fill_path(devp, path, 0, &fz_identity, fz_device_gray, &white, 1);
}
fz_always(ctx)
{
@@ -778,7 +785,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
}
static void
-fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm)
+fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm)
{
fz_draw_device *dev = devp->user;
fz_context *ctx = dev->ctx;
@@ -789,20 +796,21 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke
int i, x, y, gid;
fz_draw_state *state = push_stack(dev);
fz_colorspace *model = state->dest->colorspace;
+ fz_rect rect;
/* make the mask the exact size needed */
- bbox = fz_bbox_from_rect(fz_bound_text(dev->ctx, text, ctm));
- bbox = fz_intersect_bbox(bbox, state->scissor);
+ fz_bbox_from_rect(&bbox, fz_bound_text(dev->ctx, text, ctm, &rect));
+ fz_intersect_bbox(&bbox, &state->scissor);
fz_try(ctx)
{
- state[1].mask = mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].mask = mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, mask);
- state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, bbox);
+ state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox);
fz_clear_pixmap(dev->ctx, dest);
if (state->shape)
{
- state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, shape);
}
else
@@ -814,7 +822,7 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke
dump_spaces(dev->top-1, "Clip (stroke text) begin\n");
#endif
- if (!fz_is_empty_rect(bbox))
+ if (!fz_is_empty_rect(&bbox))
{
tm = text->trm;
@@ -826,7 +834,7 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke
tm.e = text->items[i].x;
tm.f = text->items[i].y;
- trm = fz_concat(tm, ctm);
+ fz_concat(&trm, &tm, ctm);
x = floorf(trm.e);
y = floorf(trm.f);
@@ -834,17 +842,17 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke
trunc_trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX);
trunc_trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX);
- glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, trunc_trm, ctm, stroke, bbox);
+ glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, &trunc_trm, ctm, stroke, bbox);
if (glyph)
{
- draw_glyph(NULL, mask, glyph, x, y, bbox);
+ draw_glyph(NULL, mask, glyph, x, y, &bbox);
if (shape)
- draw_glyph(NULL, shape, glyph, x, y, bbox);
+ draw_glyph(NULL, shape, glyph, x, y, &bbox);
fz_drop_pixmap(dev->ctx, glyph);
}
else
{
- fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, trm);
+ fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, &trm);
if (path)
{
fz_pixmap *old_dest;
@@ -856,7 +864,7 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke
state[0].mask = NULL;
fz_try(ctx)
{
- fz_draw_stroke_path(devp, path, stroke, fz_identity, fz_device_gray, &white, 1);
+ fz_draw_stroke_path(devp, path, stroke, &fz_identity, fz_device_gray, &white, 1);
}
fz_always(ctx)
{
@@ -884,12 +892,12 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke
}
static void
-fz_draw_ignore_text(fz_device *dev, fz_text *text, fz_matrix ctm)
+fz_draw_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm)
{
}
static void
-fz_draw_fill_shade(fz_device *devp, fz_shade *shade, fz_matrix ctm, float alpha)
+fz_draw_fill_shade(fz_device *devp, fz_shade *shade, const fz_matrix *ctm, float alpha)
{
fz_draw_device *dev = devp->user;
fz_rect bounds;
@@ -900,11 +908,11 @@ fz_draw_fill_shade(fz_device *devp, fz_shade *shade, fz_matrix ctm, float alpha)
fz_draw_state *state = &dev->stack[dev->top];
fz_colorspace *model = state->dest->colorspace;
- bounds = fz_bound_shade(dev->ctx, shade, ctm);
+ fz_bound_shade(dev->ctx, shade, ctm, &bounds);
scissor = state->scissor;
- bbox = fz_intersect_bbox(fz_bbox_from_rect(bounds), scissor);
+ fz_intersect_bbox(fz_bbox_from_rect(&bbox, &bounds), &scissor);
- if (fz_is_empty_rect(bbox))
+ if (fz_is_empty_rect(&bbox))
return;
if (!model)
@@ -921,11 +929,11 @@ fz_draw_fill_shade(fz_device *devp, fz_shade *shade, fz_matrix ctm, float alpha)
if (alpha < 1)
{
- dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, bbox);
+ dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, &bbox);
fz_clear_pixmap(dev->ctx, dest);
if (shape)
{
- shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, shape);
}
}
@@ -962,9 +970,9 @@ fz_draw_fill_shade(fz_device *devp, fz_shade *shade, fz_matrix ctm, float alpha)
}
}
- fz_paint_shade(dev->ctx, shade, ctm, dest, bbox);
+ fz_paint_shade(dev->ctx, shade, ctm, dest, &bbox);
if (shape)
- fz_clear_pixmap_rect_with_value(dev->ctx, shape, 255, bbox);
+ fz_clear_pixmap_rect_with_value(dev->ctx, shape, 255, &bbox);
if (alpha < 1)
{
@@ -982,7 +990,7 @@ fz_draw_fill_shade(fz_device *devp, fz_shade *shade, fz_matrix ctm, float alpha)
}
static fz_pixmap *
-fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int dy, int gridfit, fz_bbox *clip)
+fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int dy, int gridfit, const fz_bbox *clip)
{
fz_pixmap *scaled;
fz_context *ctx = dev->ctx;
@@ -992,7 +1000,7 @@ fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x
/* Unrotated or X-flip or Y-flip or XY-flip */
fz_matrix m = *ctm;
if (gridfit)
- m = fz_gridfit_matrix(m);
+ fz_gridfit_matrix(&m);
scaled = fz_scale_pixmap_cached(ctx, image, m.e, m.f, m.a, m.d, clip, dev->cache_x, dev->cache_y);
if (!scaled)
return NULL;
@@ -1009,7 +1017,7 @@ fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x
fz_matrix m = *ctm;
fz_bbox rclip;
if (gridfit)
- m = fz_gridfit_matrix(m);
+ fz_gridfit_matrix(&m);
if (clip)
{
rclip.x0 = clip->y0;
@@ -1017,7 +1025,7 @@ fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x
rclip.x1 = clip->y1;
rclip.y1 = clip->x1;
}
- scaled = fz_scale_pixmap_cached(ctx, image, m.f, m.e, m.b, m.c, (clip ? &rclip : 0), dev->cache_x, dev->cache_y);
+ scaled = fz_scale_pixmap_cached(ctx, image, m.f, m.e, m.b, m.c, (clip ? &rclip : NULL), dev->cache_x, dev->cache_y);
if (!scaled)
return NULL;
ctm->b = scaled->w;
@@ -1038,7 +1046,7 @@ fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x
}
static void
-fz_draw_fill_image(fz_device *devp, fz_image *image, fz_matrix ctm, float alpha)
+fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float alpha)
{
fz_draw_device *dev = devp->user;
fz_pixmap *converted = NULL;
@@ -1050,9 +1058,10 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, fz_matrix ctm, float alpha)
fz_context *ctx = dev->ctx;
fz_draw_state *state = &dev->stack[dev->top];
fz_colorspace *model = state->dest->colorspace;
- fz_bbox clip = fz_pixmap_bbox(ctx, state->dest);
+ fz_bbox clip;
+ fz_matrix local_ctm = *ctm;
- clip = fz_intersect_bbox(clip, state->scissor);
+ fz_intersect_bbox(fz_pixmap_bbox(ctx, state->dest, &clip), &state->scissor);
fz_var(scaled);
@@ -1065,8 +1074,8 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, fz_matrix ctm, float alpha)
if (image->w == 0 || image->h == 0)
return;
- dx = sqrtf(ctm.a * ctm.a + ctm.b * ctm.b);
- dy = sqrtf(ctm.c * ctm.c + ctm.d * ctm.d);
+ dx = sqrtf(local_ctm.a * local_ctm.a + local_ctm.b * local_ctm.b);
+ dy = sqrtf(local_ctm.c * local_ctm.c + local_ctm.d * local_ctm.d);
pixmap = fz_image_to_pixmap(ctx, image, dx, dy);
orig_pixmap = pixmap;
@@ -1086,7 +1095,9 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, fz_matrix ctm, float alpha)
if (pixmap->colorspace != model && !after)
{
- converted = fz_new_pixmap_with_bbox(ctx, model, fz_pixmap_bbox(ctx, pixmap));
+ fz_bbox bbox;
+ fz_pixmap_bbox(ctx, pixmap, &bbox);
+ converted = fz_new_pixmap_with_bbox(ctx, model, &bbox);
fz_convert_pixmap(ctx, converted, pixmap);
pixmap = converted;
}
@@ -1094,7 +1105,7 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, fz_matrix ctm, float alpha)
if (dx < pixmap->w && dy < pixmap->h)
{
int gridfit = alpha == 1.0f && !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3);
- scaled = fz_transform_pixmap(dev, pixmap, &ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip);
+ scaled = fz_transform_pixmap(dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip);
if (!scaled)
{
if (dx < 1)
@@ -1116,13 +1127,15 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, fz_matrix ctm, float alpha)
}
else
{
- converted = fz_new_pixmap_with_bbox(ctx, model, fz_pixmap_bbox(ctx, pixmap));
+ fz_bbox bbox;
+ fz_pixmap_bbox(ctx, pixmap, &bbox);
+ converted = fz_new_pixmap_with_bbox(ctx, model, &bbox);
fz_convert_pixmap(ctx, converted, pixmap);
pixmap = converted;
}
}
- fz_paint_image(state->dest, state->scissor, state->shape, pixmap, ctm, alpha * 255);
+ fz_paint_image(state->dest, &state->scissor, state->shape, pixmap, &local_ctm, alpha * 255);
if (state->blendmode & FZ_BLEND_KNOCKOUT)
fz_knockout_end(dev);
@@ -1140,7 +1153,7 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, fz_matrix ctm, float alpha)
}
static void
-fz_draw_fill_image_mask(fz_device *devp, fz_image *image, fz_matrix ctm,
+fz_draw_fill_image_mask(fz_device *devp, fz_image *image, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
fz_draw_device *dev = devp->user;
@@ -1154,15 +1167,17 @@ fz_draw_fill_image_mask(fz_device *devp, fz_image *image, fz_matrix ctm,
fz_context *ctx = dev->ctx;
fz_draw_state *state = &dev->stack[dev->top];
fz_colorspace *model = state->dest->colorspace;
- fz_bbox clip = fz_pixmap_bbox(ctx, state->dest);
+ fz_bbox clip;
+ fz_matrix local_ctm = *ctm;
- clip = fz_intersect_bbox(clip, state->scissor);
+ fz_pixmap_bbox(ctx, state->dest, &clip);
+ fz_intersect_bbox(&clip, &state->scissor);
if (image->w == 0 || image->h == 0)
return;
- dx = sqrtf(ctm.a * ctm.a + ctm.b * ctm.b);
- dy = sqrtf(ctm.c * ctm.c + ctm.d * ctm.d);
+ dx = sqrtf(local_ctm.a * local_ctm.a + local_ctm.b * local_ctm.b);
+ dy = sqrtf(local_ctm.c * local_ctm.c + local_ctm.d * local_ctm.d);
pixmap = fz_image_to_pixmap(ctx, image, dx, dy);
orig_pixmap = pixmap;
@@ -1174,7 +1189,7 @@ fz_draw_fill_image_mask(fz_device *devp, fz_image *image, fz_matrix ctm,
if (dx < pixmap->w && dy < pixmap->h)
{
int gridfit = alpha == 1.0f && !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3);
- scaled = fz_transform_pixmap(dev, pixmap, &ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip);
+ scaled = fz_transform_pixmap(dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip);
if (!scaled)
{
if (dx < 1)
@@ -1192,7 +1207,7 @@ fz_draw_fill_image_mask(fz_device *devp, fz_image *image, fz_matrix ctm,
colorbv[i] = colorfv[i] * 255;
colorbv[i] = alpha * 255;
- fz_paint_image_with_color(state->dest, state->scissor, state->shape, pixmap, ctm, colorbv);
+ fz_paint_image_with_color(state->dest, &state->scissor, state->shape, pixmap, &local_ctm, colorbv);
if (scaled)
fz_drop_pixmap(dev->ctx, scaled);
@@ -1211,7 +1226,7 @@ fz_draw_fill_image_mask(fz_device *devp, fz_image *image, fz_matrix ctm,
}
static void
-fz_draw_clip_image_mask(fz_device *devp, fz_image *image, fz_rect rect, fz_matrix ctm)
+fz_draw_clip_image_mask(fz_device *devp, fz_image *image, const fz_rect *rect, const fz_matrix *ctm)
{
fz_draw_device *dev = devp->user;
fz_context *ctx = dev->ctx;
@@ -1225,9 +1240,12 @@ fz_draw_clip_image_mask(fz_device *devp, fz_image *image, fz_rect rect, fz_matri
int dx, dy;
fz_draw_state *state = push_stack(dev);
fz_colorspace *model = state->dest->colorspace;
- fz_bbox clip = fz_pixmap_bbox(ctx, state->dest);
+ fz_bbox clip;
+ fz_matrix local_ctm = *ctm;
+ fz_rect urect;
- clip = fz_intersect_bbox(clip, state->scissor);
+ fz_pixmap_bbox(ctx, state->dest, &clip);
+ fz_intersect_bbox(&clip, &state->scissor);
fz_var(mask);
fz_var(dest);
@@ -1249,26 +1267,31 @@ fz_draw_clip_image_mask(fz_device *devp, fz_image *image, fz_rect rect, fz_matri
dump_spaces(dev->top-1, "Clip (image mask) begin\n");
#endif
- bbox = fz_bbox_from_rect(fz_transform_rect(ctm, fz_unit_rect));
- bbox = fz_intersect_bbox(bbox, state->scissor);
- bbox = fz_intersect_bbox(bbox, fz_bbox_from_rect(rect));
+ urect = fz_unit_rect;
+ fz_bbox_from_rect(&bbox, fz_transform_rect(&urect, &local_ctm));
+ fz_intersect_bbox(&bbox, &state->scissor);
+ if (rect)
+ {
+ fz_bbox bbox2;
+ fz_intersect_bbox(&bbox, fz_bbox_from_rect(&bbox2, rect));
+ }
- dx = sqrtf(ctm.a * ctm.a + ctm.b * ctm.b);
- dy = sqrtf(ctm.c * ctm.c + ctm.d * ctm.d);
+ dx = sqrtf(local_ctm.a * local_ctm.a + local_ctm.b * local_ctm.b);
+ dy = sqrtf(local_ctm.c * local_ctm.c + local_ctm.d * local_ctm.d);
fz_try(ctx)
{
pixmap = fz_image_to_pixmap(ctx, image, dx, dy);
orig_pixmap = pixmap;
- state[1].mask = mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].mask = mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, mask);
- state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, bbox);
+ state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox);
fz_clear_pixmap(dev->ctx, dest);
if (state->shape)
{
- state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, shape);
}
@@ -1278,7 +1301,7 @@ fz_draw_clip_image_mask(fz_device *devp, fz_image *image, fz_rect rect, fz_matri
if (dx < pixmap->w && dy < pixmap->h)
{
int gridfit = !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3);
- scaled = fz_transform_pixmap(dev, pixmap, &ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip);
+ scaled = fz_transform_pixmap(dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip);
if (!scaled)
{
if (dx < 1)
@@ -1290,7 +1313,7 @@ fz_draw_clip_image_mask(fz_device *devp, fz_image *image, fz_rect rect, fz_matri
if (scaled)
pixmap = scaled;
}
- fz_paint_image(mask, bbox, state->shape, pixmap, ctm, 255);
+ fz_paint_image(mask, &bbox, state->shape, pixmap, &local_ctm, 255);
}
fz_always(ctx)
{
@@ -1356,7 +1379,7 @@ fz_draw_pop_clip(fz_device *devp)
}
static void
-fz_draw_begin_mask(fz_device *devp, fz_rect rect, int luminosity, fz_colorspace *colorspace, float *colorfv)
+fz_draw_begin_mask(fz_device *devp, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *colorfv)
{
fz_draw_device *dev = devp->user;
fz_pixmap *dest;
@@ -1365,12 +1388,11 @@ fz_draw_begin_mask(fz_device *devp, fz_rect rect, int luminosity, fz_colorspace
fz_pixmap *shape = state->shape;
fz_context *ctx = dev->ctx;
- bbox = fz_bbox_from_rect(rect);
- bbox = fz_intersect_bbox(bbox, state->scissor);
+ fz_intersect_bbox(fz_bbox_from_rect(&bbox, rect), &state->scissor);
fz_try(ctx)
{
- state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, fz_device_gray, bbox);
+ state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, fz_device_gray, &bbox);
if (state->shape)
{
/* FIXME: If we ever want to support AIS true, then
@@ -1446,8 +1468,8 @@ fz_draw_end_mask(fz_device *devp)
state[1].mask = NULL;
/* create new dest scratch buffer */
- bbox = fz_pixmap_bbox(ctx, temp);
- dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, bbox);
+ fz_pixmap_bbox(ctx, temp, &bbox);
+ dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, &bbox);
fz_clear_pixmap(dev->ctx, dest);
/* push soft mask as clip mask */
@@ -1458,14 +1480,14 @@ fz_draw_end_mask(fz_device *devp)
* clip mask when we pop. So create a new shape now. */
if (state[0].shape)
{
- state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, state[1].shape);
}
state[1].scissor = bbox;
}
static void
-fz_draw_begin_group(fz_device *devp, fz_rect rect, int isolated, int knockout, int blendmode, float alpha)
+fz_draw_begin_group(fz_device *devp, const fz_rect *rect, int isolated, int knockout, int blendmode, float alpha)
{
fz_draw_device *dev = devp->user;
fz_bbox bbox;
@@ -1478,12 +1500,11 @@ fz_draw_begin_group(fz_device *devp, fz_rect rect, int isolated, int knockout, i
fz_knockout_begin(dev);
state = push_stack(dev);
- bbox = fz_bbox_from_rect(rect);
- bbox = fz_intersect_bbox(bbox, state->scissor);
+ fz_intersect_bbox(fz_bbox_from_rect(&bbox, rect), &state->scissor);
fz_try(ctx)
{
- state[1].dest = dest = fz_new_pixmap_with_bbox(ctx, model, bbox);
+ state[1].dest = dest = fz_new_pixmap_with_bbox(ctx, model, &bbox);
#ifndef ATTEMPT_KNOCKOUT_AND_ISOLATED
knockout = 0;
@@ -1496,7 +1517,7 @@ fz_draw_begin_group(fz_device *devp, fz_rect rect, int isolated, int knockout, i
}
else
{
- fz_copy_pixmap_rect(dev->ctx, dest, state[0].dest, bbox);
+ fz_copy_pixmap_rect(dev->ctx, dest, state[0].dest, &bbox);
}
if (blendmode == 0 && alpha == 1.0 && isolated)
@@ -1507,7 +1528,7 @@ fz_draw_begin_group(fz_device *devp, fz_rect rect, int isolated, int knockout, i
}
else
{
- state[1].shape = shape = fz_new_pixmap_with_bbox(ctx, NULL, bbox);
+ state[1].shape = shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox);
fz_clear_pixmap(dev->ctx, shape);
}
@@ -1586,7 +1607,7 @@ fz_draw_end_group(fz_device *devp)
}
static void
-fz_draw_begin_tile(fz_device *devp, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm)
+fz_draw_begin_tile(fz_device *devp, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm)
{
fz_draw_device *dev = devp->user;
fz_pixmap *dest = NULL;
@@ -1595,6 +1616,7 @@ fz_draw_begin_tile(fz_device *devp, fz_rect area, fz_rect view, float xstep, flo
fz_context *ctx = dev->ctx;
fz_draw_state *state = &dev->stack[dev->top];
fz_colorspace *model = state->dest->colorspace;
+ fz_rect local_view = *view;
/* area, view, xstep, ystep are in pattern space */
/* ctm maps from pattern space to device space */
@@ -1603,7 +1625,7 @@ fz_draw_begin_tile(fz_device *devp, fz_rect area, fz_rect view, float xstep, flo
fz_knockout_begin(dev);
state = push_stack(dev);
- bbox = fz_bbox_from_rect(fz_transform_rect(ctm, view));
+ fz_bbox_from_rect(&bbox, fz_transform_rect(&local_view, ctm));
/* We should never have a bbox that entirely covers our destination.
* If we do, then the check for only 1 tile being visible above has
* failed. Actually, this *can* fail due to the round_rect, at extreme
@@ -1613,19 +1635,19 @@ fz_draw_begin_tile(fz_device *devp, fz_rect area, fz_rect view, float xstep, flo
*/
fz_try(ctx)
{
- state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, bbox);
+ state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox);
fz_clear_pixmap(ctx, dest);
shape = state[0].shape;
if (shape)
{
- state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, bbox);
+ state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox);
fz_clear_pixmap(ctx, shape);
}
state[1].blendmode |= FZ_BLEND_ISOLATED;
state[1].xstep = xstep;
state[1].ystep = ystep;
- state[1].area = fz_bbox_from_rect(area);
- state[1].ctm = ctm;
+ fz_bbox_from_rect(&state[1].area, area);
+ state[1].ctm = *ctm;
#ifdef DUMP_GROUP_BLENDS
dump_spaces(dev->top-1, "Tile begin\n");
#endif
@@ -1665,12 +1687,11 @@ fz_draw_end_tile(fz_device *devp)
/* Fudge the scissor bbox a little to allow for inaccuracies in the
* matrix inversion. */
- scissor_tmp = fz_rect_from_bbox(state[0].scissor);
- scissor_tmp = fz_expand_rect(scissor_tmp, 1);
- scissor_tmp = fz_transform_rect(fz_invert_matrix(ctm), scissor_tmp);
- scissor = fz_bbox_from_rect(scissor_tmp);
- area = fz_intersect_bbox(area, scissor);
+ fz_rect_from_bbox(&scissor_tmp, &state[0].scissor);
+ fz_transform_rect(fz_expand_rect(&scissor_tmp, 1), fz_invert_matrix(&ttm, &ctm));
+ fz_intersect_bbox(&area, fz_bbox_from_rect(&scissor, &scissor_tmp));
+ /* FIXME: area is a bbox, so FP not appropriate here */
x0 = floorf(area.x0 / xstep);
y0 = floorf(area.y0 / ystep);
x1 = ceilf(area.x1 / xstep);
@@ -1699,7 +1720,8 @@ fz_draw_end_tile(fz_device *devp)
{
for (x = x0; x < x1; x++)
{
- ttm = fz_concat(fz_translate(x * xstep, y * ystep), ctm);
+ ttm = ctm;
+ fz_pre_translate(&ttm, x * xstep, y * ystep);
state[1].dest->x = ttm.e;
state[1].dest->y = ttm.f;
if (state[1].dest->x > 0 && state[1].dest->x + state[1].dest->w < 0)
@@ -1709,7 +1731,8 @@ fz_draw_end_tile(fz_device *devp)
fz_paint_pixmap_with_bbox(state[0].dest, state[1].dest, 255, state[0].scissor);
if (state[1].shape)
{
- ttm = fz_concat(fz_translate(x * xstep, y * ystep), shapectm);
+ ttm = shapectm;
+ fz_pre_translate(&ttm, x * xstep, y * ystep);
state[1].shape->x = ttm.e;
state[1].shape->y = ttm.f;
fz_paint_pixmap_with_bbox(state[0].shape, state[1].shape, 255, state[0].scissor);
@@ -1829,19 +1852,19 @@ fz_new_draw_device(fz_context *ctx, fz_pixmap *dest)
}
fz_device *
-fz_new_draw_device_with_bbox(fz_context *ctx, fz_pixmap *dest, fz_bbox clip)
+fz_new_draw_device_with_bbox(fz_context *ctx, fz_pixmap *dest, const fz_bbox *clip)
{
fz_device *dev = fz_new_draw_device(ctx, dest);
fz_draw_device *ddev = dev->user;
- if (clip.x0 > ddev->stack[0].scissor.x0)
- ddev->stack[0].scissor.x0 = clip.x0;
- if (clip.x1 < ddev->stack[0].scissor.x1)
- ddev->stack[0].scissor.x1 = clip.x1;
- if (clip.y0 > ddev->stack[0].scissor.y0)
- ddev->stack[0].scissor.y0 = clip.y0;
- if (clip.y1 < ddev->stack[0].scissor.y1)
- ddev->stack[0].scissor.y1 = clip.y1;
+ if (clip->x0 > ddev->stack[0].scissor.x0)
+ ddev->stack[0].scissor.x0 = clip->x0;
+ if (clip->x1 < ddev->stack[0].scissor.x1)
+ ddev->stack[0].scissor.x1 = clip->x1;
+ if (clip->y0 > ddev->stack[0].scissor.y0)
+ ddev->stack[0].scissor.y0 = clip->y0;
+ if (clip->y1 < ddev->stack[0].scissor.y1)
+ ddev->stack[0].scissor.y1 = clip->y1;
return dev;
}
diff --git a/draw/draw_edge.c b/draw/draw_edge.c
index 6c22aa73..dca6a648 100644
--- a/draw/draw_edge.c
+++ b/draw/draw_edge.c
@@ -203,7 +203,7 @@ fz_new_gel(fz_context *ctx)
}
void
-fz_reset_gel(fz_gel *gel, fz_bbox clip)
+fz_reset_gel(fz_gel *gel, const fz_bbox *clip)
{
fz_aa_context *ctxaa = gel->ctx->aa;
@@ -213,10 +213,10 @@ fz_reset_gel(fz_gel *gel, fz_bbox clip)
gel->clip.x1 = gel->clip.y1 = BBOX_MIN;
}
else {
- gel->clip.x0 = clip.x0 * fz_aa_hscale;
- gel->clip.x1 = clip.x1 * fz_aa_hscale;
- gel->clip.y0 = clip.y0 * fz_aa_vscale;
- gel->clip.y1 = clip.y1 * fz_aa_vscale;
+ gel->clip.x0 = clip->x0 * fz_aa_hscale;
+ gel->clip.x1 = clip->x1 * fz_aa_hscale;
+ gel->clip.y0 = clip->y0 * fz_aa_vscale;
+ gel->clip.y1 = clip->y1 * fz_aa_vscale;
}
gel->bbox.x0 = gel->bbox.y0 = BBOX_MAX;
@@ -235,17 +235,21 @@ fz_free_gel(fz_gel *gel)
fz_free(gel->ctx, gel);
}
-fz_bbox
-fz_bound_gel(fz_gel *gel)
+fz_bbox *
+fz_bound_gel(const fz_gel *gel, fz_bbox *bbox)
{
- fz_bbox bbox;
fz_aa_context *ctxaa = gel->ctx->aa;
if (gel->len == 0)
- return fz_empty_bbox;
- bbox.x0 = fz_idiv(gel->bbox.x0, fz_aa_hscale);
- bbox.y0 = fz_idiv(gel->bbox.y0, fz_aa_vscale);
- bbox.x1 = fz_idiv(gel->bbox.x1, fz_aa_hscale) + 1;
- bbox.y1 = fz_idiv(gel->bbox.y1, fz_aa_vscale) + 1;
+ {
+ *bbox = fz_empty_bbox;
+ }
+ else
+ {
+ bbox->x0 = fz_idiv(gel->bbox.x0, fz_aa_hscale);
+ bbox->y0 = fz_idiv(gel->bbox.y0, fz_aa_vscale);
+ bbox->x1 = fz_idiv(gel->bbox.x1, fz_aa_hscale) + 1;
+ bbox->y1 = fz_idiv(gel->bbox.y1, fz_aa_vscale) + 1;
+ }
return bbox;
}
@@ -666,7 +670,7 @@ static inline void blit_aa(fz_pixmap *dst, int x, int y,
}
static void
-fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
+fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_bbox *clip,
fz_pixmap *dst, unsigned char *color)
{
unsigned char *alphas;
@@ -682,14 +686,14 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
int xofs = xmin * fz_aa_hscale;
- int skipx = clip.x0 - xmin;
- int clipn = clip.x1 - clip.x0;
+ int skipx = clip->x0 - xmin;
+ int clipn = clip->x1 - clip->x0;
if (gel->len == 0)
return;
- assert(clip.x0 >= xmin);
- assert(clip.x1 <= 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));
@@ -719,7 +723,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
yd = fz_idiv(y, fz_aa_vscale);
/* Quickly skip to the start of the clip region */
- while (yd < clip.y0 && (gel->alen > 0 || e < gel->len))
+ while (yd < clip->y0 && (gel->alen > 0 || e < gel->len))
{
/* rh = remaining height = number of subscanlines left to be
* inserted into the current scanline, which will be plotted
@@ -738,14 +742,14 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
yd++;
}
/* Skip any whole scanlines we can */
- while (yd < clip.y0 && h0 >= fz_aa_vscale)
+ while (yd < clip->y0 && h0 >= fz_aa_vscale)
{
h0 -= fz_aa_vscale;
yd++;
}
/* If we haven't hit the start of the clip region, then we
* have less than a scanline left. */
- if (yd < clip.y0)
+ if (yd < clip->y0)
{
h0 = 0;
}
@@ -770,7 +774,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
memset(deltas, 0, (skipx + clipn) * sizeof(int));
}
yd = yc;
- if (yd >= clip.y1)
+ if (yd >= clip->y1)
break;
/* height = The number of subscanlines with identical edge
@@ -792,7 +796,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
blit_aa(dst, xmin + skipx, yd, alphas + skipx, clipn, color);
memset(deltas, 0, (skipx + clipn) * sizeof(int));
yd++;
- if (yd >= clip.y1)
+ if (yd >= clip->y1)
break;
h0 -= rh;
}
@@ -812,7 +816,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
* to recalculate deltas here. */
blit_aa(dst, xmin + skipx, yd, alphas + skipx, clipn, color);
yd++;
- if (yd >= clip.y1)
+ if (yd >= clip->y1)
goto clip_ended;
h0 -= fz_aa_vscale;
}
@@ -836,7 +840,7 @@ advance:
y += height;
}
- if (yd < clip.y1)
+ if (yd < clip->y1)
{
undelta_aa(ctxaa, alphas, deltas, skipx + clipn);
blit_aa(dst, xmin + skipx, yd, alphas + skipx, clipn, color);
@@ -851,7 +855,7 @@ clip_ended:
*/
static inline void blit_sharp(int x0, int x1, int y,
- fz_bbox clip, fz_pixmap *dst, unsigned char *color)
+ const fz_bbox *clip, fz_pixmap *dst, unsigned char *color)
{
unsigned char *dp;
x0 = fz_clampi(x0, dst->x, dst->x + dst->w);
@@ -867,7 +871,7 @@ static inline void blit_sharp(int x0, int x1, int y,
}
static inline void non_zero_winding_sharp(fz_gel *gel, int y,
- fz_bbox clip, fz_pixmap *dst, unsigned char *color)
+ const fz_bbox *clip, fz_pixmap *dst, unsigned char *color)
{
int winding = 0;
int x = 0;
@@ -883,7 +887,7 @@ static inline void non_zero_winding_sharp(fz_gel *gel, int y,
}
static inline void even_odd_sharp(fz_gel *gel, int y,
- fz_bbox clip, fz_pixmap *dst, unsigned char *color)
+ const fz_bbox *clip, fz_pixmap *dst, unsigned char *color)
{
int even = 0;
int x = 0;
@@ -899,7 +903,7 @@ static inline void even_odd_sharp(fz_gel *gel, int y,
}
static void
-fz_scan_convert_sharp(fz_gel *gel, int eofill, fz_bbox clip,
+fz_scan_convert_sharp(fz_gel *gel, int eofill, const fz_bbox *clip,
fz_pixmap *dst, unsigned char *color)
{
int e = 0;
@@ -909,16 +913,16 @@ fz_scan_convert_sharp(fz_gel *gel, int eofill, fz_bbox clip,
gel->alen = 0;
/* Skip any lines before the clip region */
- if (y < clip.y0)
+ if (y < clip->y0)
{
while (gel->alen > 0 || e < gel->len)
{
height = insert_active(gel, y, &e);
y += height;
- if (y >= clip.y0)
+ if (y >= clip->y0)
{
- height -= y - clip.y0;
- y = clip.y0;
+ height -= y - clip->y0;
+ y = clip->y0;
break;
}
}
@@ -934,8 +938,8 @@ fz_scan_convert_sharp(fz_gel *gel, int eofill, fz_bbox clip,
else
{
int h;
- if (height >= clip.y1 - y)
- height = clip.y1 - y;
+ if (height >= clip->y1 - y)
+ height = clip->y1 - y;
h = height;
while (h--)
@@ -947,7 +951,7 @@ fz_scan_convert_sharp(fz_gel *gel, int eofill, fz_bbox clip,
y++;
}
}
- if (y >= clip.y1)
+ if (y >= clip->y1)
break;
advance_active(gel, height);
@@ -955,7 +959,7 @@ fz_scan_convert_sharp(fz_gel *gel, int eofill, fz_bbox clip,
}
void
-fz_scan_convert(fz_gel *gel, int eofill, fz_bbox clip,
+fz_scan_convert(fz_gel *gel, int eofill, const fz_bbox *clip,
fz_pixmap *dst, unsigned char *color)
{
fz_aa_context *ctxaa = gel->ctx->aa;
diff --git a/draw/draw_glyph.c b/draw/draw_glyph.c
index de2f47c2..3ad2f10f 100644
--- a/draw/draw_glyph.c
+++ b/draw/draw_glyph.c
@@ -95,7 +95,7 @@ fz_keep_glyph_cache(fz_context *ctx)
}
fz_pixmap *
-fz_render_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *stroke, fz_bbox scissor)
+fz_render_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, const fz_matrix *ctm, fz_stroke_state *stroke, fz_bbox scissor)
{
if (font->ft_face)
{
@@ -116,13 +116,14 @@ fz_render_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm,
This must not be inserted into the cache.
*/
fz_pixmap *
-fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_colorspace *model, fz_bbox scissor)
+fz_render_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *ctm, fz_colorspace *model, fz_bbox scissor)
{
fz_glyph_cache *cache;
fz_glyph_key key;
fz_pixmap *val;
float size = fz_matrix_expansion(ctm);
int do_cache;
+ fz_matrix local_ctm = *ctm;
if (size <= MAX_GLYPH_SIZE)
{
@@ -141,16 +142,16 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_color
memset(&key, 0, sizeof key);
key.font = font;
key.gid = gid;
- key.a = ctm.a * 65536;
- key.b = ctm.b * 65536;
- key.c = ctm.c * 65536;
- key.d = ctm.d * 65536;
- key.e = (ctm.e - floorf(ctm.e)) * 256;
- key.f = (ctm.f - floorf(ctm.f)) * 256;
+ key.a = local_ctm.a * 65536;
+ key.b = local_ctm.b * 65536;
+ key.c = local_ctm.c * 65536;
+ key.d = local_ctm.d * 65536;
+ key.e = (local_ctm.e - floorf(local_ctm.e)) * 256;
+ key.f = (local_ctm.f - floorf(local_ctm.f)) * 256;
key.aa = fz_aa_level(ctx);
- ctm.e = floorf(ctm.e) + key.e / 256.0f;
- ctm.f = floorf(ctm.f) + key.f / 256.0f;
+ local_ctm.e = floorf(local_ctm.e) + key.e / 256.0f;
+ local_ctm.f = floorf(local_ctm.f) + key.f / 256.0f;
fz_lock(ctx, FZ_LOCK_GLYPHCACHE);
val = fz_hash_find(ctx, cache->hash, &key);
@@ -165,7 +166,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_color
{
if (font->ft_face)
{
- val = fz_render_ft_glyph(ctx, font, gid, ctm, key.aa);
+ val = fz_render_ft_glyph(ctx, font, gid, &local_ctm, key.aa);
}
else if (font->t3procs)
{
@@ -179,7 +180,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_color
* abandon ours, and use the one there already.
*/
fz_unlock(ctx, FZ_LOCK_GLYPHCACHE);
- val = fz_render_t3_glyph(ctx, font, gid, ctm, model, scissor);
+ val = fz_render_t3_glyph(ctx, font, gid, &local_ctm, model, scissor);
fz_lock(ctx, FZ_LOCK_GLYPHCACHE);
}
else
diff --git a/draw/draw_mesh.c b/draw/draw_mesh.c
index 03d187f7..343e9302 100644
--- a/draw/draw_mesh.c
+++ b/draw/draw_mesh.c
@@ -213,14 +213,14 @@ static inline void step_edge(int *ael, int *del, int n)
}
static void
-fz_paint_triangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n, fz_bbox bbox)
+fz_paint_triangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n, const fz_bbox *bbox)
{
float poly[MAXV][MAXN];
float temp[MAXV][MAXN];
- float cx0 = bbox.x0;
- float cy0 = bbox.y0;
- float cx1 = bbox.x1;
- float cy1 = bbox.y1;
+ float cx0 = bbox->x0;
+ float cy0 = bbox->y0;
+ float cx1 = bbox->x1;
+ float cy1 = bbox->y1;
int gel[MAXV][MAXN];
int ael[2][MAXN];
@@ -307,7 +307,7 @@ struct paint_tri_data
fz_context *ctx;
fz_shade *shade;
fz_pixmap *dest;
- fz_bbox bbox;
+ const fz_bbox *bbox;
};
static void
@@ -349,7 +349,7 @@ do_paint_tri(void *arg, fz_vertex *av, fz_vertex *bv, fz_vertex *cv)
}
void
-fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
+fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap *dest, const fz_bbox *bbox)
{
unsigned char clut[256][FZ_MAX_COLORS];
fz_pixmap *temp = NULL;
@@ -357,13 +357,14 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_pixmap *dest,
float color[FZ_MAX_COLORS];
struct paint_tri_data ptd;
int i, k;
+ fz_matrix local_ctm;
fz_var(temp);
fz_var(conv);
fz_try(ctx)
{
- ctm = fz_concat(shade->matrix, ctm);
+ fz_concat(&local_ctm, &shade->matrix, ctm);
if (shade->use_function)
{
@@ -390,7 +391,7 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_pixmap *dest,
ptd.shade = shade;
ptd.bbox = bbox;
- fz_process_mesh(ctx, shade, ctm, &do_paint_tri, &ptd);
+ fz_process_mesh(ctx, shade, &local_ctm, &do_paint_tri, &ptd);
if (shade->use_function)
{
diff --git a/draw/draw_paint.c b/draw/draw_paint.c
index 4c99dc7d..2862b892 100644
--- a/draw/draw_paint.c
+++ b/draw/draw_paint.c
@@ -379,11 +379,14 @@ fz_paint_pixmap_with_bbox(fz_pixmap *dst, fz_pixmap *src, int alpha, fz_bbox bbo
{
unsigned char *sp, *dp;
int x, y, w, h, n;
+ fz_bbox bbox2;
assert(dst->n == src->n);
- bbox = fz_intersect_bbox(bbox, fz_pixmap_bbox_no_ctx(dst));
- bbox = fz_intersect_bbox(bbox, fz_pixmap_bbox_no_ctx(src));
+ fz_pixmap_bbox_no_ctx(dst, &bbox2);
+ fz_intersect_bbox(&bbox, &bbox2);
+ fz_pixmap_bbox_no_ctx(src, &bbox2);
+ fz_intersect_bbox(&bbox, &bbox2);
x = bbox.x0;
y = bbox.y0;
@@ -409,12 +412,14 @@ fz_paint_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha)
{
unsigned char *sp, *dp;
fz_bbox bbox;
+ fz_bbox bbox2;
int x, y, w, h, n;
assert(dst->n == src->n);
- bbox = fz_pixmap_bbox_no_ctx(dst);
- bbox = fz_intersect_bbox(bbox, fz_pixmap_bbox_no_ctx(src));
+ fz_pixmap_bbox_no_ctx(dst, &bbox);
+ fz_pixmap_bbox_no_ctx(src, &bbox2);
+ fz_intersect_bbox(&bbox, &bbox2);
x = bbox.x0;
y = bbox.y0;
@@ -439,15 +444,17 @@ void
fz_paint_pixmap_with_mask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *msk)
{
unsigned char *sp, *dp, *mp;
- fz_bbox bbox;
+ fz_bbox bbox, bbox2;
int x, y, w, h, n;
assert(dst->n == src->n);
assert(msk->n == 1);
- bbox = fz_pixmap_bbox_no_ctx(dst);
- bbox = fz_intersect_bbox(bbox, fz_pixmap_bbox_no_ctx(src));
- bbox = fz_intersect_bbox(bbox, fz_pixmap_bbox_no_ctx(msk));
+ fz_pixmap_bbox_no_ctx(dst, &bbox);
+ fz_pixmap_bbox_no_ctx(src, &bbox2);
+ fz_intersect_bbox(&bbox, &bbox2);
+ fz_pixmap_bbox_no_ctx(msk, &bbox2);
+ fz_intersect_bbox(&bbox, &bbox2);
x = bbox.x0;
y = bbox.y0;
diff --git a/draw/draw_path.c b/draw/draw_path.c
index 9996c182..2a0c20ab 100644
--- a/draw/draw_path.c
+++ b/draw/draw_path.c
@@ -3,7 +3,7 @@
#define MAX_DEPTH 8
static void
-line(fz_gel *gel, fz_matrix *ctm, float x0, float y0, float x1, float y1)
+line(fz_gel *gel, const fz_matrix *ctm, float x0, float y0, float x1, float y1)
{
float tx0 = ctm->a * x0 + ctm->c * y0 + ctm->e;
float ty0 = ctm->b * x0 + ctm->d * y0 + ctm->f;
@@ -13,7 +13,7 @@ line(fz_gel *gel, fz_matrix *ctm, float x0, float y0, float x1, float y1)
}
static void
-bezier(fz_gel *gel, fz_matrix *ctm, float flatness,
+bezier(fz_gel *gel, const fz_matrix *ctm, float flatness,
float xa, float ya,
float xb, float yb,
float xc, float yc,
@@ -67,7 +67,7 @@ bezier(fz_gel *gel, fz_matrix *ctm, float flatness,
}
void
-fz_flatten_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness)
+fz_flatten_fill_path(fz_gel *gel, fz_path *path, const fz_matrix *ctm, float flatness)
{
float x1, y1, x2, y2, x3, y3;
float cx = 0;
@@ -83,7 +83,7 @@ fz_flatten_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness)
case FZ_MOVETO:
/* implicit closepath before moveto */
if (cx != bx || cy != by)
- line(gel, &ctm, cx, cy, bx, by);
+ line(gel, ctm, cx, cy, bx, by);
x1 = path->items[i++].v;
y1 = path->items[i++].v;
cx = bx = x1;
@@ -93,7 +93,7 @@ fz_flatten_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness)
case FZ_LINETO:
x1 = path->items[i++].v;
y1 = path->items[i++].v;
- line(gel, &ctm, cx, cy, x1, y1);
+ line(gel, ctm, cx, cy, x1, y1);
cx = x1;
cy = y1;
break;
@@ -105,13 +105,13 @@ fz_flatten_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness)
y2 = path->items[i++].v;
x3 = path->items[i++].v;
y3 = path->items[i++].v;
- bezier(gel, &ctm, flatness, cx, cy, x1, y1, x2, y2, x3, y3, 0);
+ bezier(gel, ctm, flatness, cx, cy, x1, y1, x2, y2, x3, y3, 0);
cx = x3;
cy = y3;
break;
case FZ_CLOSE_PATH:
- line(gel, &ctm, cx, cy, bx, by);
+ line(gel, ctm, cx, cy, bx, by);
cx = bx;
cy = by;
break;
@@ -119,13 +119,13 @@ fz_flatten_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness)
}
if (cx != bx || cy != by)
- line(gel, &ctm, cx, cy, bx, by);
+ line(gel, ctm, cx, cy, bx, by);
}
struct sctx
{
fz_gel *gel;
- fz_matrix *ctm;
+ const fz_matrix *ctm;
float flatness;
int linejoin;
@@ -541,14 +541,14 @@ fz_stroke_bezier(struct sctx *s,
}
void
-fz_flatten_stroke_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth)
+fz_flatten_stroke_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth)
{
struct sctx s;
fz_point p0, p1, p2, p3;
int i;
s.gel = gel;
- s.ctm = &ctm;
+ s.ctm = ctm;
s.flatness = flatness;
s.linejoin = stroke->linejoin;
@@ -747,7 +747,7 @@ fz_dash_bezier(struct sctx *s,
}
void
-fz_flatten_dash_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth)
+fz_flatten_dash_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth)
{
struct sctx s;
fz_point p0, p1, p2, p3, beg;
@@ -755,7 +755,7 @@ fz_flatten_dash_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_mat
int i;
s.gel = gel;
- s.ctm = &ctm;
+ s.ctm = ctm;
s.flatness = flatness;
s.linejoin = stroke->linejoin;
@@ -780,7 +780,7 @@ fz_flatten_dash_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_mat
phase_len = 0;
for (i = 0; i < stroke->dash_len; i++)
phase_len += stroke->dash_list[i];
- max_expand = fz_max(fz_max(fz_abs(ctm.a),fz_abs(ctm.b)),fz_max(fz_abs(ctm.c),fz_abs(ctm.d)));
+ max_expand = fz_matrix_max_expansion(ctm);
if (phase_len < 0.01f || phase_len * max_expand < 0.5f)
{
fz_flatten_stroke_path(gel, path, stroke, ctm, flatness, linewidth);
diff --git a/draw/draw_scale.c b/draw/draw_scale.c
index 93d2219a..e20cc46d 100644
--- a/draw/draw_scale.c
+++ b/draw/draw_scale.c
@@ -1244,7 +1244,7 @@ fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, floa
}
fz_pixmap *
-fz_scale_pixmap_cached(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, fz_bbox *clip, fz_scale_cache *cache_x, fz_scale_cache *cache_y)
+fz_scale_pixmap_cached(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, const fz_bbox *clip, fz_scale_cache *cache_x, fz_scale_cache *cache_y)
{
fz_scale_filter *filter = &fz_scale_filter_simple;
fz_weights *contrib_rows = NULL;
diff --git a/draw/draw_simple_scale.c b/draw/draw_simple_scale.c
index 0096d93d..d624aa57 100644
--- a/draw/draw_simple_scale.c
+++ b/draw/draw_simple_scale.c
@@ -1220,7 +1220,7 @@ fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, floa
}
fz_pixmap *
-fz_scale_pixmap_cached(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, fz_bbox *clip, fz_scale_cache *cache_x, fz_scale_cache *cache_y)
+fz_scale_pixmap_cached(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, const fz_bbox *clip, fz_scale_cache *cache_x, fz_scale_cache *cache_y)
{
fz_scale_filter *filter = &fz_scale_filter_simple;
fz_weights *contrib_rows = NULL;