summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2004-10-22 10:04:22 +0200
committerTor Andersson <tor@ghostscript.com>2004-10-22 10:04:22 +0200
commit3dae7919da3ba4baf4dbe4c59dd9202b912d21e9 (patch)
tree67af833c4f6ac22cdbc724e04eb71a6065ea45ad /render
parentf49341e713b65b6e49862d02b38cd89c6a56c568 (diff)
downloadmupdf-3dae7919da3ba4baf4dbe4c59dd9202b912d21e9.tar.xz
image rendering
Diffstat (limited to 'render')
-rw-r--r--render/render.c2
-rw-r--r--render/renderimage.c93
-rw-r--r--render/stroke.c4
3 files changed, 84 insertions, 15 deletions
diff --git a/render/render.c b/render/render.c
index 29b51480..d77c0c9d 100644
--- a/render/render.c
+++ b/render/render.c
@@ -80,8 +80,6 @@ fz_rendercolor(fz_renderer *gc, fz_colornode *color, fz_matrix ctm)
gc->g = rgb[1] * 255;
gc->b = rgb[2] * 255;
-puts("render color");
-
error = fz_newpixmap(&gc->tmp, color->cs, gc->x, gc->y, gc->w, gc->h, 3, 1);
if (error)
return error;
diff --git a/render/renderimage.c b/render/renderimage.c
index 4c6ef816..15eda833 100644
--- a/render/renderimage.c
+++ b/render/renderimage.c
@@ -1,27 +1,91 @@
#include <fitz.h>
-static int cmpy(const void *a, const void *b)
+static inline void
+drawscan(fz_matrix *invmat, fz_pixmap *dst, fz_pixmap *src, int y, int x0, int x1)
{
- const fz_point *ap = a;
- const fz_point *bp = b;
- return bp->y - ap->y;
+ int x, k;
+ float u, v;
+ float du, dv;
+ fz_point p;
+ int iu, iv;
+ unsigned char c;
+
+ p.x = x0;
+ p.y = y;
+ p = fz_transformpoint(*invmat, p);
+
+ u = p.x;
+ v = p.y;
+ du = invmat->a;
+ dv = invmat->c;
+
+ for (x = x0; x < x1; x++)
+ {
+ iu = CLAMP((int)u, 0, src->w - 1);
+ iv = CLAMP((int)v, 0, src->h - 1);
+
+ for (k = 0; k < src->n + src->a; k++)
+ {
+ c = src->samples[ iv * src->stride + iu * (src->n+src->a) + k];
+ dst->samples[ y * dst->stride + x * (dst->n+dst->a) + k ] = c;
+ }
+
+ u += du;
+ v += dv;
+ }
}
-static void
-drawtile(fz_pixmap *out, fz_pixmap *tile, fz_matrix ctm)
+static fz_error *
+drawtile(fz_renderer *gc, fz_pixmap *out, fz_pixmap *tile, fz_matrix ctm)
{
static const fz_point rect[4] = { {0, 0}, {0, 1}, {1, 1}, {1, 0} };
+ fz_error *error;
+ fz_gel *gel = gc->gel;
+ fz_ael *ael = gc->ael;
+ fz_matrix imgmat;
+ fz_matrix invmat;
fz_point v[4];
- int i;
+ int i, e, y, x0, x1;
+
+ imgmat.a = 1.0 / tile->w;
+ imgmat.b = 0.0;
+ imgmat.c = 0.0;
+ imgmat.d = -1.0 / tile->h;
+ imgmat.e = 0.0;
+ imgmat.f = 1.0;
+ invmat = fz_invertmatrix(fz_concat(imgmat, ctm));
for (i = 0; i < 4; i++)
v[i] = fz_transformpoint(ctm, rect[i]);
+ fz_resetgel(gel, 1, 1);
+ fz_insertgel(gel, v[0].x, v[0].y, v[1].x, v[1].y);
+ fz_insertgel(gel, v[1].x, v[1].y, v[2].x, v[2].y);
+ fz_insertgel(gel, v[2].x, v[2].y, v[3].x, v[3].y);
+ fz_insertgel(gel, v[3].x, v[3].y, v[0].x, v[0].y);
+ fz_sortgel(gel);
- qsort(v, 4, sizeof(fz_point), cmpy);
+ e = 0;
+ y = gel->edges[0].y;
- for (i = 0; i < 4; i++)
- printf("%d: %g %g\n", i, v[i].x, v[i].y);
+ while (ael->len > 0 || e < gel->len)
+ {
+ error = fz_insertael(ael, gel, y, &e);
+ if (error)
+ return error;
+ x0 = ael->edges[0]->x;
+ x1 = ael->edges[ael->len - 1]->x;
+ drawscan(&invmat, out, tile, y, x0, x1);
+
+ fz_advanceael(ael);
+
+ if (ael->len > 0)
+ y ++;
+ else if (e < gel->len)
+ y = gel->edges[e].y;
+ }
+
+ return nil;
}
fz_error *
@@ -43,11 +107,18 @@ fz_renderimage(fz_renderer *gc, fz_imagenode *node, fz_matrix ctm)
if (error)
goto cleanup;
+ fz_clearpixmap(gc->tmp);
+
error = image->loadtile(image, tile);
if (error)
goto cleanup;
- drawtile(gc->tmp, tile, ctm);
+ error = drawtile(gc, gc->tmp, tile, ctm);
+ if (error)
+ goto cleanup;
+
+printf("loadtile "); fz_debugpixmap(tile); getchar();
+//printf("drawtile "); fz_debugpixmap(gc->tmp); getchar();
fz_freepixmap(tile);
return nil;
diff --git a/render/stroke.c b/render/stroke.c
index cd4f5a13..2527e6ad 100644
--- a/render/stroke.c
+++ b/render/stroke.c
@@ -469,7 +469,7 @@ fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness)
s.linecap = path->linecap;
s.linejoin = path->linejoin;
- s.linewidth = path->linewidth;
+ s.linewidth = path->linewidth * 0.5;
s.miterlimit = path->miterlimit;
s.sn = 0;
s.bn = 0;
@@ -664,7 +664,7 @@ fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness)
s.linecap = path->linecap;
s.linejoin = path->linejoin;
- s.linewidth = path->linewidth;
+ s.linewidth = path->linewidth * 0.5;
s.miterlimit = path->miterlimit;
s.sn = 0;
s.bn = 0;