diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-12-08 05:56:41 +0100 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-12-08 05:56:41 +0100 |
commit | 9fe76b3d9c643c48c0e05c75b93b1516dac52174 (patch) | |
tree | 27b5f40151746840eb06d8f8721abdcf4d10685c | |
parent | f70650f6e5387c9493e0d14b2cf57f90e8535073 (diff) | |
download | mupdf-9fe76b3d9c643c48c0e05c75b93b1516dac52174.tar.xz |
shade loading cleanups
-rw-r--r-- | include/fitz/shade.h | 2 | ||||
-rw-r--r-- | mupdf/function.c | 2 | ||||
-rw-r--r-- | mupdf/shade.c | 176 | ||||
-rw-r--r-- | mupdf/shade3.c | 2 | ||||
-rw-r--r-- | render/meshdraw.c | 14 | ||||
-rw-r--r-- | tree/shade.c | 4 |
6 files changed, 112 insertions, 88 deletions
diff --git a/include/fitz/shade.h b/include/fitz/shade.h index 02a3a8f3..1b7c81c5 100644 --- a/include/fitz/shade.h +++ b/include/fitz/shade.h @@ -5,7 +5,7 @@ struct fz_shade_s int refs; fz_rect bbox; /* can be fz_infiniterect */ - fz_colorspace *colorspace; + fz_colorspace *cs; /* used by build.c -- not used in drawshade.c */ fz_matrix matrix; /* matrix from pattern dict */ diff --git a/mupdf/function.c b/mupdf/function.c index 586c7af7..f1098c74 100644 --- a/mupdf/function.c +++ b/mupdf/function.c @@ -1107,7 +1107,7 @@ evalsamplefunc(pdf_function *func, float *in, float *out) } /* decode output values */ - out[i] = LERP(out[i], 0, (1 << func->u.sa.bps) - 1, + out[i] = LERP(s0[0], 0, (1 << func->u.sa.bps) - 1, func->u.sa.decode[i][0], func->u.sa.decode[i][1]); out[i] = CLAMP(out[i], func->range[i][0], func->range[i][1]); } diff --git a/mupdf/shade.c b/mupdf/shade.c index 2f65f395..cb8e54e6 100644 --- a/mupdf/shade.c +++ b/mupdf/shade.c @@ -13,71 +13,70 @@ pdf_loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *shading, float t0 obj = fz_dictgets(shading, "Function"); error = pdf_loadfunction(&func, xref, obj); - if (error) return error; + if (error) + return error; - for (int i=0; i<256; ++i) { - t = t0 + (i / 255.0) * (t1 - t0); - error = pdf_evalfunction(func, &t, 1, shade->function[i], shade->colorspace->n); + for (int i = 0; i < 256; ++i) + { + t = t0 + (i / 256.0) * (t1 - t0); + error = pdf_evalfunction(func, &t, 1, shade->function[i], shade->cs->n); + if (error) + return error; } - if (error) return error; return nil; } -fz_error * -pdf_loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *shading, fz_obj *ref, fz_matrix mat) +static fz_error * +loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_obj *ref, fz_matrix mat) { fz_error *error; fz_shade *shade; - pdf_function *func; fz_obj *obj; - - fz_colorspace *cs = nil; - - fz_obj *sobj; int type; + int i; + + pdf_logshade("load shade dict %d %d {\n", fz_tonum(ref), fz_togen(ref)); shade = fz_malloc(sizeof(fz_shade)); + if (!shade) + return fz_outofmem; shade->refs = 1; + shade->usebackground = 0; shade->usefunction = 0; shade->matrix = mat; - pdf_logshade("load shade dict %d %d {\n", fz_tonum(ref), fz_togen(ref)); - - sobj = fz_dictgets(shading, "ShadingType"); - type = fz_toint(sobj); + obj = fz_dictgets(dict, "ShadingType"); + type = fz_toint(obj); + pdf_logshade("type %d\n", type); - sobj = fz_dictgets(shading, "ColorSpace"); - if (sobj) + /* TODO: use finditem... flatten indexed... */ + obj = fz_dictgets(dict, "ColorSpace"); + if (obj) { - error = pdf_resolve(&sobj, xref); + error = pdf_resolve(&obj, xref); if (error) return error; - error = pdf_loadcolorspace(&cs, xref, sobj); + error = pdf_loadcolorspace(&shade->cs, xref, obj); if (error) return error; - /* - if (!strcmp(cs->name, "Indexed")) - { - indexed = (pdf_indexed*)cs; - cs = indexed->base; - } - n = cs->n; - a = 0; - */ - - fz_dropobj(sobj); + fz_dropobj(obj); } - shade->colorspace = cs; - - pdf_logshade("colorspace %s\n", shade->colorspace->name); + pdf_logshade("colorspace %s\n", shade->cs->name); -// shade->background = fz_dictgets(shading, "Background"); + obj = fz_dictgets(dict, "Background"); + if (obj) + { + pdf_logshade("background\n"); + shade->usebackground = 1; + for (i = 0; i < shade->cs->n; i++) + shade->background[i] = fz_toreal(fz_arrayget(obj, i)); + } - obj = fz_dictgets(shading, "BBox"); + obj = fz_dictgets(dict, "BBox"); if (fz_isarray(obj)) { shade->bbox = pdf_torect(obj); @@ -86,87 +85,112 @@ pdf_loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *shading, fz_obj *re shade->bbox.max.x, shade->bbox.max.y); } - switch(type) { - case 1: -// error = pdf_loadtype1shade(shade, xref, shading, ref, mat); - if (error) goto cleanup; - break; + switch(type) + { +// case 1: +// error = pdf_loadtype1shade(shade, xref, dict, ref, mat); +// if (error) goto cleanup; +// break; case 2: - error = pdf_loadtype2shade(shade, xref, shading, ref, mat); + error = pdf_loadtype2shade(shade, xref, dict, ref, mat); if (error) goto cleanup; break; case 3: - error = pdf_loadtype3shade(shade, xref, shading, ref, mat); + error = pdf_loadtype3shade(shade, xref, dict, ref, mat); if (error) goto cleanup; break; - case 4: - break; default: - break; + error = fz_throw("syntaxerror: unknown shading type: %d", type); + goto cleanup; }; + pdf_logshade("}\n"); + *shadep = shade; return nil; cleanup: + fz_dropshade(shade); return error; } fz_error * -pdf_loadshade(fz_shade **shadep, pdf_xref *xref, fz_obj *obj, fz_obj *ref) +pdf_loadshade(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_obj *ref) { - fz_error *error = fz_throw("NYI"); - - fz_obj *shading; + fz_error *error; fz_matrix mat; - fz_obj *extgstate; + fz_obj *obj; + fz_obj *shd; if ((*shadep = pdf_finditem(xref->store, PDF_KSHADE, ref))) return nil; - pdf_logshade("load shade %d %d {\n", fz_tonum(ref), fz_togen(ref)); + /* + * Type 2 pattern dictionary + */ + if (fz_dictgets(dict, "PatternType")) + { + pdf_logshade("load shade pattern %d %d {\n", fz_tonum(ref), fz_togen(ref)); - shading = fz_dictgets(obj, "Shading"); + obj = fz_dictgets(dict, "Matrix"); + if (obj) + { + mat = pdf_tomatrix(obj); + pdf_logshade("matrix [%g %g %g %g %g %g]\n", + mat.a, mat.b, mat.c, mat.d, mat.e, mat.f); + } + else + { + mat = fz_identity(); + } - if (fz_isindirect(shading)) { - error = pdf_loadindirect(&shading, xref, shading); - if (error) goto cleanup; - } + obj = fz_dictgets(dict, "ExtGState"); + if (obj) + { + pdf_logshade("extgstate ...\n"); + } - obj = fz_dictgets(obj, "Matrix"); - if (obj) - mat = pdf_tomatrix(obj); - else - mat = fz_identity(); + obj = fz_dictgets(dict, "Shading"); + if (!obj) + return fz_throw("syntaxerror: missing shading dictionary"); - if (fz_isdict(shading)) { - pdf_loadshadedict(shadep, xref, shading, ref, mat); - } - else if (pdf_isstream(xref, fz_tonum(shading), fz_togen(shading))) { - } - else { - } + shd = obj; + error = pdf_resolve(&shd, xref); + if (error) + return error; + error = loadshadedict(shadep, xref, shd, obj, mat); + fz_dropobj(shd); + if (error) + return error; - pdf_logshade("}\n"); + pdf_logshade("}\n"); + } - if (*shadep) + /* + * Naked shading dictionary + */ + else { + error = loadshadedict(shadep, xref, dict, ref, fz_identity()); + if (error) + return error; + } + error = pdf_storeitem(xref->store, PDF_KSHADE, ref, *shadep); if (error) - goto cleanup; + { + fz_dropshade(*shadep); + return error; } return nil; - -cleanup: - return error; } void pdf_setmeshvalue(float *mesh, int i, float x, float y, float t) { -// pdf_logshade("mesh %d: %g %g %g\n", i, x, y, t); mesh[i*3+0] = x; mesh[i*3+1] = y; mesh[i*3+2] = t; } + diff --git a/mupdf/shade3.c b/mupdf/shade3.c index eb2badac..d56c3819 100644 --- a/mupdf/shade3.c +++ b/mupdf/shade3.c @@ -396,7 +396,7 @@ pdf_loadtype3shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading, y1 = fz_toreal(fz_arrayget(obj, 4)); r1 = fz_toreal(fz_arrayget(obj, 5)); - pdf_logshade("coords %g %g %g %g %g %g\n", x0, y0, r0, x1, y1, r1); + pdf_logshade("coords %g %g %g %g %g %g\n", x0, y0, r0, x1, y1, r1); obj = fz_dictgets(shading, "Domain"); if (obj) { diff --git a/render/meshdraw.c b/render/meshdraw.c index 79a49768..eb068580 100644 --- a/render/meshdraw.c +++ b/render/meshdraw.c @@ -333,17 +333,17 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *destcs, fz_pixmap if (error) return error; } - else if (shade->colorspace != destcs) + else if (shade->cs != destcs) { - n = 2 + shade->colorspace->n; + n = 2 + shade->cs->n; error = fz_newpixmap(&temp, dest->x, dest->y, dest->w, dest->h, - shade->colorspace->n + 1); + shade->cs->n + 1); if (error) return error; } else { - n = 2 + shade->colorspace->n; + n = 2 + shade->cs->n; temp = dest; } @@ -368,7 +368,7 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *destcs, fz_pixmap { for (i = 0; i < 256; i++) { - fz_convertcolor(shade->colorspace, shade->function[i], destcs, rgb); + fz_convertcolor(shade->cs, shade->function[i], destcs, rgb); clut[i][0] = rgb[0] * 255; clut[i][1] = rgb[1] * 255; clut[i][2] = rgb[2] * 255; @@ -391,9 +391,9 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *destcs, fz_pixmap fz_droppixmap(temp); } - else if (shade->colorspace != destcs) + else if (shade->cs != destcs) { - fz_convertpixmap(shade->colorspace, temp, destcs, dest); + fz_convertpixmap(shade->cs, temp, destcs, dest); fz_droppixmap(temp); } diff --git a/tree/shade.c b/tree/shade.c index f092fa9d..cb33072e 100644 --- a/tree/shade.c +++ b/tree/shade.c @@ -12,8 +12,8 @@ fz_dropshade(fz_shade *shade) { if (--shade->refs == 0) { - if (shade->colorspace) - fz_dropcolorspace(shade->colorspace); + if (shade->cs) + fz_dropcolorspace(shade->cs); fz_free(shade); } } |