summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jamfile1
-rw-r--r--base/cpudep.c5
-rw-r--r--include/mupdf/rsrc.h21
-rw-r--r--mupdf/repair.c6
-rw-r--r--mupdf/shade.c37
-rw-r--r--mupdf/shade1.c51
-rw-r--r--mupdf/shade2.c48
-rw-r--r--mupdf/shade3.c136
-rw-r--r--render/meshdraw.c4
9 files changed, 141 insertions, 168 deletions
diff --git a/Jamfile b/Jamfile
index 68867637..6b452ddf 100644
--- a/Jamfile
+++ b/Jamfile
@@ -128,6 +128,7 @@ Library libmupdf :
mupdf/image.c
mupdf/pattern.c
mupdf/shade.c
+ mupdf/shade1.c
mupdf/shade2.c
mupdf/shade3.c
mupdf/cmap.c
diff --git a/base/cpudep.c b/base/cpudep.c
index b9e7b36a..4175fafc 100644
--- a/base/cpudep.c
+++ b/base/cpudep.c
@@ -87,7 +87,10 @@ static const featuretest features[] = {
#endif
#ifndef HAVE_CPUDEP
-static const featuretest features[] = {};
+static void dummy(void) {}
+static const featuretest features[1] = {
+ { dummy, 0, "dummy" }
+};
#endif
#include <signal.h> /* signal/sigaction */
diff --git a/include/mupdf/rsrc.h b/include/mupdf/rsrc.h
index 30a35b1e..29c8fa97 100644
--- a/include/mupdf/rsrc.h
+++ b/include/mupdf/rsrc.h
@@ -86,20 +86,15 @@ void pdf_droppattern(pdf_pattern *pat);
* Shading
*/
-fz_error *
-pdf_loadtype1shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
- fz_obj *ref, fz_matrix mat);
-fz_error *
-pdf_loadtype2shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
- fz_obj *ref, fz_matrix mat);
-fz_error *
-pdf_loadtype3shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
- fz_obj *ref, fz_matrix mat);
-
-fz_error *
-pdf_loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *shading, float t0, float t1);
-
void pdf_setmeshvalue(float *mesh, int i, float x, float y, float t);
+fz_error *pdf_loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *dict, float t0, float t1);
+fz_error *pdf_loadtype1shade(fz_shade *, pdf_xref *, fz_obj *dict, fz_obj *ref);
+fz_error *pdf_loadtype2shade(fz_shade *, pdf_xref *, fz_obj *dict, fz_obj *ref);
+fz_error *pdf_loadtype3shade(fz_shade *, pdf_xref *, fz_obj *dict, fz_obj *ref);
+fz_error *pdf_loadtype4shade(fz_shade *, pdf_xref *, fz_obj *dict, fz_obj *ref);
+fz_error *pdf_loadtype5shade(fz_shade *, pdf_xref *, fz_obj *dict, fz_obj *ref);
+fz_error *pdf_loadtype6shade(fz_shade *, pdf_xref *, fz_obj *dict, fz_obj *ref);
+fz_error *pdf_loadtype7shade(fz_shade *, pdf_xref *, fz_obj *dict, fz_obj *ref);
fz_error *pdf_loadshade(fz_shade **shadep, pdf_xref *xref, fz_obj *obj, fz_obj *ref);
/*
diff --git a/mupdf/repair.c b/mupdf/repair.c
index bacdaead..bd0f6add 100644
--- a/mupdf/repair.c
+++ b/mupdf/repair.c
@@ -212,6 +212,12 @@ pdf_repairpdf(pdf_xref **xrefp, char *filename)
break;
}
+ if (rootoid == 0)
+ {
+ error = fz_throw("syntaxerror: could not find catalog");
+ goto cleanup;
+ }
+
error = fz_packobj(&xref->trailer,
"<< /Size %i /Root %r >>",
maxoid + 1, rootoid, rootgen);
diff --git a/mupdf/shade.c b/mupdf/shade.c
index a72bf56a..b309a2be 100644
--- a/mupdf/shade.c
+++ b/mupdf/shade.c
@@ -13,8 +13,9 @@ pdf_loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *shading, float t0
obj = fz_dictgets(shading, "Function");
if (obj)
{
- t = t0 + (i / 256.0) * (t1 - t0);
- error = pdf_evalfunction(func, &t, 1, shade->function[i], shade->cs->n);
+ shade->usefunction = 1;
+
+ error = pdf_loadfunction(&func, xref, obj);
if (error)
return error;
@@ -35,8 +36,16 @@ pdf_loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *shading, float t0
return nil;
}
+void
+pdf_setmeshvalue(float *mesh, int i, float x, float y, float t)
+{
+ mesh[i*3+0] = x;
+ mesh[i*3+1] = y;
+ mesh[i*3+2] = t;
+}
+
static fz_error *
-loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_obj *ref, fz_matrix mat)
+loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_obj *ref, fz_matrix matrix)
{
fz_error *error;
fz_shade *shade;
@@ -53,7 +62,7 @@ loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_obj *ref, fz_m
shade->refs = 1;
shade->usebackground = 0;
shade->usefunction = 0;
- shade->matrix = mat;
+ shade->matrix = matrix;
obj = fz_dictgets(dict, "ShadingType");
type = fz_toint(obj);
@@ -99,16 +108,16 @@ loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_obj *ref, fz_m
switch(type)
{
-// case 1:
-// error = pdf_loadtype1shade(shade, xref, dict, ref, mat);
-// if (error) goto cleanup;
-// break;
+ case 1:
+ error = pdf_loadtype1shade(shade, xref, dict, ref);
+ if (error) goto cleanup;
+ break;
case 2:
- error = pdf_loadtype2shade(shade, xref, dict, ref, mat);
+ error = pdf_loadtype2shade(shade, xref, dict, ref);
if (error) goto cleanup;
break;
case 3:
- error = pdf_loadtype3shade(shade, xref, dict, ref, mat);
+ error = pdf_loadtype3shade(shade, xref, dict, ref);
if (error) goto cleanup;
break;
default:
@@ -198,11 +207,3 @@ pdf_loadshade(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
return nil;
}
-void
-pdf_setmeshvalue(float *mesh, int i, float x, float y, float t)
-{
- mesh[i*3+0] = x;
- mesh[i*3+1] = y;
- mesh[i*3+2] = t;
-}
-
diff --git a/mupdf/shade1.c b/mupdf/shade1.c
index 16ed04e3..63c276b3 100644
--- a/mupdf/shade1.c
+++ b/mupdf/shade1.c
@@ -2,24 +2,26 @@
#include <mupdf.h>
fz_error *
-loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *shading, float x0, float x1, float y0, float y1)
+loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *dict,
+ float x0, float x1, float y0, float y1)
{
fz_error *error;
float t[2];
fz_obj *obj;
pdf_function *func;
+ int x, y;
shade->usefunction = 1;
- obj = fz_dictgets(shading, "Function");
+ obj = fz_dictgets(dict, "Function");
error = pdf_loadfunction(&func, xref, obj);
if (error)
return error;
-
- for (int y = 0; y < 16; ++y) {
+ for (y = 0; y < 16; ++y)
+ {
t[1] = y0 + (y / 15.0) * (y1 - y0);
- for (int x = 0; x < 16; ++x)
+ for (x = 0; x < 16; ++x)
{
t[0] = x0 + (x / 15.0) * (x1 - x0);
error = pdf_evalfunction(func, t, 2, shade->function[y*16+x], shade->cs->n);
@@ -32,45 +34,53 @@ loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *shading, float x0, fl
}
fz_error *
-pdf_loadtype1shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
- fz_obj *ref, fz_matrix mat)
+pdf_loadtype1shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
{
fz_error *error;
fz_obj *obj;
+ fz_matrix matrix;
+ int xx, yy;
float x, y;
float xn, yn;
float x0, y0, x1, y1;
float t;
int n;
- obj = fz_dictgets(shading, "Domain");
+ pdf_logshade("type1 shade {\n");
+
+ obj = fz_dictgets(dict, "Domain");
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));
- obj = fz_dictgets(shading, "Matrix");
+ pdf_logshade("domain %g %g %g %g\n", x0, x1, y0, y1);
+
+ obj = fz_dictgets(dict, "Matrix");
if (obj)
{
- shade->matrix = pdf_tomatrix(obj);
+ matrix = 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
- {
- shade->matrix = fz_identity();
+ matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
+ shade->matrix = fz_concat(matrix, shade->matrix);
}
- error = loadshadefunction(shade, xref, shading, x0, x1, y0, y1);
+ error = loadshadefunction(shade, xref, dict, x0, x1, y0, y1);
+ if (error)
+ return error;
shade->meshlen = 512;
- shade->mesh = (float*) malloc(sizeof(float) * 3*3 * shade->meshlen);
+ shade->mesh = fz_malloc(sizeof(float) * 3*3 * shade->meshlen);
+ if (!shade->mesh)
+ return fz_outofmem;
n = 0;
- for (int yy = 0; yy < 16; ++yy) {
+ for (yy = 0; yy < 16; ++yy)
+ {
y = y0 + (y1 - y0) * yy / 16.0;
yn = y0 + (y1 - y0) * (yy + 1) / 16.0;
- for (int xx = 0; xx < 16; ++xx) {
+ for (xx = 0; xx < 16; ++xx)
+ {
x = x0 + (x1 - x0) * (xx / 16.0);
xn = x0 + (x1 - x0) * (xx + 1) / 16.0;
@@ -84,5 +94,6 @@ pdf_loadtype1shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
}
}
- return error;
+ return nil;
}
+
diff --git a/mupdf/shade2.c b/mupdf/shade2.c
index 8871b6bf..4af9e056 100644
--- a/mupdf/shade2.c
+++ b/mupdf/shade2.c
@@ -1,20 +1,24 @@
#include <fitz.h>
#include <mupdf.h>
+#define BIGNUM 32000
+
fz_error *
-pdf_buildt2shademesh(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
- fz_obj *ref, fz_matrix mat)
+pdf_loadtype2shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
{
- fz_error *error;
+ fz_point p1, p2, p3, p4;
+ fz_point ep1, ep2, ep3, ep4;
float x0, y0, x1, y1;
float t0, t1;
int e0, e1;
fz_obj *obj;
- pdf_function *func;
+ float theta;
+ float dist;
+ int n;
pdf_logshade("load type2 shade {\n");
- obj = fz_dictgets(shading, "Coords");
+ obj = fz_dictgets(dict, "Coords");
x0 = fz_toreal(fz_arrayget(obj, 0));
y0 = fz_toreal(fz_arrayget(obj, 1));
x1 = fz_toreal(fz_arrayget(obj, 2));
@@ -22,7 +26,7 @@ pdf_buildt2shademesh(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
pdf_logshade("coords %g %g %g %g\n", x0, y0, x1, y1);
- obj = fz_dictgets(shading, "Domain");
+ obj = fz_dictgets(dict, "Domain");
if (obj) {
t0 = fz_toreal(fz_arrayget(obj, 0));
t1 = fz_toreal(fz_arrayget(obj, 1));
@@ -31,7 +35,7 @@ pdf_buildt2shademesh(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
t1 = 1.;
}
- obj = fz_dictgets(shading, "Extend");
+ obj = fz_dictgets(dict, "Extend");
if (obj) {
e0 = fz_tobool(fz_arrayget(obj, 0));
e1 = fz_tobool(fz_arrayget(obj, 1));
@@ -43,24 +47,20 @@ pdf_buildt2shademesh(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
pdf_logshade("domain %g %g\n", t0, t1);
pdf_logshade("extend %d %d\n", e0, e1);
- pdf_loadshadefunction(shade, xref, shading, t0, t1);
+ pdf_loadshadefunction(shade, xref, dict, t0, t1);
- shade->meshlen = 2 + e0 *2 + e1 * 2;
- shade->mesh = (float*) malloc(sizeof(float) * 3*3 * shade->meshlen);
+ shade->meshlen = 2 + e0 * 2 + e1 * 2;
+ shade->mesh = fz_malloc(sizeof(float) * 3*3 * shade->meshlen);
+ if (!shade->mesh)
+ return fz_outofmem;
- float theta;
theta = atan2(y1 - y0, x1 - x0);
theta += M_PI / 2.0;
pdf_logshade("theta=%g\n", theta);
- fz_point p1, p2, p3, p4;
- fz_point ep1, ep2, ep3, ep4;
- float dist;
dist = hypot(x1 - x0, y1 - y0);
-#define BIGNUM 1000
-
p1.x = x0 + BIGNUM * cos(theta);
p1.y = y0 + BIGNUM * sin(theta);
p2.x = x1 + BIGNUM * cos(theta);
@@ -84,7 +84,7 @@ pdf_buildt2shademesh(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
pdf_logshade("p3 %g %g\n", p3.x, p3.y);
pdf_logshade("p4 %g %g\n", p4.x, p4.y);
- int n = 0;
+ n = 0;
pdf_setmeshvalue(shade->mesh, n++, p1.x, p1.y, 0);
pdf_setmeshvalue(shade->mesh, n++, p2.x, p2.y, 1);
@@ -114,19 +114,5 @@ pdf_buildt2shademesh(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
pdf_logshade("}\n");
return nil;
-
-cleanup:
- return error;
}
-fz_error *
-pdf_loadtype2shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
- fz_obj *ref, fz_matrix mat)
-{
- fz_error *error;
- fz_obj *obj;
-
- pdf_buildt2shademesh(shade, xref, shading, ref, mat);
-
- return nil;
-}
diff --git a/mupdf/shade3.c b/mupdf/shade3.c
index a7914c90..59cfaed2 100644
--- a/mupdf/shade3.c
+++ b/mupdf/shade3.c
@@ -1,6 +1,8 @@
#include <fitz.h>
#include <mupdf.h>
+#define BIGNUM 32000
+
#define MAX_RAD_SEGS 36
int
@@ -10,19 +12,24 @@ buildannulusmesh(float* mesh, int pos,
{
int n = pos * 3;
float dist = hypot(x1 - x0, y1 - y0);
+ float step;
float theta;
+ int i;
+
if (dist != 0)
theta = asin((r1 - r0) / dist) + M_PI/2.0 + atan2(y1 - y0, x1 - x0);
else
theta = 0;
- if (!(theta >= 0 && theta <= M_PI)) {
+
+ if (!(theta >= 0 && theta <= M_PI))
theta = 0;
- }
- float step = M_PI * 2. / (float)MAX_RAD_SEGS;
- fz_point pt1, pt2, pt3, pt4;
+ step = M_PI * 2. / (float)MAX_RAD_SEGS;
+
+ for (i = 0; i < MAX_RAD_SEGS; theta -= step, ++i)
+ {
+ fz_point pt1, pt2, pt3, pt4;
- for (int i=0; i < MAX_RAD_SEGS; theta -= step, ++i) {
pt1.x = cos (theta) * r1 + x1;
pt1.y = sin (theta) * r1 + y1;
pt2.x = cos (theta) * r0 + x0;
@@ -54,61 +61,16 @@ buildannulusmesh(float* mesh, int pos,
return pos;
}
-#endif
-
-
fz_error *
-fz_buildannulusmesh(float* mesh,
- int x0, int y0, int r0, int x1, int y1, int r1,
- float c0, float c1, int nsegs)
+pdf_loadtype3shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading, fz_obj *ref)
{
- fz_error *error;
- fz_point pt1, pt2, pt3, pt4;
- float step;
- float theta;
-
- theta = 0.;
- step = 3.1415921 * 2. / (float)nsegs;
-
- for (int n=0; theta < step*nsegs; theta += step) {
- pt1.x = cos (theta) * r1 + x1;
- pt1.y = sin (theta) * r1 + y1;
- pt2.x = cos (theta) * r0 + x0;
- pt2.y = sin (theta) * r0 + y0;
- pt3.x = cos (theta+step) * r1 + x1;
- pt3.y = sin (theta+step) * r1 + y1;
- pt4.x = cos (theta+step) * r0 + x0;
- pt4.y = sin (theta+step) * r0 + y0;
-
- pdf_setmeshvalue(mesh, n, pt1.x, pt1.y, c1);
- ++n;
- pdf_setmeshvalue(mesh, n, pt2.x, pt2.y, c0);
- ++n;
- pdf_setmeshvalue(mesh, n, pt4.x, pt4.y, c0);
- ++n;
-
- pdf_setmeshvalue(mesh, n, pt1.x, pt1.y, c1);
- ++n;
- pdf_setmeshvalue(mesh, n, pt3.x, pt3.y, c1);
- ++n;
- pdf_setmeshvalue(mesh, n, pt4.x, pt4.y, c0);
- ++n;
- }
-
- return error;
-}
-
-fz_error *
-pdf_loadtype3shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
- fz_obj *ref, fz_matrix mat)
-{
- fz_error *error;
+ fz_obj *obj;
float x0, y0, r0, x1, y1, r1;
float t0, t1;
int e0, e1;
- int e0meshlen, e1meshlen;
- fz_obj *obj;
- pdf_function *func;
+ float ex0, ey0, er0;
+ float ex1, ey1, er1;
+ float rs;
int i;
pdf_logshade("load type3 shade {\n");
@@ -133,8 +95,6 @@ pdf_loadtype3shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
}
obj = fz_dictgets(shading, "Extend");
- pdf_logshade("extend %d %d\n", e0, e1);
-
if (obj) {
e0 = fz_tobool(fz_arrayget(obj, 0));
e1 = fz_tobool(fz_arrayget(obj, 1));
@@ -144,38 +104,48 @@ pdf_loadtype3shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
}
pdf_logshade("domain %g %g\n", t0, t1);
+ pdf_logshade("extend %d %d\n", e0, e1);
pdf_loadshadefunction(shade, xref, shading, t0, t1);
- shade->meshlen = 36 * 10 * 2;
- shade->mesh = (float*) malloc(sizeof(float) * 9 * shade->meshlen);
-
- float tn, tn1;
- float tstep = (t1 - t0) / 10.;
- tn = t0;
- tn1 = t0 + tstep;
-
- for (int i = 0; i < 10; ++i) {
- float tx0, ty0, tr0;
- float tx1, ty1, tr1;
- float c0, c1;
-
- tx0 = x0 + (x1 - x0) * i / 10.;
- ty0 = y0 + (y1 - y0) * i / 10.;
- tr0 = r0 + (r1 - r0) * i / 10.;
- tx1 = x0 + (x1 - x0) * (i + 1) / 10.;
- ty1 = y0 + (y1 - y0) * (i + 1) / 10.;
- tr1 = r0 + (r1 - r0) * (i + 1) / 10.;
- c0 = i / 10.0;
- c1 = (i + 1) / 10.0;
-
- fz_buildannulusmesh(&(shade->mesh[i*36*2*9]), tx0, ty0, tr0, tx1, ty1, tr1, c0, c1, 36);
+ if (r0 < r1)
+ rs = r0 / (r0 - r1);
+ else
+ rs = -BIGNUM;
+
+ ex0 = x0 + (x1 - x0) * rs;
+ ey0 = y0 + (y1 - y0) * rs;
+ er0 = r0 + (r1 - r0) * rs;
+
+ if (r0 > r1)
+ rs = r1 / (r1 - r0);
+ else
+ rs = -BIGNUM;
+
+ ex1 = x1 + (x0 - x1) * rs;
+ ey1 = y1 + (y0 - y1) * rs;
+ er1 = r1 + (r0 - r1) * rs;
+
+ for (i=0; i<2; ++i)
+ {
+ int pos = 0;
+ if (e0)
+ pos = buildannulusmesh(shade->mesh, pos, ex0, ey0, er0, x0, y0, r0, 0, 0, 1-i);
+ pos = buildannulusmesh(shade->mesh, pos, x0, y0, r0, x1, y1, r1, 0, 1., 1-i);
+ if (e1)
+ pos = buildannulusmesh(shade->mesh, pos, x1, y1, r1, ex1, ey1, er1, 1., 1., 1-i);
+
+ if (i == 0)
+ {
+ shade->meshlen = pos;
+ shade->mesh = fz_malloc(sizeof(float) * 9 * shade->meshlen);
+ if (!shade->mesh)
+ return fz_outofmem;
+ }
}
pdf_logshade("}\n");
return nil;
-
-cleanup:
- return error;
}
+
diff --git a/render/meshdraw.c b/render/meshdraw.c
index eb068580..f5b1a3fb 100644
--- a/render/meshdraw.c
+++ b/render/meshdraw.c
@@ -248,8 +248,8 @@ fz_drawtriangle(fz_pixmap *pix, float *av, float *bv, float *cv, int n)
for (i = 0; i < len; i++)
{
- gel[i][0] = fz_floor(poly[i][0]) * 65536; /* trunc and fix */
- gel[i][1] = fz_floor(poly[i][1]); /* y is not fixpoint */
+ gel[i][0] = fz_floor(poly[i][0] + 0.5) * 65536; /* trunc and fix */
+ gel[i][1] = fz_floor(poly[i][1] + 0.5); /* y is not fixpoint */
for (k = 2; k < n; k++)
gel[i][k] = poly[i][k] * 65536; /* fix with precision */
}