summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Jeong Hee <jeong@pdf-pro.com>2004-12-08 20:04:42 +0100
committerKim Jeong Hee <jeong@pdf-pro.com>2004-12-08 20:04:42 +0100
commit9f1cb4223a122fb0aa0eb60166976944c2613c8c (patch)
tree9142789d9811ebbb21fdb1fad64338500680463a
parenta623f0e4b720e774d8fd02ed4cce523659cd7c59 (diff)
downloadmupdf-9f1cb4223a122fb0aa0eb60166976944c2613c8c.tar.xz
shade type 1 implementation 16x16 segmented meshs
-rw-r--r--mupdf/shade.c9
-rw-r--r--mupdf/shade1.c82
2 files changed, 73 insertions, 18 deletions
diff --git a/mupdf/shade.c b/mupdf/shade.c
index 12d6b525..a72bf56a 100644
--- a/mupdf/shade.c
+++ b/mupdf/shade.c
@@ -13,9 +13,8 @@ pdf_loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *shading, float t0
obj = fz_dictgets(shading, "Function");
if (obj)
{
- shade->usefunction = 1;
-
- error = pdf_loadfunction(&func, xref, obj);
+ t = t0 + (i / 256.0) * (t1 - t0);
+ error = pdf_evalfunction(func, &t, 1, shade->function[i], shade->cs->n);
if (error)
return error;
@@ -100,6 +99,10 @@ 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 2:
error = pdf_loadtype2shade(shade, xref, dict, ref, mat);
if (error) goto cleanup;
diff --git a/mupdf/shade1.c b/mupdf/shade1.c
index 5ce3ee95..16ed04e3 100644
--- a/mupdf/shade1.c
+++ b/mupdf/shade1.c
@@ -2,17 +2,33 @@
#include <mupdf.h>
fz_error *
-pdf_buildt1shademesh(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
- fz_obj *ref, fz_matrix mat)
+loadshadefunction(fz_shade *shade, pdf_xref *xref, fz_obj *shading, float x0, float x1, float y0, float y1)
{
fz_error *error;
+ float t[2];
+ fz_obj *obj;
+ pdf_function *func;
- shade->meshlen = 2;
- shade->mesh = (float*) malloc(sizeof(float) * 9 * meshlen);
+ shade->usefunction = 1;
- pdf_setmeshvalue(mesh, 0, shade->
-cleanup:
- return error;
+ obj = fz_dictgets(shading, "Function");
+ error = pdf_loadfunction(&func, xref, obj);
+ if (error)
+ return error;
+
+
+ for (int y = 0; y < 16; ++y) {
+ t[1] = y0 + (y / 15.0) * (y1 - y0);
+ for (int 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);
+ if (error)
+ return error;
+ }
+ }
+
+ return nil;
}
fz_error *
@@ -21,16 +37,52 @@ pdf_loadtype1shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading,
{
fz_error *error;
fz_obj *obj;
+ float x, y;
+ float xn, yn;
+ float x0, y0, x1, y1;
+ float t;
+ int n;
obj = fz_dictgets(shading, "Domain");
- if (obj) {
- t0 = fz_toreal(fz_arrayget(obj, 0));
- t1 = fz_toreal(fz_arrayget(obj, 1));
- } else {
- t0 = 0.;
- t1 = 1.;
+ 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");
+ if (obj)
+ {
+ shade->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();
+ }
+
+ error = loadshadefunction(shade, xref, shading, x0, x1, y0, y1);
+
+ shade->meshlen = 512;
+ shade->mesh = (float*) malloc(sizeof(float) * 3*3 * shade->meshlen);
+
+ n = 0;
+ for (int 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) {
+ x = x0 + (x1 - x0) * (xx / 16.0);
+ xn = x0 + (x1 - x0) * (xx + 1) / 16.0;
- pdf_loadshadefunction(shade, xref, shading);
- pdf_buildt1shademesh(shade, xref, shading, ref, mat);
+ t = (yy * 16 + xx) / 255.;
+ pdf_setmeshvalue(shade->mesh, n++, x, y, t);
+ pdf_setmeshvalue(shade->mesh, n++, xn, y, t);
+ pdf_setmeshvalue(shade->mesh, n++, xn, yn, t);
+ pdf_setmeshvalue(shade->mesh, n++, x, y, t);
+ pdf_setmeshvalue(shade->mesh, n++, xn, yn, t);
+ pdf_setmeshvalue(shade->mesh, n++, x, yn, t);
+ }
+ }
+
+ return error;
}