diff options
author | Tor Andersson <tor@ghostscript.com> | 2010-07-01 17:19:36 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2010-07-01 17:19:36 +0200 |
commit | 43db0e886a753b6f11785b29e2e74a718216ff43 (patch) | |
tree | 8f30df199d03ec7d57fe2a83088237a9ade2d988 /fitz | |
parent | 45698f39beedeeaff4a35b84d3fdc1f9c5259b5b (diff) | |
download | mupdf-43db0e886a753b6f11785b29e2e74a718216ff43.tar.xz |
Compute shading bounding box using the triangle mesh.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/dev_draw.c | 30 | ||||
-rw-r--r-- | fitz/res_shade.c | 33 |
2 files changed, 50 insertions, 13 deletions
diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c index 6050c09f..0906985f 100644 --- a/fitz/dev_draw.c +++ b/fitz/dev_draw.c @@ -452,12 +452,16 @@ fz_drawfillshade(void *user, fz_shade *shade, fz_matrix ctm) fz_bbox bbox; float colorfv[FZ_MAXCOLORS]; unsigned char colorbv[FZ_MAXCOLORS + 1]; - unsigned char *s; - int x, y; - bounds = fz_transformrect(fz_concat(shade->matrix, ctm), shade->bbox); - bbox = fz_roundrect(bounds); - bbox = fz_intersectbbox(bbox, dev->scissor); + bounds = fz_boundshade(shade, ctm); + bbox = fz_intersectbbox(fz_roundrect(bounds), dev->scissor); + + // TODO: proper clip by shade->bbox + if (!fz_isemptyrect(shade->bbox)) + { +// bounds = fz_transformrect(fz_concat(shade->matrix, ctm), shade->bbox); +// bbox = fz_intersectbbox(fz_roundrect(bounds), bbox); + } if (fz_isemptyrect(bbox)) return; @@ -470,19 +474,21 @@ fz_drawfillshade(void *user, fz_shade *shade, fz_matrix ctm) if (shade->usebackground) { - /* FIXME: Could use optimisation */ - int i, n = dev->model->n + 1; - + unsigned char *s; + int x, y, n, i; +printf("usebackground!\n"); fz_convertcolor(shade->cs, shade->background, dev->model, colorfv); - colorbv[0] = 255; - for (i = 1; i < n; i++) - colorbv[n-i] = colorfv[i-1] * 255; + for (i = 0; i < dev->model->n; i++) + colorbv[i] = colorfv[i] * 255; + colorbv[i] = 255; + + n = dest->n; for (y = bbox.y0; y < bbox.y1; y++) { s = dest->samples + ((bbox.x0 - dest->x) + (y - dest->y) * dest->w) * dest->n; for (x = bbox.x0; x < bbox.x1; x++) { - for (i = n; i > 0; i--) + for (i = 0; i < n; i++) *s++ = colorbv[i]; } } diff --git a/fitz/res_shade.c b/fitz/res_shade.c index 2ddd6275..5fc23372 100644 --- a/fitz/res_shade.c +++ b/fitz/res_shade.c @@ -22,8 +22,39 @@ fz_dropshade(fz_shade *shade) fz_rect fz_boundshade(fz_shade *shade, fz_matrix ctm) { + float *v; + fz_rect r; + fz_point p; + int i, ncomp, nvert; + ctm = fz_concat(shade->matrix, ctm); - return fz_transformrect(ctm, shade->bbox); + ncomp = shade->usefunction ? 3 : 2 + shade->cs->n; + nvert = shade->meshlen / ncomp; + v = shade->mesh; + + if (nvert == 0) + return fz_emptyrect; + + p.x = v[0]; + p.y = v[1]; + v += ncomp; + p = fz_transformpoint(ctm, p); + r.x0 = r.x1 = p.x; + r.y0 = r.y1 = p.y; + + for (i = 1; i < nvert; i++) + { + p.x = v[0]; + p.y = v[1]; + p = fz_transformpoint(ctm, p); + v += ncomp; + if (p.x < r.x0) r.x0 = p.x; + if (p.y < r.y0) r.y0 = p.y; + if (p.x > r.x1) r.x1 = p.x; + if (p.y > r.y1) r.y1 = p.y; + } + + return r; } void |