summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@hotmail.com>2009-11-26 00:19:42 +0100
committerSebastian Rasmussen <sebras@hotmail.com>2009-11-26 00:19:42 +0100
commitcf6860c3d70a2f7a63cdb621cc3b58c891915deb (patch)
tree35dada1b4dacff23cc6e3b61176a956004159399
parent3e4dbcabd687819d8ef51f1769f63ba6f497c1b5 (diff)
Factor out color decode parsing to common function for shadings type 4-7.
-rw-r--r--mupdf/pdf_shade4.c104
1 files changed, 40 insertions, 64 deletions
diff --git a/mupdf/pdf_shade4.c b/mupdf/pdf_shade4.c
index fa9850e84..d336d4fa1 100644
--- a/mupdf/pdf_shade4.c
+++ b/mupdf/pdf_shade4.c
@@ -28,6 +28,30 @@ growshademesh(fz_shade *shade, int amount)
return fz_okay;
}
+static fz_error
+parsedecode(fz_obj *decode, int ncomp,
+ float *x0, float *x1, float *y0, float *y1, float *c0, float *c1)
+{
+ int i;
+
+ pdf_logshade("decode array\n");
+
+ *x0 = fz_toreal(fz_arrayget(decode, 0));
+ *x1 = fz_toreal(fz_arrayget(decode, 1));
+ *y0 = fz_toreal(fz_arrayget(decode, 2));
+ *y1 = fz_toreal(fz_arrayget(decode, 3));
+
+ pdf_logshade("domain %g %g %g %g\n", *x0, *x1, *y0, *y1);
+
+ for (i = 0; i < MIN(fz_arraylen(decode) / 2, ncomp); i++)
+ {
+ c0[i] = fz_toreal(fz_arrayget(decode, i * 2 + 4));
+ c1[i] = fz_toreal(fz_arrayget(decode, i * 2 + 5));
+ }
+
+ return fz_okay;
+}
+
fz_error
pdf_loadtype4shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict)
{
@@ -60,22 +84,10 @@ pdf_loadtype4shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict)
bpflag = fz_toint(fz_dictgets(dict, "BitsPerFlag"));
obj = fz_dictgets(dict, "Decode");
- if (fz_isarray(obj))
- {
- pdf_logshade("decode array\n");
- x0 = fz_toreal(fz_arrayget(obj, 0));
- x1 = fz_toreal(fz_arrayget(obj, 1));
- y0 = fz_toreal(fz_arrayget(obj, 2));
- y1 = fz_toreal(fz_arrayget(obj, 3));
- for (i=0; i < fz_arraylen(obj) / 2; ++i) {
- c0[i] = fz_toreal(fz_arrayget(obj, i*2+4));
- c1[i] = fz_toreal(fz_arrayget(obj, i*2+5));
- }
- }
- else {
- error = fz_throw("shading is missing vertex color decoding");
- goto cleanup;
- }
+ if (!fz_isarray(obj))
+ return fz_throw("shading is missing vertex color decoding");
+
+ parsedecode(obj, ncomp, &x0, &x1, &y0, &y1, c0, c1);
obj = fz_dictgets(dict, "Function");
if (obj)
@@ -252,22 +264,10 @@ pdf_loadtype5shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict)
return fz_throw("VerticesPerRow must be greater than or equal to 2");
obj = fz_dictgets(dict, "Decode");
- if (fz_isarray(obj))
- {
- pdf_logshade("decode array\n");
- x0 = fz_toreal(fz_arrayget(obj, 0));
- x1 = fz_toreal(fz_arrayget(obj, 1));
- y0 = fz_toreal(fz_arrayget(obj, 2));
- y1 = fz_toreal(fz_arrayget(obj, 3));
- for (i=0; i < fz_arraylen(obj) / 2; ++i) {
- c0[i] = fz_toreal(fz_arrayget(obj, i*2+4));
- c1[i] = fz_toreal(fz_arrayget(obj, i*2+5));
- }
- }
- else {
- error = fz_throw("shading is missing vertex color decoding");
- goto cleanup;
- }
+ if (!fz_isarray(obj))
+ return fz_throw("shading is missing vertex color decoding");
+
+ parsedecode(obj, ncomp, &x0, &x1, &y0, &y1, c0, c1);
obj = fz_dictgets(dict, "Function");
if (obj)
@@ -631,22 +631,10 @@ pdf_loadtype6shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict)
bpflag = fz_toint(fz_dictgets(dict, "BitsPerFlag"));
obj = fz_dictgets(dict, "Decode");
- if (fz_isarray(obj))
- {
- pdf_logshade("decode array\n");
- p0.x = fz_toreal(fz_arrayget(obj, 0));
- p1.x = fz_toreal(fz_arrayget(obj, 1));
- p0.y = fz_toreal(fz_arrayget(obj, 2));
- p1.y = fz_toreal(fz_arrayget(obj, 3));
- for (i=0; i < fz_arraylen(obj) / 2; ++i) {
- c0[i] = fz_toreal(fz_arrayget(obj, i*2+4));
- c1[i] = fz_toreal(fz_arrayget(obj, i*2+5));
- }
- }
- else {
- error = fz_throw("shading is missing vertex color decoding");
- goto cleanup;
- }
+ if (!fz_isarray(obj))
+ return fz_throw("shading is missing vertex color decoding");
+
+ parsedecode(obj, ncomp, &p0.x, &p1.x, &p0.y, &p1.y, c0, c1);
obj = fz_dictgets(dict, "Function");
if (obj)
@@ -756,22 +744,10 @@ pdf_loadtype7shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict)
bpflag = fz_toint(fz_dictgets(dict, "BitsPerFlag"));
obj = fz_dictgets(dict, "Decode");
- if (fz_isarray(obj))
- {
- pdf_logshade("decode array\n");
- x0 = fz_toreal(fz_arrayget(obj, 0));
- x1 = fz_toreal(fz_arrayget(obj, 1));
- y0 = fz_toreal(fz_arrayget(obj, 2));
- y1 = fz_toreal(fz_arrayget(obj, 3));
- for (i=0; i < fz_arraylen(obj) / 2; ++i) {
- c0[i] = fz_toreal(fz_arrayget(obj, i*2+4));
- c1[i] = fz_toreal(fz_arrayget(obj, i*2+5));
- }
- }
- else {
- error = fz_throw("shading is missing vertex color decoding");
- goto cleanup;
- }
+ if (!fz_isarray(obj))
+ return fz_throw("shading is missing vertex color decoding");
+
+ parsedecode(obj, ncomp, &x0, &x1, &y0, &y1, c0, c1);
obj = fz_dictgets(dict, "Function");
if (obj)