summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Kennard <glenn.kennard@gmail.com>2008-03-21 01:49:00 +0100
committerGlenn Kennard <glenn.kennard@gmail.com>2008-03-21 01:49:00 +0100
commit783f538d4ee8e87bfd911345c903052b29b92338 (patch)
tree3bb43754e7051d9529311facbb15b559b1d6c76e
parent81cf682d56185937d83dba5d787b0c72d10f0446 (diff)
downloadmupdf-783f538d4ee8e87bfd911345c903052b29b92338.tar.xz
Propagate alpha into rendering routines
I think these need premul, but not certain yet.
-rw-r--r--include/fitz/draw_misc.h3
-rw-r--r--raster/archx86.c4
-rw-r--r--raster/imagedraw.c10
-rw-r--r--raster/porterduff.c28
-rw-r--r--raster/render.c46
5 files changed, 51 insertions, 40 deletions
diff --git a/include/fitz/draw_misc.h b/include/fitz/draw_misc.h
index cd9035a1..8cf01d49 100644
--- a/include/fitz/draw_misc.h
+++ b/include/fitz/draw_misc.h
@@ -69,8 +69,7 @@ struct fz_renderer_s
fz_irect clip;
fz_pixmap *dest;
fz_pixmap *over;
- unsigned char a;
- unsigned char rgb[3];
+ unsigned char argb[4];
int flag;
};
diff --git a/raster/archx86.c b/raster/archx86.c
index 089edf02..f797d44b 100644
--- a/raster/archx86.c
+++ b/raster/archx86.c
@@ -115,8 +115,8 @@ static void img_4o4mmx(FZ_PSRC, FZ_PDST, FZ_PCTM)
int fv = v & 0x7fff;
int atedge =
- iu < 0 | iu >= (srcw - 1) |
- iv < 0 | iv >= (srch - 1);
+ (iu < 0) | (iu >= (srcw - 1)) |
+ (iv < 0) | (iv >= (srch - 1));
__m64 ms0s1;
__m64 ms2s3;
diff --git a/raster/imagedraw.c b/raster/imagedraw.c
index 0f51c01b..d7eb5dc7 100644
--- a/raster/imagedraw.c
+++ b/raster/imagedraw.c
@@ -201,11 +201,12 @@ static void img_4o4(FZ_PSRC, FZ_PDST, FZ_PCTM)
}
}
-static void img_w3i1o4(byte *rgb, FZ_PSRC, FZ_PDST, FZ_PCTM)
+static void img_w3i1o4(byte *argb, FZ_PSRC, FZ_PDST, FZ_PCTM)
{
- byte rgb0 = rgb[0];
- byte rgb1 = rgb[1];
- byte rgb2 = rgb[2];
+ byte ca = argb[0];
+ byte rgb0 = argb[1];
+ byte rgb1 = argb[2];
+ byte rgb2 = argb[3];
byte sa, ssa;
while (h--)
{
@@ -216,6 +217,7 @@ static void img_w3i1o4(byte *rgb, FZ_PSRC, FZ_PDST, FZ_PCTM)
while (w--)
{
sa = samplemask(src, srcw, srch, u, v);
+ sa = fz_mul255(sa, ca);
ssa = 255 - sa;
dstp[0] = sa + fz_mul255(dstp[0], ssa);
dstp[1] = rgb0 + fz_mul255((short)dstp[1] - rgb0, ssa);
diff --git a/raster/porterduff.c b/raster/porterduff.c
index 74b34ac2..fdc42951 100644
--- a/raster/porterduff.c
+++ b/raster/porterduff.c
@@ -257,16 +257,19 @@ static void path_1o1(byte * restrict src, int cov, int len, byte * restrict dst)
}
}
-static void path_w3i1o4(byte * restrict rgb, byte * restrict src, int cov, int len, byte * restrict dst)
+static void path_w3i1o4(byte * restrict argb, byte * restrict src, int cov, int len, byte * restrict dst)
{
- byte rgb0 = rgb[0];
- byte rgb1 = rgb[1];
- byte rgb2 = rgb[2];
+ byte ca = argb[0];
+ byte rgb0 = argb[1];
+ byte rgb1 = argb[2];
+ byte rgb2 = argb[3];
byte ssa;
while (len--)
{
+ byte a;
cov += *src; *src = 0; src++;
- ssa = 255 - cov;
+ a = fz_mul255(cov, ca);
+ ssa = 255 - a;
dst[0] = cov + fz_mul255(dst[0], ssa);
dst[1] = rgb0 + fz_mul255((short)dst[1] - rgb0, ssa);
dst[2] = rgb1 + fz_mul255((short)dst[2] - rgb1, ssa);
@@ -279,8 +282,8 @@ static void text_1c1(byte * restrict src0, int srcw, byte * restrict dst0, int d
{
while (h--)
{
- byte *src = src0;
- byte *dst = dst0;
+ byte * restrict src = src0;
+ byte * restrict dst = dst0;
int w = w0;
while (w--)
{
@@ -309,11 +312,12 @@ static void text_1o1(byte * restrict src0, int srcw, byte * restrict dst0, int d
}
}
-static void text_w3i1o4(byte * restrict rgb, byte * restrict src0, int srcw, byte * restrict dst0, int dstw, int w0, int h)
+static void text_w3i1o4(byte * restrict argb, byte * restrict src0, int srcw, byte * restrict dst0, int dstw, int w0, int h)
{
- unsigned char rgb0 = rgb[0];
- unsigned char rgb1 = rgb[1];
- unsigned char rgb2 = rgb[2];
+ unsigned char ca = argb[0];
+ unsigned char rgb0 = argb[1];
+ unsigned char rgb1 = argb[2];
+ unsigned char rgb2 = argb[3];
while (h--)
{
byte *src = src0;
@@ -321,7 +325,7 @@ static void text_w3i1o4(byte * restrict rgb, byte * restrict src0, int srcw, byt
int w = w0;
while (w--)
{
- byte sa = src[0];
+ byte sa = fz_mul255(src[0], ca);
byte ssa = 255 - sa;
dst[0] = sa + fz_mul255(dst[0], ssa);
dst[1] = rgb0 + fz_mul255((short)dst[1] - rgb0, ssa);
diff --git a/raster/render.c b/raster/render.c
index 65a32fc1..e3caadce 100644
--- a/raster/render.c
+++ b/raster/render.c
@@ -47,9 +47,10 @@ fz_newrenderer(fz_renderer **gcp, fz_colorspace *pcm, int maskonly, int gcmem)
gc->dest = nil;
gc->over = nil;
- gc->rgb[0] = 0;
- gc->rgb[1] = 0;
- gc->rgb[2] = 0;
+ gc->argb[0] = 255;
+ gc->argb[1] = 0;
+ gc->argb[2] = 0;
+ gc->argb[3] = 0;
gc->flag = 0;
*gcp = gc;
@@ -105,6 +106,7 @@ rendersolid(fz_renderer *gc, fz_solidnode *solid, fz_matrix ctm)
{
fz_error *error;
float rgb[3];
+ unsigned char a, r, g, b;
unsigned char *p;
int n;
@@ -113,14 +115,13 @@ rendersolid(fz_renderer *gc, fz_solidnode *solid, fz_matrix ctm)
if (gc->model->n != 3)
return fz_throw("assert: non-rgb renderer");
- gc->a = solid->a * 255;
-
fz_convertcolor(solid->cs, solid->samples, gc->model, rgb);
- gc->rgb[0] = rgb[0] * 255;
- gc->rgb[1] = rgb[1] * 255;
- gc->rgb[2] = rgb[2] * 255;
+ gc->argb[0] = solid->a * 255;
+ gc->argb[1] = rgb[0] * 255;
+ gc->argb[2] = rgb[1] * 255;
+ gc->argb[3] = rgb[2] * 255;
-DEBUG("solid %s [%d %d %d];\n", solid->cs->name, gc->rgb[0], gc->rgb[1], gc->rgb[2]);
+DEBUG("solid %s [%d %d %d %d];\n", solid->cs->name, gc->argb[0], gc->argb[1], gc->argb[2], gc->argb[3]);
if (gc->flag == FOVER)
{
@@ -135,13 +136,17 @@ DEBUG("solid %s [%d %d %d];\n", solid->cs->name, gc->rgb[0], gc->rgb[1], gc->rgb
p = gc->dest->samples;
n = gc->dest->w * gc->dest->h;
}
-
+
+ a = gc->argb[0];
+ r = gc->argb[1];
+ g = gc->argb[2];
+ b = gc->argb[3];
while (n--)
{
- p[0] = gc->a;
- p[1] = gc->rgb[0];
- p[2] = gc->rgb[1];
- p[3] = gc->rgb[2];
+ p[0] = a;
+ p[1] = r;
+ p[2] = g;
+ p[3] = b;
p += 4;
}
@@ -193,7 +198,7 @@ DEBUG("path %s;\n", path->paint == FZ_STROKE ? "stroke" : "fill");
if (gc->flag & FRGB)
{
return fz_scanconvert(gc->gel, gc->ael, path->paint == FZ_EOFILL,
- clip, gc->over, gc->rgb, 1);
+ clip, gc->over, gc->argb, 1);
}
else if (gc->flag & FOVER)
{
@@ -262,7 +267,7 @@ static void drawglyph(fz_renderer *gc, fz_pixmap *dst, fz_glyph *src, int xorig,
case FOVER | FRGB:
assert(dst->n == 4);
- fz_text_w3i1o4(gc->rgb, sp, src->w, dp, dst->w * 4, w, h);
+ fz_text_w3i1o4(gc->argb, sp, src->w, dp, dst->w * 4, w, h);
break;
default:
@@ -500,7 +505,7 @@ DEBUG(" fover %d x %d\n", w, h);
case FOVER | FRGB:
DEBUG(" fover+rgb %d x %d\n", w, h);
- fz_img_w3i1o4(gc->rgb, PSRC, PDST(gc->over), PCTM);
+ fz_img_w3i1o4(gc->argb, PSRC, PDST(gc->over), PCTM);
break;
default:
@@ -711,9 +716,10 @@ rendermask(fz_renderer *gc, fz_masknode *mask, fz_matrix ctm)
fz_solidnode *solid = (fz_solidnode*)color;
fz_convertcolor(solid->cs, solid->samples, gc->model, rgb);
- gc->rgb[0] = rgb[0] * 255;
- gc->rgb[1] = rgb[1] * 255;
- gc->rgb[2] = rgb[2] * 255;
+ gc->argb[0] = solid->a * 255;
+ gc->argb[1] = rgb[0] * 255;
+ gc->argb[2] = rgb[1] * 255;
+ gc->argb[3] = rgb[2] * 255;
gc->flag |= FRGB;
/* we know these can handle the FRGB shortcut */