summaryrefslogtreecommitdiff
path: root/draw
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-06-15 23:14:05 +0200
committerTor Andersson <tor@ghostscript.com>2010-06-15 23:14:05 +0200
commit0604c0103d3a1a5a75ab7bd3060ff34bd8973592 (patch)
treed0a9b71b031de933959ea0651974b1698c9faff4 /draw
parent5795eaee9455031dead3dff50d1ab2d06c5f9915 (diff)
downloadmupdf-0604c0103d3a1a5a75ab7bd3060ff34bd8973592.tar.xz
Use scissor bbox to clip shadings instead of using scratch buffers.
Diffstat (limited to 'draw')
-rw-r--r--draw/meshdraw.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/draw/meshdraw.c b/draw/meshdraw.c
index 002f58ad..8e876397 100644
--- a/draw/meshdraw.c
+++ b/draw/meshdraw.c
@@ -217,14 +217,14 @@ stepedge(int *ael, int *del, int n)
}
static void
-fz_drawtriangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n)
+fz_drawtriangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n, fz_bbox bbox)
{
float poly[MAXV][MAXN];
float temp[MAXV][MAXN];
- float cx0 = pix->x;
- float cy0 = pix->y;
- float cx1 = pix->x + pix->w;
- float cy1 = pix->y + pix->h;
+ float cx0 = bbox.x0;
+ float cy0 = bbox.y0;
+ float cx1 = bbox.x1;
+ float cy1 = bbox.y1;
int gel[MAXV][MAXN];
int ael[2][MAXN];
@@ -311,15 +311,17 @@ fz_drawtriangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n)
*/
void
-fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest)
+fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
{
unsigned char clut[256][FZ_MAXCOLORS];
unsigned char *s, *d;
+ unsigned char sa, ssa;
fz_pixmap *temp;
float color[FZ_MAXCOLORS];
float tri[3][MAXN];
fz_point p;
int i, j, k, n;
+ int x, y;
assert(dest->n == 4);
@@ -328,7 +330,8 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest)
if (shade->usefunction)
{
n = 3;
- temp = fz_newpixmap(pdf_devicegray, dest->x, dest->y, dest->w, dest->h);
+ temp = fz_newpixmapwithrect(pdf_devicegray, bbox);
+ fz_clearpixmap(temp, 0);
}
else
{
@@ -336,8 +339,6 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest)
temp = dest;
}
- fz_clearpixmap(temp, 0);
-
for (i = 0; i < shade->meshlen; i++)
{
for (k = 0; k < 3; k++)
@@ -357,7 +358,7 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest)
tri[k][j + 2] *= 255;
}
}
- fz_drawtriangle(temp, tri[0], tri[1], tri[2], 2 + temp->colorspace->n);
+ fz_drawtriangle(temp, tri[0], tri[1], tri[2], 2 + temp->colorspace->n, bbox);
}
if (shade->usefunction)
@@ -369,17 +370,20 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest)
clut[i][k] = color[k] * 255;
}
- n = temp->w * temp->h;
- s = temp->samples;
- d = dest->samples;
-
- while (n--)
+ for (y = bbox.y0; y < bbox.y1; y++)
{
- d[0] = s[0];
- for (k = 0; k < dest->colorspace->n; k++)
- d[k + 1] = fz_mul255(s[0], clut[s[1]][k]);
- s += 2;
- d += 1 + dest->colorspace->n;
+ s = temp->samples + ((bbox.x0 - temp->x) + (y - temp->y) * temp->w) * temp->n;
+ d = dest->samples + ((bbox.x0 - dest->x) + (y - dest->y) * dest->w) * dest->n;
+ for (x = bbox.x0; x < bbox.x1; x++)
+ {
+ sa = s[0];
+ ssa = 255 - sa;
+ d[0] = s[0] + fz_mul255(d[0], ssa);
+ for (k = 0; k < dest->colorspace->n; k++)
+ d[k+1] = fz_mul255(clut[s[1]][k], sa) + fz_mul255(d[k+1], ssa);
+ s += 2;
+ d += 1 + dest->colorspace->n;
+ }
}
fz_droppixmap(temp);