summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-08-04 13:43:58 +0000
committerTor Andersson <tor@ghostscript.com>2010-08-04 13:43:58 +0000
commit2c036aab4670a93490d42de3492983feb389231d (patch)
tree1248816b579df9101cae086c88a568aeac5224f5 /fitz
parent724d113ed8840470ded2b32a52c9b53a4e0a5c6b (diff)
downloadmupdf-2c036aab4670a93490d42de3492983feb389231d.tar.xz
Rearrange low level painting functions and add new functions for constant alpha painting.
Diffstat (limited to 'fitz')
-rw-r--r--fitz/dev_draw.c138
-rw-r--r--fitz/fitz.h66
-rw-r--r--fitz/res_font.c8
3 files changed, 100 insertions, 112 deletions
diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c
index 964ab4f6..4f7e41a0 100644
--- a/fitz/dev_draw.c
+++ b/fitz/dev_draw.c
@@ -53,18 +53,12 @@ fz_drawfillpath(void *user, fz_path *path, int evenodd, fz_matrix ctm,
if (fz_isemptyrect(bbox))
return;
- if (model)
- {
- fz_convertcolor(colorspace, color, model, colorfv);
- for (i = 0; i < model->n; i++)
- colorbv[i] = colorfv[i] * 255;
- colorbv[i] = alpha * 255;
- fz_scanconvert(dev->gel, dev->ael, evenodd, bbox, dev->dest, colorbv);
- }
- else
- {
- fz_scanconvert(dev->gel, dev->ael, evenodd, bbox, dev->dest, nil);
- }
+ fz_convertcolor(colorspace, color, model, colorfv);
+ for (i = 0; i < model->n; i++)
+ colorbv[i] = colorfv[i] * 255;
+ colorbv[i] = alpha * 255;
+
+ fz_scanconvert(dev->gel, dev->ael, evenodd, bbox, dev->dest, colorbv);
}
static void
@@ -97,18 +91,12 @@ fz_drawstrokepath(void *user, fz_path *path, fz_strokestate *stroke, fz_matrix c
if (fz_isemptyrect(bbox))
return;
- if (model)
- {
- fz_convertcolor(colorspace, color, model, colorfv);
- for (i = 0; i < model->n; i++)
- colorbv[i] = colorfv[i] * 255;
- colorbv[i] = alpha * 255;
- fz_scanconvert(dev->gel, dev->ael, 0, bbox, dev->dest, colorbv);
- }
- else
- {
- fz_scanconvert(dev->gel, dev->ael, 0, bbox, dev->dest, nil);
- }
+ fz_convertcolor(colorspace, color, model, colorfv);
+ for (i = 0; i < model->n; i++)
+ colorbv[i] = colorfv[i] * 255;
+ colorbv[i] = alpha * 255;
+
+ fz_scanconvert(dev->gel, dev->ael, 0, bbox, dev->dest, colorbv);
}
static void
@@ -235,9 +223,9 @@ drawglyph(unsigned char *colorbv, fz_pixmap *dst, fz_pixmap *msk,
while (h--)
{
if (dst->colorspace)
- fz_blendwithcolormask(dp, colorbv, mp, dst->n, w);
+ fz_paintspancolor(dp, mp, dst->n, w, colorbv);
else
- fz_blendmasks(dp, mp, w);
+ fz_paintspan(dp, mp, 1, w, 255);
dp += dst->w * dst->n;
mp += msk->w;
}
@@ -255,13 +243,10 @@ fz_drawfilltext(void *user, fz_text *text, fz_matrix ctm,
fz_pixmap *glyph;
int i, x, y, gid;
- if (model)
- {
- fz_convertcolor(colorspace, color, model, colorfv);
- for (i = 0; i < model->n; i++)
- colorbv[i] = colorfv[i] * 255;
- colorbv[i] = alpha * 255;
- }
+ fz_convertcolor(colorspace, color, model, colorfv);
+ for (i = 0; i < model->n; i++)
+ colorbv[i] = colorfv[i] * 255;
+ colorbv[i] = alpha * 255;
tm = text->trm;
@@ -282,10 +267,7 @@ fz_drawfilltext(void *user, fz_text *text, fz_matrix ctm,
glyph = fz_renderglyph(dev->cache, text->font, gid, trm);
if (glyph)
{
- if (model)
- drawglyph(colorbv, dev->dest, glyph, x, y, dev->scissor);
- else
- drawglyph(nil, dev->dest, glyph, x, y, dev->scissor);
+ drawglyph(colorbv, dev->dest, glyph, x, y, dev->scissor);
fz_droppixmap(glyph);
}
}
@@ -303,13 +285,10 @@ fz_drawstroketext(void *user, fz_text *text, fz_strokestate *stroke, fz_matrix c
fz_pixmap *glyph;
int i, x, y, gid;
- if (model)
- {
- fz_convertcolor(colorspace, color, model, colorfv);
- for (i = 0; i < model->n; i++)
- colorbv[i] = colorfv[i] * 255;
- colorbv[i] = alpha * 255;
- }
+ fz_convertcolor(colorspace, color, model, colorfv);
+ for (i = 0; i < model->n; i++)
+ colorbv[i] = colorfv[i] * 255;
+ colorbv[i] = alpha * 255;
tm = text->trm;
@@ -330,10 +309,7 @@ fz_drawstroketext(void *user, fz_text *text, fz_strokestate *stroke, fz_matrix c
glyph = fz_renderstrokedglyph(dev->cache, text->font, gid, trm, ctm, stroke);
if (glyph)
{
- if (model)
- drawglyph(colorbv, dev->dest, glyph, x, y, dev->scissor);
- else
- drawglyph(nil, dev->dest, glyph, x, y, dev->scissor);
+ drawglyph(colorbv, dev->dest, glyph, x, y, dev->scissor);
fz_droppixmap(glyph);
}
}
@@ -413,7 +389,7 @@ fz_drawcliptext(void *user, fz_text *text, fz_matrix ctm, int accumulate)
glyph = fz_renderglyph(dev->cache, text->font, gid, trm);
if (glyph)
{
- drawglyph(NULL, mask, glyph, x, y, bbox);
+ drawglyph(nil, mask, glyph, x, y, bbox);
fz_droppixmap(glyph);
}
}
@@ -475,7 +451,7 @@ fz_drawclipstroketext(void *user, fz_text *text, fz_strokestate *stroke, fz_matr
glyph = fz_renderstrokedglyph(dev->cache, text->font, gid, trm, ctm, stroke);
if (glyph)
{
- drawglyph(NULL, mask, glyph, x, y, bbox);
+ drawglyph(nil, mask, glyph, x, y, bbox);
fz_droppixmap(glyph);
}
}
@@ -548,7 +524,7 @@ fz_drawfillshade(void *user, fz_shade *shade, fz_matrix ctm, float alpha)
if (alpha < 1)
{
- fz_blendpixmapswithalpha(dev->dest, dest, alpha);
+ fz_paintpixmap(dev->dest, dest, alpha * 255);
fz_droppixmap(dest);
}
}
@@ -604,21 +580,7 @@ fz_drawfillimage(void *user, fz_pixmap *image, fz_matrix ctm, float alpha)
}
#endif
- if (alpha < 1)
- {
- fz_pixmap *temp;
- fz_bbox bbox;
- bbox = fz_roundrect(fz_transformrect(ctm, fz_unitrect));
- bbox = fz_intersectbbox(bbox, dev->scissor);
- temp = fz_newpixmapwithrect(dev->dest->colorspace, bbox);
- fz_blendimage(temp, bbox, image, ctm);
- fz_blendpixmapswithalpha(dev->dest, temp, alpha);
- fz_droppixmap(temp);
- }
- else
- {
- fz_blendimage(dev->dest, dev->scissor, image, ctm);
- }
+ fz_paintimage(dev->dest, dev->scissor, image, ctm, alpha * 255);
if (scaled)
fz_droppixmap(scaled);
@@ -657,18 +619,12 @@ fz_drawfillimagemask(void *user, fz_pixmap *image, fz_matrix ctm,
}
#endif
- if (dev->dest->colorspace)
- {
- fz_convertcolor(colorspace, color, model, colorfv);
- for (i = 0; i < model->n; i++)
- colorbv[i] = colorfv[i] * 255;
- colorbv[i] = alpha * 255;
- fz_blendimagewithcolor(dev->dest, dev->scissor, image, ctm, colorbv);
- }
- else
- {
- fz_blendimage(dev->dest, dev->scissor, image, ctm);
- }
+ fz_convertcolor(colorspace, color, model, colorfv);
+ for (i = 0; i < model->n; i++)
+ colorbv[i] = colorfv[i] * 255;
+ colorbv[i] = alpha * 255;
+
+ fz_paintimagecolor(dev->dest, dev->scissor, image, ctm, colorbv);
if (scaled)
fz_droppixmap(scaled);
@@ -725,7 +681,7 @@ fz_drawclipimagemask(void *user, fz_pixmap *image, fz_matrix ctm)
}
#endif
- fz_blendimage(mask, bbox, image, ctm);
+ fz_paintimage(mask, bbox, image, ctm, 255);
if (scaled)
fz_droppixmap(scaled);
@@ -752,7 +708,7 @@ fz_drawpopclip(void *user)
if (mask && dest)
{
fz_pixmap *scratch = dev->dest;
- fz_blendpixmapswithmask(dest, scratch, mask);
+ fz_paintpixmapmask(dest, scratch, mask);
fz_droppixmap(mask);
fz_droppixmap(scratch);
dev->dest = dest;
@@ -884,27 +840,9 @@ fz_drawendgroup(void *user)
dev->scissor = dev->stack[dev->top].scissor;
if (blendmode == FZ_BNORMAL)
- {
- if (alpha < 1)
- fz_blendpixmapswithalpha(dev->dest, group, alpha);
- else
- fz_blendpixmaps(dev->dest, group);
- }
+ fz_paintpixmap(dev->dest, group, alpha * 255);
else
- {
- if (alpha < 1)
- {
- unsigned char *p = group->samples;
- int n = group->w * group->h * group->n;
- int a = alpha * 255;
- while (n--)
- {
- *p = fz_mul255(*p, a);
- p++;
- }
- }
- fz_blendpixmapswithmode(dev->dest, group, blendmode);
- }
+ fz_blendpixmap(dev->dest, group, alpha * 255, blendmode);
fz_droppixmap(group);
}
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 44f1c070..8cd351ae 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -1030,6 +1030,50 @@ void fz_executedisplaylist(fz_displaylist *list, fz_device *dev, fz_matrix ctm);
* They can be replaced by cpu-optimized versions.
*/
+/*
+These are the blending primitives:
+
+span over span (text and path drawing to clip mask)
+span in alpha over span
+span in span over span
+color in span over span (text and path drawing)
+
+ fz_paintspan(dp, sp);
+ fz_paintspanalpha(dp, sp, alpha)
+ fz_paintspanmask(dp, sp, mask);
+ fz_paintspancolor(dp, color, mask);
+
+pixmap over pixmap (shading with function lookup)
+pixmap in alpha over pixmap (xobject/shading with ca)
+pixmap in pixmap over pixmap (xobject with softmask / clip)
+
+ fz_paintpixmap()
+ fz_paintpixmapalpha()
+ fz_paintpixmapmask()
+
+affine over span
+affine in alpha over span
+color in affine over span
+
+ fz_paintaffine()
+ fz_paintaffinealpha()
+ fz_paintaffinecolor()
+
+image over pixmap (image fill)
+image in alpha over pixmap (image fill with ca)
+color in image over pixmap (image mask fill)
+
+ fz_paintimage()
+ fz_paintimagealpha()
+ fz_paintimagecolor()
+
+pixmap BLEND pixmap
+pixmap in alpha BLEND pixmap
+
+ fz_blendpixmap()
+ fz_blendpixmapalpha()
+*/
+
void fz_accelerate(void);
void fz_acceleratearch(void);
@@ -1037,18 +1081,20 @@ void fz_decodetile(fz_pixmap *pix, float *decode);
void fz_decodeindexedtile(fz_pixmap *pix, float *decode, int maxval);
void fz_unpacktile(fz_pixmap *dst, unsigned char * restrict src, int n, int depth, int stride, int scale);
-void fz_blendpixmapswithmode(fz_pixmap *dst, fz_pixmap *src, fz_blendmode blendmode);
-void fz_blendpixmapswithmask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *msk);
-void fz_blendpixmapswithalpha(fz_pixmap *dst, fz_pixmap *src, float alpha);
-void fz_blendpixmaps(fz_pixmap *dst, fz_pixmap *src);
+void fz_paintspan(unsigned char * restrict dp, unsigned char * restrict sp, int n, int w, int alpha);
+void fz_paintspancolor(unsigned char * restrict dp, unsigned char * restrict mp, int n, int w, unsigned char *color);
+void fz_paintspanmask(unsigned char * restrict dp, unsigned char * restrict sp, unsigned char * restrict mp, int n, int w);
+
+void fz_paintaffine(unsigned char *dp, unsigned char *sp, int sw, int sh, int u, int v, int fa, int fb, int w, int n, int alpha);
+void fz_paintaffinecolor(unsigned char *dp, unsigned char *sp, int sw, int sh, int u, int v, int fa, int fb, int w, int n, unsigned char *color);
+
+void fz_paintimage(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *img, fz_matrix ctm, int alpha);
+void fz_paintimagecolor(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *img, fz_matrix ctm, unsigned char *colorbv);
-void fz_blendmasks(unsigned char * restrict dp, unsigned char * restrict sp, int w);
-void fz_blendwithcolormask(unsigned char * restrict dp, unsigned char * restrict sp, unsigned char * restrict mp, int n, int w);
-void fz_blendnormal(unsigned char * restrict dp, unsigned char * restrict sp, int n, int w);
-void fz_blendwithmask(unsigned char * restrict dp, unsigned char * restrict sp, unsigned char * restrict mp, int n, int w);
+void fz_paintpixmap(fz_pixmap *dst, fz_pixmap *src, int alpha);
+void fz_paintpixmapmask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *msk);
-void fz_blendimage(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *img, fz_matrix ctm);
-void fz_blendimagewithcolor(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *img, fz_matrix ctm, unsigned char *colorbv);
+void fz_blendpixmap(fz_pixmap *dst, fz_pixmap *src, int alpha, fz_blendmode blendmode);
extern void (*fz_srown)(unsigned char *restrict, unsigned char *restrict, int w, int denom, int n);
extern void (*fz_srow1)(unsigned char *restrict, unsigned char *restrict, int w, int denom);
diff --git a/fitz/res_font.c b/fitz/res_font.c
index 68b761b2..fd3bbe3f 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -458,6 +458,7 @@ fz_rendert3glyph(fz_font *font, int gid, fz_matrix trm)
fz_device *dev;
fz_glyphcache *cache;
fz_pixmap *glyph;
+ fz_pixmap *result;
if (gid < 0 || gid > 255)
return NULL;
@@ -473,7 +474,7 @@ fz_rendert3glyph(fz_font *font, int gid, fz_matrix trm)
fz_catch(error, "cannot draw type3 glyph");
fz_freedevice(dev);
- glyph = fz_newpixmap(nil, bbox.x0-1, bbox.y0-1, bbox.x1 - bbox.x0 + 1, bbox.y1 - bbox.y0 + 1);
+ glyph = fz_newpixmap(fz_devicegray, bbox.x0-1, bbox.y0-1, bbox.x1 - bbox.x0 + 1, bbox.y1 - bbox.y0 + 1);
fz_clearpixmap(glyph, 0);
cache = fz_newglyphcache();
@@ -484,7 +485,10 @@ fz_rendert3glyph(fz_font *font, int gid, fz_matrix trm)
fz_freedevice(dev);
fz_freeglyphcache(cache);
- return glyph;
+ result = fz_alphafromgray(glyph, 0);
+ fz_droppixmap(glyph);
+
+ return result;
}
void