summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2004-10-21 10:51:08 +0200
committerTor Andersson <tor@ghostscript.com>2004-10-21 10:51:08 +0200
commitded124f1cc463bac9e076146a4ffb77b8a370e0c (patch)
treec1b35fe12bd14ed507294b185587b428a92bcbef /render
parent730cf84f6323b977bf7bcde1557d1803a16ad855 (diff)
downloadmupdf-ded124f1cc463bac9e076146a4ffb77b8a370e0c.tar.xz
rewrote resource dict handling
Diffstat (limited to 'render')
-rw-r--r--render/render.c14
-rw-r--r--render/renderimage.c59
-rw-r--r--render/renderpath.c53
-rw-r--r--render/rendertext.c8
-rw-r--r--render/scanconv.c30
5 files changed, 119 insertions, 45 deletions
diff --git a/render/render.c b/render/render.c
index d46d5b71..29b51480 100644
--- a/render/render.c
+++ b/render/render.c
@@ -5,6 +5,9 @@ fz_error *fz_rendercolorpath(fz_renderer*, fz_pathnode*, fz_colornode*, fz_matri
fz_error *fz_rendertext(fz_renderer*, fz_textnode*, fz_matrix);
fz_error *fz_renderpath(fz_renderer*, fz_pathnode*, fz_matrix);
+fz_error *fz_renderimageover(fz_renderer*, fz_imagenode*, fz_matrix);
+fz_error *fz_renderimage(fz_renderer*, fz_imagenode*, fz_matrix);
+
fz_error *
fz_newrenderer(fz_renderer **gcp, fz_colorspace *processcolormodel)
{
@@ -131,7 +134,6 @@ fz_renderover(fz_renderer *gc, fz_overnode *over, fz_matrix ctm)
fz_error *error;
fz_pixmap *oldacc = nil;
int oldmode;
-int i;
/* uh-oh! we have a new over cluster */
if (gc->mode != FZ_ROVER)
@@ -209,6 +211,10 @@ fz_rendermask(fz_renderer *gc, fz_masknode *mask, fz_matrix ctm)
fz_blendmask(gc->tmp, colorpix, shapepix);
+//printf("mask color");fz_debugpixmap(colorpix);getchar();
+//printf("mask shape");fz_debugpixmap(shapepix);getchar();
+//printf("mask blend");fz_debugpixmap(gc->tmp);getchar();
+
fz_freepixmap(shapepix);
fz_freepixmap(colorpix);
@@ -246,6 +252,8 @@ fz_rendernode(fz_renderer *gc, fz_node *node, fz_matrix ctm)
return fz_renderpath(gc, (fz_pathnode*)node, ctm);
case FZ_NTEXT:
return fz_rendertext(gc, (fz_textnode*)node, ctm);
+ case FZ_NIMAGE:
+ return fz_renderimage(gc, (fz_imagenode*)node, ctm);
default:
return nil;
}
@@ -261,6 +269,10 @@ fz_rendertree(fz_pixmap **outp, fz_renderer *gc, fz_tree *tree, fz_matrix ctm, f
gc->w = ceil(bbox.max.x) - floor(bbox.min.x);
gc->h = ceil(bbox.max.y) - floor(bbox.min.y);
+ /* compensate for rounding */
+ ctm.e -= bbox.min.x - floor(bbox.min.x);
+ ctm.f -= bbox.min.y - floor(bbox.min.y);
+
error = fz_rendernode(gc, tree->root, ctm);
if (error)
return error;
diff --git a/render/renderimage.c b/render/renderimage.c
new file mode 100644
index 00000000..4c6ef816
--- /dev/null
+++ b/render/renderimage.c
@@ -0,0 +1,59 @@
+#include <fitz.h>
+
+static int cmpy(const void *a, const void *b)
+{
+ const fz_point *ap = a;
+ const fz_point *bp = b;
+ return bp->y - ap->y;
+}
+
+static void
+drawtile(fz_pixmap *out, fz_pixmap *tile, fz_matrix ctm)
+{
+ static const fz_point rect[4] = { {0, 0}, {0, 1}, {1, 1}, {1, 0} };
+ fz_point v[4];
+ int i;
+
+ for (i = 0; i < 4; i++)
+ v[i] = fz_transformpoint(ctm, rect[i]);
+
+ qsort(v, 4, sizeof(fz_point), cmpy);
+
+ for (i = 0; i < 4; i++)
+ printf("%d: %g %g\n", i, v[i].x, v[i].y);
+
+}
+
+fz_error *
+fz_renderimage(fz_renderer *gc, fz_imagenode *node, fz_matrix ctm)
+{
+ fz_error *error;
+ fz_pixmap *tile;
+ fz_image *image = node->image;
+ fz_colorspace *cs = image->cs;
+ int w = image->w;
+ int h = image->h;
+ int n = image->n;
+
+ error = fz_newpixmap(&tile, cs, 0, 0, w, h, n, 1);
+ if (error)
+ return error;
+
+ error = fz_newpixmap(&gc->tmp, cs, gc->x, gc->y, gc->w, gc->h, n, 1);
+ if (error)
+ goto cleanup;
+
+ error = image->loadtile(image, tile);
+ if (error)
+ goto cleanup;
+
+ drawtile(gc->tmp, tile, ctm);
+
+ fz_freepixmap(tile);
+ return nil;
+
+cleanup:
+ fz_freepixmap(tile);
+ return error;
+}
+
diff --git a/render/renderpath.c b/render/renderpath.c
index 9e805a53..8d2f875b 100644
--- a/render/renderpath.c
+++ b/render/renderpath.c
@@ -1,6 +1,8 @@
#include <fitz.h>
-enum { HS = 17, VS = 15 };
+// enum { HS = 1, VS = 1, SF = 255 };
+// enum { HS = 5, VS = 3, SF = 17 };
+enum { HS = 17, VS = 15, SF = 1 };
static fz_error *pathtogel(fz_gel *gel, fz_pathnode *path, fz_matrix ctm)
{
@@ -17,7 +19,7 @@ static fz_error *pathtogel(fz_gel *gel, fz_pathnode *path, fz_matrix ctm)
return fz_fillpath(gel, path, ctm, flatness);
}
-static void blitcolorspan(int y, int x0, int n, short *list, void *userdata)
+static void blitcolorspan(int y, int x, int n, unsigned char *alpha, void *userdata)
{
fz_renderer *gc = userdata;
fz_pixmap *pix = gc->acc;
@@ -28,23 +30,24 @@ static void blitcolorspan(int y, int x0, int n, short *list, void *userdata)
unsigned char g = gc->g;
unsigned char b = gc->b;
- sa = 0;
-
- while (x0 < pix->x)
+ if (x < pix->x)
{
- sa += *list++;
- x0 ++;
- n --;
+ alpha += pix->x - x;
+ n -= pix->x - x;
+ x = pix->x;
}
- if (n > pix->w)
- n = pix->w;
+ if (x + n > pix->x + pix->w)
+ n = pix->x + pix->w - x;
+
+ if (n < 0)
+ return;
- p = &pix->samples[(y - pix->y) * pix->stride + (x0 - pix->x) * 4];
+ p = &pix->samples[(y - pix->y) * pix->stride + (x - pix->x) * 4];
while (n--)
{
- sa += *list++;
+ sa = *alpha++ * SF;
ssa = 255 - sa;
p[0] = fz_mul255(r, sa) + fz_mul255(p[0], ssa);
@@ -56,31 +59,27 @@ static void blitcolorspan(int y, int x0, int n, short *list, void *userdata)
}
}
-static void blitalphaspan(int y, int x0, int n, short *list, void *userdata)
+static void blitalphaspan(int y, int x, int n, unsigned char *alpha, void *userdata)
{
fz_pixmap *pix = userdata;
- unsigned char a;
unsigned char *p;
- a = 0;
-
- while (x0 < pix->x)
+ if (x < pix->x)
{
- a += *list++;
- x0 ++;
- n --;
+ alpha += pix->x - x;
+ n -= pix->x - x;
+ x = pix->x;
}
- if (n > pix->w)
- n = pix->w;
+ if (x + n > pix->x + pix->w)
+ n = pix->x + pix->w - x;
- p = &pix->samples[(y - pix->y) * pix->stride + (x0 - pix->x) * 4];
+ if (n < 0)
+ return;
+ p = &pix->samples[(y - pix->y) * pix->stride + (x - pix->x)];
while (n--)
- {
- a += *list++;
- *p++ = a;
- }
+ *p++ = *alpha++ * SF;
}
fz_error *
diff --git a/render/rendertext.c b/render/rendertext.c
index cc181657..81afeafa 100644
--- a/render/rendertext.c
+++ b/render/rendertext.c
@@ -33,13 +33,13 @@ static void blitcolorglyph(fz_pixmap *out, fz_glyph *gl, int xo, int yo, fz_rend
{
for (sx = 0; sx < gl->w; sx++)
{
- dx = xo + sx + gl->lsb - out->x;
dy = yo - sy + gl->top - out->y;
+ if (dy < 0) continue;
+ if (dy >= out->h) break;
+ dx = xo + sx + gl->lsb - out->x;
if (dx < 0) continue;
- if (dy < 0) continue;
- if (dx >= out->w) continue;
- if (dy >= out->h) continue;
+ if (dx >= out->w) break;
sa = gl->bitmap[sx + sy * gl->w];
ssa = 255 - sa;
diff --git a/render/scanconv.c b/render/scanconv.c
index b2689ae2..db859d1f 100644
--- a/render/scanconv.c
+++ b/render/scanconv.c
@@ -1,7 +1,7 @@
#include <fitz.h>
static inline void
-addspan(short *list, int x0, int x1, int xofs, int hs)
+addspan(unsigned char *list, int x0, int x1, int xofs, int hs)
{
int x0pix, x0sub;
int x1pix, x1sub;
@@ -34,7 +34,7 @@ addspan(short *list, int x0, int x1, int xofs, int hs)
}
static inline void
-nonzerowinding(fz_ael *ael, short *list, int xofs, int hs)
+nonzerowinding(fz_ael *ael, unsigned char *list, int xofs, int hs)
{
int winding = 0;
int x = 0;
@@ -50,7 +50,7 @@ nonzerowinding(fz_ael *ael, short *list, int xofs, int hs)
}
static inline void
-evenodd(fz_ael *ael, short *list, int xofs, int hs)
+evenodd(fz_ael *ael, unsigned char *list, int xofs, int hs)
{
int even = 0;
int x = 0;
@@ -65,22 +65,22 @@ evenodd(fz_ael *ael, short *list, int xofs, int hs)
}
}
-/*
-void
-fz_emitdeltas(short *list, int y, int xofs, int n)
+static void toalpha(unsigned char *list, int n)
{
int d = 0;
while (n--)
- d += *list++;
+ {
+ d += *list;
+ *list++ = d;
+ }
}
-*/
fz_error *
fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill, int y0, int y1,
- void (*blitfunc)(int,int,int,short*,void*), void *blitdata)
+ void (*blitfunc)(int,int,int,unsigned char*,void*), void *blitdata)
{
fz_error *error;
- short *deltas;
+ unsigned char *deltas;
int y, e;
int yd, yc;
@@ -96,11 +96,11 @@ fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill, int y0, int y1,
if (gel->len == 0)
return nil;
- deltas = fz_malloc(sizeof(short) * (xmax - xmin + 1));
+ deltas = fz_malloc(xmax - xmin + 1);
if (!deltas)
return fz_outofmem;
- memset(deltas, 0, sizeof(short) * (xmax - xmin + 1));
+ memset(deltas, 0, xmax - xmin + 1);
e = 0;
y = gel->edges[0].y;
@@ -113,8 +113,9 @@ fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill, int y0, int y1,
if (yc != yd) {
if (yd >= y0 && yd < y1)
{
+ toalpha(deltas, xmax - xmin);
blitfunc(yd, xmin, xmax - xmin, deltas, blitdata);
- memset(deltas, 0, sizeof(short) * (xmax - xmin + 1));
+ memset(deltas, 0, xmax - xmin + 1);
}
}
yd = yc;
@@ -142,7 +143,10 @@ fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill, int y0, int y1,
}
if (yd >= y0 && yd < y1)
+ {
+ toalpha(deltas, xmax - xmin);
blitfunc(yd, xmin, xmax - xmin, deltas, blitdata);
+ }
fz_free(deltas);
return nil;