summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2004-11-22 09:18:56 +0100
committerTor Andersson <tor@ghostscript.com>2004-11-22 09:18:56 +0100
commite092458f4403f1424d8fd1f5ec194880a05c3362 (patch)
treec9ae89916a56c90857766ffab9abf36a13332e40
parent459f682af16a1982745f2c40a368c1a54059b23e (diff)
downloadmupdf-e092458f4403f1424d8fd1f5ec194880a05c3362.tar.xz
fixed bugs in new render loop
-rw-r--r--mupdf/fontagl.c2
-rw-r--r--mupdf/image1.c3
-rw-r--r--render/rastnone.c65
-rw-r--r--render/render.c45
-rw-r--r--render/renderimage.c326
-rw-r--r--render/renderpath.c142
-rw-r--r--render/rendertext.c147
7 files changed, 64 insertions, 666 deletions
diff --git a/mupdf/fontagl.c b/mupdf/fontagl.c
index 2b083313..de4156a2 100644
--- a/mupdf/fontagl.c
+++ b/mupdf/fontagl.c
@@ -15,7 +15,7 @@
int pdf_lookupagl(char *name)
{
int l = 0;
- int r = pdf_adobeglyphlen;
+ int r = pdf_adobeglyphlen - 1;
while (l <= r)
{
diff --git a/mupdf/image1.c b/mupdf/image1.c
index 90fb4862..295af901 100644
--- a/mupdf/image1.c
+++ b/mupdf/image1.c
@@ -41,6 +41,7 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
if (ismask)
{
+ img->super.cs = nil;
img->super.n = 0;
img->super.a = 1;
img->bpc = 1;
@@ -48,8 +49,6 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
if (cs)
{
- img->super.cs = nil;
-
if (fz_isname(cs))
{
fz_obj *csd = fz_dictgets(rdb, "ColorSpace");
diff --git a/render/rastnone.c b/render/rastnone.c
index 2a575ccb..2af45882 100644
--- a/render/rastnone.c
+++ b/render/rastnone.c
@@ -1,5 +1,7 @@
#include <fitz.h>
+/* XXX: half of these funcs are totally wrong. fix! */
+
typedef unsigned char byte;
/*
@@ -111,8 +113,8 @@ static inline int samplemsk(byte *s, int w, int h, int u, int v)
{
int ui = u >> 16;
int vi = v >> 16;
- int ud = u & 0xFF;
- int vd = v & 0xFF;
+ int ud = u & 0xFFFF;
+ int vd = v & 0xFFFF;
int a = getmsk(s, w, h, ui, vi);
int b = getmsk(s, w, h, ui+1, vi);
int c = getmsk(s, w, h, ui, vi+1);
@@ -144,8 +146,8 @@ static inline void sampleargb(byte *s, int w, int h, int u, int v, byte *abcd)
byte cd[4];
int ui = u >> 16;
int vi = v >> 16;
- int ud = u & 0xFF;
- int vd = v & 0xFF;
+ int ud = u & 0xFFFF;
+ int vd = v & 0xFFFF;
byte *a = getargb(s, w, h, ui, vi);
byte *b = getargb(s, w, h, ui+1, vi);
byte *c = getargb(s, w, h, ui, vi+1);
@@ -186,7 +188,7 @@ static void example(PSRC, PDST, PMSK, PCTM)
}
#endif
-#define BLOOP \
+#define BEGLOOP \
while (ny--) \
{ \
byte *dst = dst0; \
@@ -195,13 +197,13 @@ static void example(PSRC, PDST, PMSK, PCTM)
int nx = nx0; \
while (nx--)
-#define ELOOP \
+#define ENDLOOP \
u0 += fc; \
v0 += fd; \
dst0 += dstw; \
}
-#define BLOOPM \
+#define BEGLOOPM \
while (ny--) \
{ \
byte *dst = dst0; \
@@ -211,7 +213,7 @@ static void example(PSRC, PDST, PMSK, PCTM)
int nx = nx0; \
while (nx--)
-#define ELOOPM \
+#define ENDLOOPM \
u0 += fc; \
v0 += fd; \
dst0 += dstw; \
@@ -220,31 +222,31 @@ static void example(PSRC, PDST, PMSK, PCTM)
static void img1_g(PSRC, PDST, PCTM)
{
- BLOOP
+ BEGLOOP
{
dst[0] = samplemsk(src, w, h, u, v);
dst ++;
u += fa;
v += fb;
}
- ELOOP
+ ENDLOOP
}
static void img1_i1(PSRC, PDST, PCTM)
{
- BLOOP
+ BEGLOOP
{
dst[0] = fz_mul255(dst[0], samplemsk(src, w, h, u, v));
dst ++;
u += fa;
v += fb;
}
- ELOOP
+ ENDLOOP
}
static void img1_o1(PSRC, PDST, PCTM)
{
- BLOOP
+ BEGLOOP
{
byte sa = samplemsk(src, w, h, u, v);
dst[0] = sa + fz_mul255(dst[0], 255 - sa);
@@ -252,12 +254,12 @@ static void img1_o1(PSRC, PDST, PCTM)
u += fa;
v += fb;
}
- ELOOP
+ ENDLOOP
}
static void img1_i1o1(PSRC, PDST, PMSK, PCTM)
{
- BLOOPM
+ BEGLOOPM
{
byte sa = fz_mul255(msk[0], samplemsk(src, w, h, u, v));
dst[0] = sa + fz_mul255(dst[0], 255 - sa);
@@ -266,12 +268,12 @@ static void img1_i1o1(PSRC, PDST, PMSK, PCTM)
u += fa;
v += fb;
}
- ELOOPM
+ ENDLOOPM
}
static void img1_o4w3(PSRC, PDST, PCTM, byte *rgb)
{
- BLOOP
+ BEGLOOP
{
byte sa = samplemsk(src, w, h, u, v);
byte ssa = 255 - sa;
@@ -283,12 +285,12 @@ static void img1_o4w3(PSRC, PDST, PCTM, byte *rgb)
u += fa;
v += fb;
}
- ELOOP
+ ENDLOOP
}
static void img1_i1o4w3(PSRC, PDST, PMSK, PCTM, byte *rgb)
{
- BLOOPM
+ BEGLOOPM
{
byte sa = fz_mul255(msk[0], samplemsk(src, w, h, u, v));
byte ssa = 255 - sa;
@@ -301,43 +303,44 @@ static void img1_i1o4w3(PSRC, PDST, PMSK, PCTM, byte *rgb)
u += fa;
v += fb;
}
- ELOOPM
+ ENDLOOPM
}
static void img4_g(PSRC, PDST, PCTM)
{
- BLOOP
+ BEGLOOP
{
sampleargb(src, w, h, u, v, dst);
dst += 4;
u += fa;
v += fb;
}
- ELOOP
+ ENDLOOP
}
static void img4_o4(PSRC, PDST, PCTM)
{
byte argb[4];
- BLOOP
+ BEGLOOP
{
sampleargb(src, w, h, u, v, argb);
- byte ssa = 255 - argb[0];
- dst[0] = argb[0] + fz_mul255(dst[0], ssa);
- dst[1] = argb[1] + fz_mul255((short)dst[1] - argb[1], ssa);
- dst[2] = argb[2] + fz_mul255((short)dst[2] - argb[2], ssa);
- dst[3] = argb[3] + fz_mul255((short)dst[3] - argb[3], ssa);
+ byte sa = argb[0];
+ byte ssa = 255 - sa;
+ dst[0] = sa + fz_mul255(dst[0], ssa);
+ dst[1] = argb[1] + fz_mul255(dst[1], ssa);
+ dst[2] = argb[2] + fz_mul255(dst[2], ssa);
+ dst[3] = argb[3] + fz_mul255(dst[3], ssa);
dst += 4;
u += fa;
v += fb;
}
- ELOOP
+ ENDLOOP
}
static void img4_i1o4(PSRC, PDST, PMSK, PCTM)
{
byte argb[4];
- BLOOPM
+ BEGLOOPM
{
sampleargb(src, w, h, u, v, argb);
byte sa = fz_mul255(msk[0], argb[0]);
@@ -351,7 +354,7 @@ static void img4_i1o4(PSRC, PDST, PMSK, PCTM)
u += fa;
v += fb;
}
- ELOOPM
+ ENDLOOPM
}
/*
diff --git a/render/render.c b/render/render.c
index 13787ce4..6aee9c8a 100644
--- a/render/render.c
+++ b/render/render.c
@@ -79,14 +79,14 @@ static fz_error *
rendertransform(fz_renderer *gc, fz_transformnode *transform, fz_matrix ctm)
{
fz_error *error;
-printf("transform [%g %g %g %g %g %g]\n",
-transform->m.a, transform->m.b,
-transform->m.c, transform->m.d,
-transform->m.e, transform->m.f);
-puts("{");
+//printf("transform [%g %g %g %g %g %g]\n",
+//transform->m.a, transform->m.b,
+//transform->m.c, transform->m.d,
+//transform->m.e, transform->m.f);
+//puts("{");
ctm = fz_concat(transform->m, ctm);
error = rendernode(gc, transform->super.first, ctm);
-puts("}");
+//puts("}");
return error;
}
@@ -334,10 +334,10 @@ rendertext(fz_renderer *gc, fz_textnode *text, fz_matrix ctm)
tbox = fz_roundrect(fz_boundnode((fz_node*)text, ctm));
clip = fz_intersectirects(gc->clip, tbox);
-printf("text %s n=%d [%g %g %g %g] clip[%d %d %d %d]\n",
- text->font->name, text->len,
- text->trm.a, text->trm.b, text->trm.c, text->trm.d,
- clip.min.x, clip.min.y, clip.max.x, clip.max.y);
+//printf("text %s n=%d [%g %g %g %g] clip[%d %d %d %d]\n",
+//text->font->name, text->len,
+//text->trm.a, text->trm.b, text->trm.c, text->trm.d,
+//clip.min.x, clip.min.y, clip.max.x, clip.max.y);
if (clip.max.x <= clip.min.x)
return nil;
@@ -423,8 +423,6 @@ renderimage(fz_renderer *gc, fz_imagenode *node, fz_matrix ctm)
int x0, y0;
int w, h;
- /* TODO: check validity of xxx->n + 1 */
-
printf("renderimage %dx%d %d+%d %s\n", image->w, image->h, image->n, image->a, image->cs?image->cs->name:"(nil)");
bbox = fz_roundrect(fz_boundnode((fz_node*)node, ctm));
@@ -439,13 +437,20 @@ printf("renderimage %dx%d %d+%d %s\n", image->w, image->h, image->n, image->a, i
printf(" load image\n");
error = fz_newpixmap(&tile, 0, 0, image->w, image->h, image->n + 1);
+ if (error)
+ return error;
+
error = image->loadtile(image, tile);
+ if (error)
+ goto cleanup;
if (dx != 1 || dy != 1)
{
printf(" scale image 1/%d 1/%d\n", dx, dy);
fz_pixmap *temp;
error = fz_scalepixmap(&temp, tile, dx, dy);
+ if (error)
+ goto cleanup;
fz_droppixmap(tile);
tile = temp;
}
@@ -455,6 +460,8 @@ printf(" scale image 1/%d 1/%d\n", dx, dy);
fz_pixmap *temp;
printf(" convert from %s to %s\n", image->cs->name, gc->model->name);
error = fz_newpixmap(&temp, tile->x, tile->y, tile->w, tile->h, gc->model->n + 1);
+ if (error)
+ goto cleanup;
fz_convertpixmap(image->cs, tile, gc->model, temp);
fz_droppixmap(tile);
tile = temp;
@@ -488,7 +495,8 @@ printf(" fnone %d x %d\n", w, h);
error = fz_newpixmapwithrect(&gc->dest, clip, gc->model->n + 1);
else
error = fz_newpixmapwithrect(&gc->dest, clip, 1);
- fz_clearpixmap(gc->dest);
+ if (error)
+ goto cleanup;
if (image->cs)
gc->rast.img4_g(
@@ -536,8 +544,11 @@ printf(" fover+rgb %d x %d\n", w, h);
}
fz_droppixmap(tile);
-
return nil;
+
+cleanup:
+ fz_droppixmap(tile);
+ return error;
}
/*
@@ -551,11 +562,11 @@ renderover(fz_renderer *gc, fz_overnode *over, fz_matrix ctm)
fz_node *child;
int cluster = 0;;
-printf("over\n{\n");
+//printf("over\n{\n");
if (!gc->over)
{
-printf(" alloc dest!\n");
+//printf(" alloc dest!\n");
error = fz_newpixmapwithrect(&gc->over, gc->clip, gc->maskonly ? 1 : 4);
if (error)
return error;
@@ -582,7 +593,7 @@ printf(" alloc dest!\n");
gc->over = nil;
}
-printf("}\n");
+//printf("}\n");
return nil;
}
diff --git a/render/renderimage.c b/render/renderimage.c
deleted file mode 100644
index fb0dcb68..00000000
--- a/render/renderimage.c
+++ /dev/null
@@ -1,326 +0,0 @@
-#include <fitz.h>
-
-#define LERP(a,b,t) (a + (((b - a) * t) >> 16))
-
-static inline int getcomp(fz_pixmap *pix, int u, int v, int k)
-{
- if (u < 0 || u >= pix->w)
- return 0;
- if (v < 0 || v >= pix->h)
- return 0;
- return pix->samples[ (v * pix->w + u) * pix->n + k ];
-}
-
-static inline int sampleimage(fz_pixmap *pix, int u, int v, int k)
-{
- int ui = u >> 16;
- int vi = v >> 16;
- int ud = u & 0xFFFF;
- int vd = v & 0xFFFF;
-
- int a = getcomp(pix, ui, vi, k);
- int b = getcomp(pix, ui + 1, vi, k);
- int c = getcomp(pix, ui, vi + 1, k);
- int d = getcomp(pix, ui + 1, vi + 1, k);
-
- int ab = LERP(a, b, ud);
- int cd = LERP(c, d, ud);
- return LERP(ab, cd, vd);
-}
-
-static inline void
-sgeneral(fz_matrix *invmat, fz_pixmap *dst, fz_pixmap *src, int y, int x0, int x1)
-{
- unsigned char *d;
- int k, n;
-
- int u = (invmat->a * (x0+0.5) + invmat->c * (y+0.5) + invmat->e) * 65536;
- int v = (invmat->b * (x0+0.5) + invmat->d * (y+0.5) + invmat->f) * 65536;
- int du = invmat->a * 65536;
- int dv = invmat->b * 65536;
-
- u -= 0.5 * 65536;
- v -= 0.5 * 65536;
-
- n = x1 - x0 + 1;
- d = dst->samples + ((y - dst->y) * dst->w + (x0 - dst->x)) * dst->n;
-
- while (n--)
- {
- for (k = 0; k < src->n; k++)
- *d++ = sampleimage(src, u, v, k);
- u += du;
- v += dv;
- }
-}
-
-static inline void
-srgbover(fz_matrix *invmat, fz_pixmap *dst, fz_pixmap *src, int y, int x0, int x1)
-{
- unsigned char *d;
- int x;
-
- int u = (invmat->a * (x0+0.5) + invmat->c * (y+0.5) + invmat->e) * 65536;
- int v = (invmat->b * (x0+0.5) + invmat->d * (y+0.5) + invmat->f) * 65536;
- int du = invmat->a * 65536;
- int dv = invmat->b * 65536;
-
- u -= 0.5 * 65536;
- v -= 0.5 * 65536;
-
- d = dst->samples + ((y - dst->y) * dst->w + (x0 - dst->x)) * dst->n;
-
- for (x = x0; x <= x1; x++)
- {
- int sa = sampleimage(src, u, v, 0);
- int sr = sampleimage(src, u, v, 1);
- int sg = sampleimage(src, u, v, 2);
- int sb = sampleimage(src, u, v, 3);
- int ssa = 255 - sa;
- d[0] = sa + fz_mul255(d[0], ssa);
- d[1] = sr + fz_mul255(d[1], ssa);
- d[2] = sg + fz_mul255(d[2], ssa);
- d[3] = sb + fz_mul255(d[3], ssa);
- d += 4;
- u += du;
- v += dv;
- }
-}
-
-static inline void
-smaskover(fz_matrix *invmat, fz_pixmap *dst, fz_pixmap *src, int y, int x0, int x1)
-{
- unsigned char *d;
- int x;
-
- int u = (invmat->a * (x0+0.5) + invmat->c * (y+0.5) + invmat->e) * 65536;
- int v = (invmat->b * (x0+0.5) + invmat->d * (y+0.5) + invmat->f) * 65536;
- int du = invmat->a * 65536;
- int dv = invmat->b * 65536;
-
- u -= 0.5 * 65536;
- v -= 0.5 * 65536;
-
- d = dst->samples + ((y - dst->y) * dst->w + (x0 - dst->x)) * dst->n;
-
- for (x = x0; x <= x1; x++)
- {
- int sa = sampleimage(src, u, v, 0);
- d[0] = sa + fz_mul255(d[0], 255 - sa);
- d += 1;
- u += du;
- v += dv;
- }
-}
-
-static inline void
-smaskrgbover(fz_matrix *invmat, fz_pixmap *dst, fz_pixmap *src, int y, int x0, int x1, fz_renderer *gc)
-{
- unsigned char r = gc->r;
- unsigned char g = gc->g;
- unsigned char b = gc->b;
- unsigned char *d;
- int x;
-
- int u = (invmat->a * (x0+0.5) + invmat->c * (y+0.5) + invmat->e) * 65536;
- int v = (invmat->b * (x0+0.5) + invmat->d * (y+0.5) + invmat->f) * 65536;
- int du = invmat->a * 65536;
- int dv = invmat->b * 65536;
-
- u -= 0.5 * 65536;
- v -= 0.5 * 65536;
-
- d = dst->samples + ((y - dst->y) * dst->w + (x0 - dst->x)) * dst->n;
-
- for (x = x0; x <= x1; x++)
- {
- int sa = sampleimage(src, u, v, 0);
- int ssa = 255 - sa;
- d[0] = sa + fz_mul255(d[0], ssa);
- d[1] = fz_mul255(r, sa) + fz_mul255(d[1], ssa);
- d[2] = fz_mul255(g, sa) + fz_mul255(d[2], ssa);
- d[3] = fz_mul255(b, sa) + fz_mul255(d[3], ssa);
- d += 4;
- u += du;
- v += dv;
- }
-}
-
-static fz_error *
-drawtile(fz_renderer *gc, fz_pixmap *out, fz_pixmap *tile, fz_matrix ctm, int over)
-{
- static const fz_point rect[4] = { {0, 0}, {0, 1}, {1, 1}, {1, 0} };
- fz_matrix imgmat;
- fz_matrix invmat;
- fz_point v[4];
- int y0, y1, x0, x1, y;
- int i;
-
- 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]);
-
- y0 = fz_floor(MIN4(v[0].y, v[1].y, v[2].y, v[3].y));
- y1 = fz_ceil(MAX4(v[0].y, v[1].y, v[2].y, v[3].y));
- x0 = fz_floor(MIN4(v[0].x, v[1].x, v[2].x, v[3].x));
- x1 = fz_ceil(MAX4(v[0].x, v[1].x, v[2].x, v[3].x));
-
- y0 = CLAMP(y0, out->y, out->y + out->h - 1);
- y1 = CLAMP(y1, out->y, out->y + out->h - 1);
- x0 = CLAMP(x0, out->x, out->x + out->w - 1);
- x1 = CLAMP(x1, out->x, out->x + out->w - 1);
-
- for (y = y0; y <= y1; y++)
- {
- if (over && tile->n == 4)
- srgbover(&invmat, out, tile, y, x0, x1);
- else if (over && tile->n == 1 && gc->hasrgb)
- smaskrgbover(&invmat, out, tile, y, x0, x1, gc);
- else if (over && tile->n == 1 && !gc->hasrgb)
- smaskover(&invmat, out, tile, y, x0, x1);
- else
- sgeneral(&invmat, out, tile, y, x0, x1);
- }
-
- return nil;
-}
-
-fz_error *
-fz_renderimage(fz_renderer *gc, fz_imagenode *node, fz_matrix ctm)
-{
- fz_error *error;
- fz_pixmap *tile1;
- fz_pixmap *tile2;
- fz_pixmap *tile3;
- fz_image *image = node->image;
- fz_colorspace *cs = image->cs;
- int w = image->w;
- int h = image->h;
- int n = image->n;
- int a = image->a;
- int dx, dy;
- fz_rect bbox;
- fz_irect r;
-
- float sx = sqrt(ctm.a * ctm.a + ctm.b * ctm.b);
- float sy = sqrt(ctm.c * ctm.c + ctm.d * ctm.d);
-
- dx = 1;
- while ( ( (w + dx - 1) / dx ) / sx > 2.0 && (w+dx-1)/dx > 1)
- dx++;
-
- dy = 1;
- while ( ( (h + dy - 1) / dy ) / sy > 2.0 && (h+dy-1)/dy > 1)
- dy++;
-
-printf("renderimage n=%d a=%d s=%gx%g/%dx%d d=%d,%d\n", n, a, sx, sy, w, h, dx, dy);
-
- error = fz_newpixmap(&tile1, 0, 0, w, h, n + 1);
-
-printf(" load tile %d x %d\n", w, h);
- error = image->loadtile(image, tile1);
-
- if (dx != 1 || dy != 1)
- {
-printf(" scale tile 1/%d x 1/%d\n", dx, dy);
- error = fz_scalepixmap(&tile2, tile1, dx, dy);
- fz_droppixmap(tile1);
- }
- else
- tile2 = tile1;
-
- bbox.min.x = 0;
- bbox.min.y = 0;
- bbox.max.x = 1;
- bbox.max.y = 1;
- bbox = fz_transformaabb(ctm, bbox);
- r = fz_intersectirects(fz_roundrect(bbox), gc->clip);
-
- /* render image mask */
- if (n == 0 && a == 1)
- {
- if (gc->acc && !gc->model)
- {
-printf(" draw image mask over\n");
- error = drawtile(gc, gc->acc, tile2, ctm, 1);
- }
- else if (gc->acc && gc->hasrgb)
- {
-printf(" draw image mask + color over\n");
- error = drawtile(gc, gc->acc, tile2, ctm, 1);
- }
- else
- {
-printf(" draw image mask\n");
- error = fz_newpixmap(&gc->tmp, r.min.x, r.min.y, r.max.x - r.min.x, r.max.y - r.min.y, 1);
- fz_clearpixmap(gc->tmp);
- error = drawtile(gc, gc->tmp, tile2, ctm, 0);
- }
- }
-
- /* render rgb over */
- else if (gc->acc)
- {
- if (n == 3 && a == 0)
- {
-printf(" draw image rgb over\n");
- error = drawtile(gc, gc->acc, tile2, ctm, 1);
- }
-
- /* render generic image */
- else
- {
-printf(" draw image rgb over after cs transform\n");
- error = fz_newpixmap(&tile3, tile2->x, tile2->y, tile2->w, tile2->h, gc->model->n + 1);
- fz_convertpixmap(cs, tile2, gc->model, tile3);
- error = drawtile(gc, gc->acc, tile3, ctm, 1);
- fz_droppixmap(tile3);
- }
- }
-
- /* render generic image */
- else
- {
-printf(" draw image after cs transform\n");
- error = fz_newpixmap(&tile3, tile2->x, tile2->y, tile2->w, tile2->h, gc->model->n + 1);
- fz_convertpixmap(cs, tile2, gc->model, tile3);
- error = fz_newpixmap(&gc->tmp, r.min.x, r.min.y,
- r.max.x - r.min.x, r.max.y - r.min.y, gc->model->n + 1);
- fz_clearpixmap(gc->tmp);
- error = drawtile(gc, gc->tmp, tile3, ctm, 0);
- fz_droppixmap(tile3);
- }
-
- fz_droppixmap(tile2);
- return nil;
-}
-
-fz_error *
-fz_rendercolorimage(fz_renderer *gc, fz_imagenode *node, fz_colornode *color, fz_matrix ctm)
-{
- fz_error *error;
- float rgb[3];
-
- assert(gc->model);
-
- fz_convertcolor(color->cs, color->samples, gc->model, rgb);
- gc->r = rgb[0] * 255;
- gc->g = rgb[1] * 255;
- gc->b = rgb[2] * 255;
-
- gc->hasrgb = 1;
-
- error = fz_renderimage(gc, node, ctm);
-
- gc->hasrgb = 0;
-
- return error;
-}
-
diff --git a/render/renderpath.c b/render/renderpath.c
deleted file mode 100644
index 05c39c8b..00000000
--- a/render/renderpath.c
+++ /dev/null
@@ -1,142 +0,0 @@
-#include <fitz.h>
-
-enum { HS = 17, VS = 15, SF = 1 };
-
-static fz_error *pathtogel(fz_gel *gel, fz_pathnode *path, fz_matrix ctm)
-{
- float flatness = 0.3 / sqrt(fabs(ctm.a * ctm.d - ctm.b * ctm.c));
- if (flatness < 0.1)
- flatness = 0.1;
- if (path->paint == FZ_STROKE)
- {
- if (path->dash)
- return fz_dashpath(gel, path, ctm, flatness);
- return fz_strokepath(gel, path, ctm, flatness);
- }
- return fz_fillpath(gel, path, ctm, flatness);
-}
-
-static void blitcolorspan(int y, int x, int n, unsigned char *alpha, void *userdata)
-{
- fz_renderer *gc = userdata;
- fz_pixmap *pix = gc->acc;
- unsigned char sa;
- unsigned char ssa;
- unsigned char *p;
- unsigned char r = gc->r;
- unsigned char g = gc->g;
- unsigned char b = gc->b;
-
- if (x < pix->x)
- {
- alpha += pix->x - x;
- n -= pix->x - x;
- x = pix->x;
- }
-
- if (x + n > pix->x + pix->w)
- n = pix->x + pix->w - x;
-
- if (n < 0)
- return;
-
- p = pix->samples + ((y - pix->y) * pix->w + (x - pix->x)) * pix->n;
-
- while (n--)
- {
- sa = *alpha++ * SF;
- ssa = 255 - sa;
-
- p[0] = sa + fz_mul255(p[0], ssa);
- p[1] = fz_mul255(r, sa) + fz_mul255(p[1], ssa);
- p[2] = fz_mul255(g, sa) + fz_mul255(p[2], ssa);
- p[3] = fz_mul255(b, sa) + fz_mul255(p[3], ssa);
-
- p += 4;
- }
-}
-
-static void blitalphaspan(int y, int x, int n, unsigned char *alpha, void *userdata)
-{
- fz_pixmap *pix = userdata;
- unsigned char *p;
-
- if (x < pix->x)
- {
- alpha += pix->x - x;
- n -= pix->x - x;
- x = pix->x;
- }
-
- if (x + n > pix->x + pix->w)
- n = pix->x + pix->w - x;
-
- if (n < 0)
- return;
-
- p = pix->samples + (y - pix->y) * pix->w + (x - pix->x);
- while (n--)
- *p++ = *alpha++ * SF;
-}
-
-fz_error *
-fz_rendercolorpath(fz_renderer *gc, fz_pathnode *path, fz_colornode *color, fz_matrix ctm)
-{
- fz_error *error;
- float rgb[3];
-
- fz_resetgel(gc->gel, HS, VS);
-
- error = pathtogel(gc->gel, path, ctm);
- if (error)
- return error;
-
- fz_sortgel(gc->gel);
-
- fz_convertcolor(color->cs, color->samples, gc->model, rgb);
- gc->r = rgb[0] * 255;
- gc->g = rgb[1] * 255;
- gc->b = rgb[2] * 255;
-
- fz_scanconvert(gc->gel, gc->ael,
- path->paint == FZ_EOFILL,
- gc->clip.min.y, gc->clip.max.y,
- blitcolorspan, gc);
-
- return nil;
-}
-
-fz_error *
-fz_renderpath(fz_renderer *gc, fz_pathnode *path, fz_matrix ctm)
-{
- fz_error *error;
- fz_irect bbox;
-
- fz_resetgel(gc->gel, HS, VS);
-
- error = pathtogel(gc->gel, path, ctm);
- if (error)
- return error;
-
- fz_sortgel(gc->gel);
-
- bbox = fz_boundgel(gc->gel);
- bbox = fz_intersectirects(bbox, gc->clip);
-
- error = fz_newpixmap(&gc->tmp,
- bbox.min.x, bbox.min.y,
- bbox.max.x - bbox.min.x,
- bbox.max.y - bbox.min.y, 1);
- if (error)
- return error;
-
- fz_clearpixmap(gc->tmp);
-
- fz_scanconvert(gc->gel, gc->ael,
- path->paint == FZ_EOFILL,
- gc->clip.min.y, gc->clip.max.y,
- blitalphaspan, gc->tmp);
-
- return nil;
-}
-
diff --git a/render/rendertext.c b/render/rendertext.c
deleted file mode 100644
index 16345ce6..00000000
--- a/render/rendertext.c
+++ /dev/null
@@ -1,147 +0,0 @@
-#include <fitz.h>
-
-static void blitalphaglyph(fz_pixmap *out, fz_glyph *gl, int xo, int yo)
-{
- int sx, sy, dx, dy, a, b, c;
-
- for (sy = 0; sy < gl->h; sy++)
- {
- for (sx = 0; sx < gl->w; sx++)
- {
- dx = xo + sx + gl->lsb - out->x;
- dy = yo - sy + gl->top - out->y;
-
- if (dx < 0) continue;
- if (dy < 0) continue;
- if (dx >= out->w) continue;
- if (dy >= out->h) continue;
-
- a = gl->bitmap[sx + sy * gl->w];
- b = out->samples[dx + dy * out->w];
- c = a + fz_mul255(b, 255 - a);
- out->samples[dx + dy * out->w] = c;
- }
- }
-}
-
-static void blitcolorglyph(fz_pixmap *out, fz_glyph *gl, int xo, int yo, fz_renderer *gc)
-{
- int sx, sy, dx, dy, sa, ssa;
- unsigned char *p;
-
- for (sy = 0; sy < gl->h; sy++)
- {
- for (sx = 0; sx < gl->w; sx++)
- {
- 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 (dx >= out->w) break;
-
- sa = gl->bitmap[sx + sy * gl->w];
- ssa = 255 - sa;
-
- p = out->samples + dx * 4 + dy * out->w * out->n;
- p[0] = sa + fz_mul255(ssa, p[0]);
- p[1] = fz_mul255(gc->r, sa) + fz_mul255(p[1], ssa);
- p[2] = fz_mul255(gc->g, sa) + fz_mul255(p[2], ssa);
- p[3] = fz_mul255(gc->b, sa) + fz_mul255(p[3], ssa);
- }
- }
-}
-
-fz_error *
-fz_rendertext(fz_renderer *gc, fz_textnode *text, fz_matrix ctm)
-{
- fz_error *error;
- fz_glyph gl;
- float x, y;
- int g, i, ix, iy;
- fz_matrix tm, trm;
- fz_irect bbox;
-
- bbox = fz_roundrect(fz_boundnode((fz_node*)text, ctm));
- bbox = fz_intersectirects(gc->clip, bbox);
-
- error = fz_newpixmap(&gc->tmp,
- bbox.min.x, bbox.min.y,
- bbox.max.x - bbox.min.x, bbox.max.y - bbox.min.y, 1);
- if (error)
- return error;
-
- fz_clearpixmap(gc->tmp);
-
- tm = text->trm;
-
- for (i = 0; i < text->len; i++)
- {
- g = text->els[i].cid;
- x = text->els[i].x;
- y = text->els[i].y;
-
- tm.e = x;
- tm.f = y;
- trm = fz_concat(tm, ctm);
-
- ix = fz_floor(trm.e);
- iy = fz_floor(trm.f);
-
- trm.e = (trm.e - fz_floor(trm.e));
- trm.f = (trm.f - fz_floor(trm.f));
-
- error = fz_renderglyph(gc->cache, &gl, text->font, g, trm);
- if (error)
- return error;
-
- blitalphaglyph(gc->tmp, &gl, ix, iy);
- }
-
- return nil;
-}
-
-fz_error *
-fz_rendercolortext(fz_renderer *gc, fz_textnode *text, fz_colornode *color, fz_matrix ctm)
-{
- fz_error *error;
- fz_glyph gl;
- float x, y;
- int g, i, ix, iy;
- fz_matrix tm, trm;
- float rgb[3];
-
- fz_convertcolor(color->cs, color->samples, gc->model, rgb);
- gc->r = rgb[0] * 255;
- gc->g = rgb[1] * 255;
- gc->b = rgb[2] * 255;
-
- tm = text->trm;
-
- for (i = 0; i < text->len; i++)
- {
- g = text->els[i].cid;
- x = text->els[i].x;
- y = text->els[i].y;
-
- tm.e = x;
- tm.f = y;
- trm = fz_concat(tm, ctm);
-
- ix = fz_floor(trm.e);
- iy = fz_floor(trm.f);
-
- trm.e = (trm.e - fz_floor(trm.e));
- trm.f = (trm.f - fz_floor(trm.f));
-
- error = fz_renderglyph(gc->cache, &gl, text->font, g, trm);
- if (error)
- return error;
-
- blitcolorglyph(gc->acc, &gl, ix, iy, gc);
- }
-
- return nil;
-}
-