diff options
author | Tor Andersson <tor@ghostscript.com> | 2008-03-20 22:59:59 +0100 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2008-03-20 22:59:59 +0100 |
commit | 818644f38c5f75c618af32ed35fa49e0045226ce (patch) | |
tree | aae3658ddc1f0924eac7b6aa2924149cf0fdab90 | |
parent | e3b78a6fa981001224682bf2b487331329285569 (diff) | |
download | mupdf-818644f38c5f75c618af32ed35fa49e0045226ce.tar.xz |
Parse fill/stroke constant alpha values.
-rw-r--r-- | include/fitz/draw_misc.h | 1 | ||||
-rw-r--r-- | include/fitz/wld_tree.h | 3 | ||||
-rw-r--r-- | include/mupdf/content.h | 3 | ||||
-rw-r--r-- | mupdf/pdf_build.c | 14 | ||||
-rw-r--r-- | mupdf/pdf_interpret.c | 12 | ||||
-rw-r--r-- | raster/render.c | 4 | ||||
-rw-r--r-- | world/node_misc2.c | 3 | ||||
-rw-r--r-- | world/node_optimize.c | 2 | ||||
-rw-r--r-- | world/node_toxml.c | 2 |
9 files changed, 32 insertions, 12 deletions
diff --git a/include/fitz/draw_misc.h b/include/fitz/draw_misc.h index cb78b57c..cd9035a1 100644 --- a/include/fitz/draw_misc.h +++ b/include/fitz/draw_misc.h @@ -69,6 +69,7 @@ struct fz_renderer_s fz_irect clip; fz_pixmap *dest; fz_pixmap *over; + unsigned char a; unsigned char rgb[3]; int flag; }; diff --git a/include/fitz/wld_tree.h b/include/fitz/wld_tree.h index 324b8098..87addcd6 100644 --- a/include/fitz/wld_tree.h +++ b/include/fitz/wld_tree.h @@ -122,6 +122,7 @@ struct fz_solidnode_s fz_node super; fz_colorspace *cs; int n; + float a; float samples[FZ_FLEX]; }; @@ -170,7 +171,7 @@ int fz_ismetanode(fz_node *node); /* leaf nodes */ fz_error *fz_newlinknode(fz_node **nodep, fz_tree *subtree); -fz_error *fz_newsolidnode(fz_node **nodep, fz_colorspace *cs, int n, float *v); +fz_error *fz_newsolidnode(fz_node **nodep, float a, fz_colorspace *cs, int n, float *v); fz_error *fz_newimagenode(fz_node **nodep, fz_image *image); fz_error *fz_newshadenode(fz_node **nodep, fz_shade *shade); diff --git a/include/mupdf/content.h b/include/mupdf/content.h index ad6b824d..49c43844 100644 --- a/include/mupdf/content.h +++ b/include/mupdf/content.h @@ -26,10 +26,11 @@ struct pdf_material_s { int kind; fz_colorspace *cs; - float v[32]; pdf_indexed *indexed; pdf_pattern *pattern; fz_shade *shade; + float alpha; + float v[32]; }; struct pdf_gstate_s diff --git a/mupdf/pdf_build.c b/mupdf/pdf_build.c index 9d47d2db..2e58246c 100644 --- a/mupdf/pdf_build.c +++ b/mupdf/pdf_build.c @@ -18,6 +18,7 @@ pdf_initgstate(pdf_gstate *gs) gs->stroke.indexed = nil; gs->stroke.pattern = nil; gs->stroke.shade = nil; + gs->stroke.alpha = 1.0; gs->fill.kind = PDF_MCOLOR; gs->fill.cs = fz_keepcolorspace(pdf_devicegray); @@ -25,6 +26,7 @@ pdf_initgstate(pdf_gstate *gs) gs->fill.indexed = nil; gs->fill.pattern = nil; gs->fill.shade = nil; + gs->fill.alpha = 1.0; gs->charspace = 0; gs->wordspace = 0; @@ -212,7 +214,7 @@ pdf_buildfillpath(pdf_gstate *gs, fz_pathnode *path, int eofill) } static fz_error * -addcolorshape(pdf_gstate *gs, fz_node *shape, fz_colorspace *cs, float *v) +addcolorshape(pdf_gstate *gs, fz_node *shape, float alpha, fz_colorspace *cs, float *v) { fz_error *error; fz_node *mask; @@ -221,7 +223,7 @@ addcolorshape(pdf_gstate *gs, fz_node *shape, fz_colorspace *cs, float *v) error = fz_newmasknode(&mask); if (error) return error; - error = fz_newsolidnode(&solid, cs, cs->n, v); + error = fz_newsolidnode(&solid, alpha, cs, cs->n, v); if (error) return error; fz_insertnodelast(mask, shape); @@ -344,7 +346,7 @@ addpatternshape(pdf_gstate *gs, fz_node *shape, } if (pat->ismask) - return addcolorshape(gs, mask, cs, v); + return addcolorshape(gs, mask, 1.0, cs, v); fz_insertnodelast(gs->head, mask); return nil; @@ -393,7 +395,7 @@ addshadeshape(pdf_gstate *gs, fz_node *shape, fz_shade *shade) error = fz_newovernode(&over); if (error) return error; - error = fz_newsolidnode(&bgnd, shade->cs, shade->cs->n, shade->background); + error = fz_newsolidnode(&bgnd, 1.0, shade->cs, shade->cs->n, shade->background); if (error) return error; fz_insertnodelast(mask, shape); @@ -425,7 +427,7 @@ pdf_addfillshape(pdf_gstate *gs, fz_node *shape) case PDF_MCOLOR: case PDF_MLAB: case PDF_MINDEXED: - return addcolorshape(gs, shape, gs->fill.cs, gs->fill.v); + return addcolorshape(gs, shape, gs->fill.alpha, gs->fill.cs, gs->fill.v); case PDF_MPATTERN: return addpatternshape(gs, shape, gs->fill.pattern, gs->fill.cs, gs->fill.v); case PDF_MSHADE: @@ -446,7 +448,7 @@ pdf_addstrokeshape(pdf_gstate *gs, fz_node *shape) case PDF_MCOLOR: case PDF_MLAB: case PDF_MINDEXED: - return addcolorshape(gs, shape, gs->stroke.cs, gs->stroke.v); + return addcolorshape(gs, shape, gs->stroke.alpha, gs->stroke.cs, gs->stroke.v); case PDF_MPATTERN: return addpatternshape(gs, shape, gs->stroke.pattern, gs->stroke.cs, gs->stroke.v); case PDF_MSHADE: diff --git a/mupdf/pdf_interpret.c b/mupdf/pdf_interpret.c index 02d08edb..a458750b 100644 --- a/mupdf/pdf_interpret.c +++ b/mupdf/pdf_interpret.c @@ -165,6 +165,13 @@ runxobject(pdf_csi *csi, pdf_xref *xref, pdf_xobject *xobj) if (error) return error; + /* reset alpha to 1.0 when starting a new group */ + { + pdf_gstate *gstate = csi->gstate + csi->gtop; + gstate->stroke.alpha = 1.0; + gstate->fill.alpha = 1.0; + } + /* push transform */ error = fz_newtransformnode(&transform, xobj->matrix); @@ -282,6 +289,11 @@ runextgstate(pdf_gstate *gstate, pdf_xref *xref, fz_obj *extgstate) else return fz_throw("syntaxerror in ExtGState/D"); } + + else if (!strcmp(s, "CA")) + gstate->stroke.alpha = fz_toreal(val); + else if (!strcmp(s, "ca")) + gstate->fill.alpha = fz_toreal(val); } return nil; diff --git a/raster/render.c b/raster/render.c index 1c1ff1de..65a32fc1 100644 --- a/raster/render.c +++ b/raster/render.c @@ -113,6 +113,8 @@ 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; @@ -136,7 +138,7 @@ DEBUG("solid %s [%d %d %d];\n", solid->cs->name, gc->rgb[0], gc->rgb[1], gc->rgb while (n--) { - p[0] = 255; + p[0] = gc->a; p[1] = gc->rgb[0]; p[2] = gc->rgb[1]; p[3] = gc->rgb[2]; diff --git a/world/node_misc2.c b/world/node_misc2.c index 5234cbc8..c8986d4d 100644 --- a/world/node_misc2.c +++ b/world/node_misc2.c @@ -230,7 +230,7 @@ fz_boundlinknode(fz_linknode *node, fz_matrix ctm) */ fz_error * -fz_newsolidnode(fz_node **nodep, fz_colorspace *cs, int n, float *v) +fz_newsolidnode(fz_node **nodep, float a, fz_colorspace *cs, int n, float *v) { fz_solidnode *node; int i; @@ -241,6 +241,7 @@ fz_newsolidnode(fz_node **nodep, fz_colorspace *cs, int n, float *v) *nodep = (fz_node*)node; fz_initnode((fz_node*)node, FZ_NCOLOR); + node->a = a; node->cs = fz_keepcolorspace(cs); node->n = n; for (i = 0; i < n; i++) diff --git a/world/node_optimize.c b/world/node_optimize.c index 276e2725..7ee92496 100644 --- a/world/node_optimize.c +++ b/world/node_optimize.c @@ -264,7 +264,7 @@ static fz_error *clean1x1(fz_node *node) fz_droppixmap(pix); - error = fz_newsolidnode(&color, image->cs, image->n, v); + error = fz_newsolidnode(&color, 1.0, image->cs, image->n, v); if (error) return error; error = fz_newmasknode(&mask); diff --git a/world/node_toxml.c b/world/node_toxml.c index 0e970ddd..c6cf146e 100644 --- a/world/node_toxml.c +++ b/world/node_toxml.c @@ -72,7 +72,7 @@ static void xmlsolid(fz_solidnode *node, int level) { int i; indent(level); - printf("<solid colorspace=\"%s\" v=\"", node->cs->name); + printf("<solid colorspace=\"%s\" alpha=\"%g\" v=\"", node->cs->name, node->a); for (i = 0; i < node->n; i++) { printf("%g", node->samples[i]); |