diff options
-rw-r--r-- | draw/archport.c | 2 | ||||
-rw-r--r-- | draw/porterduff.c | 120 | ||||
-rw-r--r-- | fitz/dev_draw.c | 66 | ||||
-rw-r--r-- | fitz/fitz.h | 6 |
4 files changed, 82 insertions, 112 deletions
diff --git a/draw/archport.c b/draw/archport.c index 3ed56973..16e80c99 100644 --- a/draw/archport.c +++ b/draw/archport.c @@ -470,7 +470,7 @@ void fz_accelerate(void) if (sizeof(int) == 4 && sizeof(unsigned int) == 4 && !fz_isbigendian()) { fz_path_w4i1o4 = path_w4i1o4_32bit; - fz_text_w4i1o4 = text_w4i1o4_32bit; +// fz_text_w4i1o4 = text_w4i1o4_32bit; fz_img_4o4 = img_4o4_32bit; fz_img_w4i1o4 = img_w4i1o4_32bit; fz_img_1o1 = img_1o1_32bit; diff --git a/draw/porterduff.c b/draw/porterduff.c index 99e00e05..3596616d 100644 --- a/draw/porterduff.c +++ b/draw/porterduff.c @@ -130,89 +130,71 @@ void (*fz_path_1o1)(byte*restrict,byte,int,byte*restrict) = path_1o1; void (*fz_path_w2i1o2)(byte*,byte*restrict,byte,int,byte*restrict) = path_w2i1o2; void (*fz_path_w4i1o4)(byte*,byte*restrict,byte,int,byte*restrict) = path_w4i1o4; -/* - * Text drawing (the source colors are not premultiplied) - */ +/* Blend source alpha over destination alpha */ -static void -text_1o1(byte * restrict src, int srcw, byte * restrict dst, int dstw, int w0, int h) +void +fz_blendmasks(byte * restrict dp, byte * restrict sp, int w) { - - srcw -= w0; - dstw -= w0; - while (h--) + while (w--) { - int w = w0; - while (w--) - { - dst[0] = src[0] + fz_mul255(dst[0], 255 - src[0]); - src++; - dst++; - } - src += srcw; - dst += dstw; + dp[0] = sp[0] + fz_mul255(dp[0], 255 - sp[0]); + sp++; + dp++; } } -static void -text_w2i1o2(byte *ga, byte * restrict src, int srcw, byte * restrict dst, int dstw, int w0, int h) +/* Blend a non-premultiplied color in mask over destination */ + +void +fz_blendwithcolormask(byte * restrict dp, byte * restrict sp, byte * restrict mp, int n, int w) { - byte g = ga[0]; - int a = FZ_EXPAND(ga[1]); + int sa, r, g, b, k; - srcw -= w0; - dstw -= w0<<1; - while (h--) + switch (n) { - int w = w0; + case 2: + sa = FZ_EXPAND(sp[1]); + g = sp[0]; while (w--) { - int c = FZ_COMBINE(FZ_EXPAND(src[0]), a); - dst[0] = FZ_BLEND(g, dst[0], c); - dst[1] = FZ_BLEND(255, dst[1], c); - src ++; - dst += 2; + int ma = *mp++; + int masa = FZ_COMBINE(FZ_EXPAND(ma), sa); + dp[0] = FZ_BLEND(g, dp[0], masa); + dp[1] = FZ_BLEND(255, dp[1], masa); + dp += 2; } - src += srcw; - dst += dstw; - } -} - -static void -text_w4i1o4(byte *rgba, byte * restrict src, int srcw, byte * restrict dst, int dstw, int w0, int h) -{ - byte r = rgba[0]; - byte g = rgba[1]; - byte b = rgba[2]; - int a = FZ_EXPAND(rgba[3]); - - srcw -= w0; - dstw -= w0<<2; - while (h--) - { - int w = w0; + break; + case 4: + sa = FZ_EXPAND(sp[3]); + r = sp[0]; + g = sp[1]; + b = sp[2]; while (w--) { - int c = FZ_COMBINE(FZ_EXPAND(src[0]), a); - dst[0] = FZ_BLEND(r, dst[0], c); - dst[1] = FZ_BLEND(g, dst[1], c); - dst[2] = FZ_BLEND(b, dst[2], c); - dst[3] = FZ_BLEND(255, dst[3], c); - src ++; - dst += 4; + int ma = *mp++; + int masa = FZ_COMBINE(FZ_EXPAND(ma), sa); + dp[0] = FZ_BLEND(r, dp[0], masa); + dp[1] = FZ_BLEND(g, dp[1], masa); + dp[2] = FZ_BLEND(b, dp[2], masa); + dp[3] = FZ_BLEND(255, dp[3], masa); + dp += 4; + } + break; + default: + sa = FZ_EXPAND(sp[n-1]); + while (w--) + { + int ma = *mp++; + int masa = FZ_COMBINE(FZ_EXPAND(ma), sa); + for (k = 0; k < n - 1; k++) + dp[k] = FZ_BLEND(sp[k], dp[k], masa); + dp[k] = FZ_BLEND(255, dp[k], masa); + dp += n; } - src += srcw; - dst += dstw; } } -void (*fz_text_1o1)(byte*restrict,int,byte*restrict,int,int,int) = text_1o1; -void (*fz_text_w2i1o2)(byte*,byte*restrict,int,byte*restrict,int,int,int) = text_w2i1o2; -void (*fz_text_w4i1o4)(byte*,byte*restrict,int,byte*restrict,int,int,int) = text_w4i1o4; - -/* - * Pixmap blending - */ +/* Blend source in mask over destination */ void fz_blendwithmask(byte * restrict dp, byte * restrict sp, byte * restrict mp, int n, int w) @@ -260,6 +242,8 @@ fz_blendwithmask(byte * restrict dp, byte * restrict sp, byte * restrict mp, int } } +/* Blend source in (constant) alpha over destination */ + void fz_blendwithalpha(byte * restrict dp, byte * restrict sp, int ma, int n, int w) { @@ -276,6 +260,8 @@ fz_blendwithalpha(byte * restrict dp, byte * restrict sp, int ma, int n, int w) } } +/* Blend source over destination */ + void fz_blendnormal(byte * restrict dp, byte * restrict sp, int n, int w) { @@ -291,6 +277,10 @@ fz_blendnormal(byte * restrict dp, byte * restrict sp, int n, int w) } } +/* + * Pixmap blending functions + */ + void fz_blendpixmapswithmask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *msk) { diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c index 9f2b088b..36423051 100644 --- a/fitz/dev_draw.c +++ b/fitz/dev_draw.c @@ -206,57 +206,39 @@ fz_drawclipstrokepath(void *user, fz_path *path, fz_strokestate *stroke, fz_matr } static void -drawglyph(unsigned char *colorbv, fz_pixmap *dst, fz_pixmap *src, +drawglyph(unsigned char *colorbv, fz_pixmap *dst, fz_pixmap *msk, int xorig, int yorig, fz_bbox scissor) { - unsigned char *dp, *sp; - int w, h; - - int dx0 = scissor.x0; - int dy0 = scissor.y0; - int dx1 = scissor.x1; - int dy1 = scissor.y1; - - int x0 = xorig + src->x; - int y0 = yorig + src->y; - int x1 = x0 + src->w; - int y1 = y0 + src->h; + unsigned char *dp, *mp; + fz_bbox bbox; + int x, y, w, h; - int sx0 = 0; - int sy0 = 0; - int sx1 = src->w; - int sy1 = src->h; + bbox = fz_boundpixmap(msk); + bbox.x0 += xorig; + bbox.y0 += yorig; + bbox.x1 += xorig; + bbox.y1 += yorig; - if (x1 <= dx0 || x0 >= dx1) return; - if (y1 <= dy0 || y0 >= dy1) return; - if (x0 < dx0) { sx0 += dx0 - x0; x0 = dx0; } - if (y0 < dy0) { sy0 += dy0 - y0; y0 = dy0; } - if (x1 > dx1) { sx1 += dx1 - x1; } - if (y1 > dy1) { sy1 += dy1 - y1; } + bbox = fz_intersectbbox(bbox, scissor); /* scissor < dst */ + x = bbox.x0; + y = bbox.y0; + w = bbox.x1 - bbox.x0; + h = bbox.y1 - bbox.y0; - sp = src->samples + (sy0 * src->w + sx0); - dp = dst->samples + ((y0 - dst->y) * dst->w + (x0 - dst->x)) * dst->n; + mp = msk->samples + ((y - msk->y - yorig) * msk->w + (x - msk->x - xorig)); + dp = dst->samples + ((y - dst->y) * dst->w + (x - dst->x)) * dst->n; - w = sx1 - sx0; - h = sy1 - sy0; + assert(msk->n == 1); - if (dst->colorspace) + while (h--) { - switch (dst->n) - { - case 2: - fz_text_w2i1o2(colorbv, sp, src->w, dp, dst->w * 2, w, h); - break; - case 4: - fz_text_w4i1o4(colorbv, sp, src->w, dp, dst->w * 4, w, h); - break; - default: - assert("Write fz_text_wni1on" != NULL); - break; - } + if (dst->colorspace) + fz_blendwithcolormask(dp, colorbv, mp, dst->n, w); + else + fz_blendmasks(dp, mp, w); + dp += dst->w * dst->n; + mp += msk->w; } - else - fz_text_1o1(sp, src->w, dp, dst->w, w, h); } static void diff --git a/fitz/fitz.h b/fitz/fitz.h index c21b2f74..1465e8b9 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -1142,6 +1142,8 @@ 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_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); @@ -1149,10 +1151,6 @@ extern void (*fz_path_1o1)(unsigned char*restrict,unsigned char,int,unsigned cha extern void (*fz_path_w2i1o2)(unsigned char*,unsigned char*restrict,unsigned char,int,unsigned char*restrict); extern void (*fz_path_w4i1o4)(unsigned char*,unsigned char*restrict,unsigned char,int,unsigned char*restrict); -extern void (*fz_text_1o1)(unsigned char*restrict,int,unsigned char*restrict,int,int,int); -extern void (*fz_text_w2i1o2)(unsigned char*,unsigned char*restrict,int,unsigned char*restrict,int,int,int); -extern void (*fz_text_w4i1o4)(unsigned char*,unsigned char*restrict,int,unsigned char*restrict,int,int,int); - extern void (*fz_img_non)(unsigned char*restrict,unsigned char,int,unsigned char*restrict,fz_pixmap*,fz_matrix*); extern void (*fz_img_1o1)(unsigned char*restrict,unsigned char,int,unsigned char*restrict,fz_pixmap*,int u, int v, int fa, int fb); extern void (*fz_img_4o4)(unsigned char*restrict,unsigned char,int,unsigned char*restrict,fz_pixmap*,int u, int v, int fa, int fb); |