summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-02-09 02:14:34 +0100
committerTor Andersson <tor@ghostscript.com>2010-02-09 02:14:34 +0100
commitc96f530870d86d552007ca2e124fc3aa1f0824ac (patch)
tree66165c92397d03b84252c3b47e5a26c76ba4aafa
parent7234a549b69760b097da1985805911b338e2a5d4 (diff)
downloadmupdf-c96f530870d86d552007ca2e124fc3aa1f0824ac.tar.xz
Use fz_pixmap instead of fz_image and remove the subclassing in pdf_image.
-rw-r--r--apps/pdfapp.c2
-rw-r--r--apps/pdfdraw.c10
-rw-r--r--fitz/Jamfile1
-rw-r--r--fitz/dev_draw.c52
-rw-r--r--fitz/dev_trace.c10
-rw-r--r--fitz/fitz_base.h16
-rw-r--r--fitz/fitz_res.h24
-rw-r--r--fitz/res_image.c22
-rw-r--r--fitzdraw/imagescale.c99
-rw-r--r--fitzdraw/meshdraw.c4
-rw-r--r--fitzdraw/pixmap.c31
-rw-r--r--mupdf/mupdf.h17
-rw-r--r--mupdf/pdf_build.c36
-rw-r--r--mupdf/pdf_image.c139
-rw-r--r--mupdf/pdf_interpret.c8
-rw-r--r--mupdf/pdf_store.c4
16 files changed, 191 insertions, 284 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index c6bc64d1..1cdf425b 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -252,7 +252,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage)
ctm = pdfapp_viewctm(app);
bbox = fz_roundrect(fz_transformaabb(ctm, app->page->mediabox));
- app->image = fz_newpixmapwithrect(bbox, 4);
+ app->image = fz_newpixmapwithrect(pdf_devicergb, bbox);
fz_clearpixmap(app->image, 0xFF);
app->page->contents->rp = app->page->contents->bp;
dev = fz_newdrawdevice(pdf_devicergb, app->image);
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index 94d2cf6a..44957dc2 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -206,7 +206,7 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *
write(fd, pnmhdr, strlen(pnmhdr));
}
- pix = fz_newpixmap(bbox.x0, bbox.y0, w, bh, 4);
+ pix = fz_newpixmap(pdf_devicergb, bbox.x0, bbox.y0, w, bh);
fz_clearpixmap(pix, 0xFF);
memset(pix->samples, 0xff, pix->h * pix->w * pix->n);
@@ -225,7 +225,13 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *
printf("END.\n");
#endif
- fz_device *dev = fz_newdrawdevice(pdf_devicergb, pix);
+ fz_device *dev;
+
+// dev = fz_newtracedevice();
+// drawpage->contents->rp = drawpage->contents->bp;
+// pdf_runcontentstream(dev, ctm, 0, xref, drawpage->resources, drawpage->contents);
+
+ dev = fz_newdrawdevice(pdf_devicergb, pix);
drawpage->contents->rp = drawpage->contents->bp;
error = pdf_runcontentstream(dev, ctm, 0, xref, drawpage->resources, drawpage->contents);
if (error)
diff --git a/fitz/Jamfile b/fitz/Jamfile
index eed4187a..91e03d61 100644
--- a/fitz/Jamfile
+++ b/fitz/Jamfile
@@ -76,7 +76,6 @@ Library libfitz :
node_text.c
res_colorspace.c
res_font.c
- res_image.c
res_shade.c
dev_trace.c
dev_draw.c
diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c
index ceceb8e0..9a84faa2 100644
--- a/fitz/dev_draw.c
+++ b/fitz/dev_draw.c
@@ -215,8 +215,8 @@ void fz_drawclippath(void *user, fz_path *path)
bbox = fz_boundgel(dev->gel);
bbox = fz_intersectirects(bbox, clip);
- mask = fz_newpixmapwithrect(bbox, 1);
- dest = fz_newpixmapwithrect(bbox, 4);
+ mask = fz_newpixmapwithrect(nil, bbox);
+ dest = fz_newpixmapwithrect(dev->model, bbox);
memset(mask->samples, 0, mask->w * mask->h * mask->n);
memset(dest->samples, 0, dest->w * dest->h * dest->n);
@@ -362,8 +362,10 @@ void fz_drawdrawshade(void *user, fz_shade *shade, fz_matrix ctm)
clip.x1 = dev->dest->x + dev->dest->w;
clip.y1 = dev->dest->y + dev->dest->h;
clip = fz_intersectirects(clip, bbox);
+ if (fz_isemptyrect(clip))
+ return;
- temp = fz_newpixmapwithrect(clip, dev->model->n + 1);
+ temp = fz_newpixmapwithrect(dev->model, clip);
if (shade->usebackground)
{
@@ -387,6 +389,8 @@ void fz_drawdrawshade(void *user, fz_shade *shade, fz_matrix ctm)
fz_rendershade(shade, ctm, dev->model, temp);
blendover(temp, dev->dest);
+ fz_debugpixmap(dev->dest, "shade");
+
fz_freepixmap(temp);
}
@@ -410,15 +414,13 @@ calcimagescale(fz_matrix ctm, int w, int h, int *odx, int *ody)
*ody = dy;
}
-void fz_drawdrawimage(void *user, fz_image *image, fz_matrix ctm)
+void fz_drawdrawimage(void *user, fz_pixmap *image, fz_matrix ctm)
{
fz_drawdevice *dev = user;
- fz_error error;
fz_rect bounds;
fz_irect bbox;
fz_irect clip;
int dx, dy;
- fz_pixmap *tile;
fz_pixmap *temp;
fz_matrix imgmat;
fz_matrix invmat;
@@ -447,34 +449,23 @@ void fz_drawdrawimage(void *user, fz_image *image, fz_matrix ctm)
calcimagescale(ctm, image->w, image->h, &dx, &dy);
- tile = fz_newpixmap(0, 0, image->w, image->h, image->n + 1);
-
- error = image->loadtile(image, tile);
- if (error)
- {
- fz_catch(error, "cannot load image data");
- return;
- }
-
if (dx != 1 || dy != 1)
{
- temp = fz_scalepixmap(tile, dx, dy);
- fz_freepixmap(tile);
- tile = temp;
+ temp = fz_scalepixmap(image, dx, dy);
+ image = temp;
}
- if (image->cs && image->cs != dev->model)
+ if (image->colorspace && image->colorspace != dev->model)
{
- temp = fz_newpixmap(tile->x, tile->y, tile->w, tile->h, dev->model->n + 1);
- fz_convertpixmap(image->cs, tile, dev->model, temp);
- fz_freepixmap(tile);
- tile = temp;
+ temp = fz_newpixmap(dev->model, image->x, image->y, image->w, image->h);
+ fz_convertpixmap(image->colorspace, image, dev->model, temp);
+ image = temp;
}
- imgmat.a = 1.0 / tile->w;
+ imgmat.a = 1.0 / image->w;
imgmat.b = 0.0;
imgmat.c = 0.0;
- imgmat.d = -1.0 / tile->h;
+ imgmat.d = -1.0 / image->h;
imgmat.e = 0.0;
imgmat.f = 1.0;
invmat = fz_invertmatrix(fz_concat(imgmat, ctm));
@@ -495,11 +486,10 @@ void fz_drawdrawimage(void *user, fz_image *image, fz_matrix ctm)
#define PDST(p) p->samples + ((y0-p->y) * p->w + (x0-p->x)) * p->n, p->w * p->n
- if (image->cs)
- fz_img_4o4(tile->samples, tile->w, tile->h, PDST(dev->dest),
+ if (image->colorspace)
+ fz_img_4o4(image->samples, image->w, image->h, PDST(dev->dest),
u0, v0, fa, fb, fc, fd, w, h);
-
- fz_freepixmap(tile);
+ // else XXX
}
fz_device *fz_newdrawdevice(fz_colorspace *colorspace, fz_pixmap *dest)
@@ -513,6 +503,8 @@ fz_device *fz_newdrawdevice(fz_colorspace *colorspace, fz_pixmap *dest)
ddev->cliptop = 0;
fz_device *dev = fz_malloc(sizeof(fz_device));
+ memset(dev, 0, sizeof(fz_device));
+
dev->user = ddev;
dev->fillpath = fz_drawfillpath;
@@ -524,6 +516,8 @@ fz_device *fz_newdrawdevice(fz_colorspace *colorspace, fz_pixmap *dest)
dev->cliptext = fz_drawcliptext;
dev->ignoretext = fz_drawignoretext;
+// dev->fillimagemask = fz_drawfillimagemask;
+// dev->clipimagemask = fz_drawclipimagemask;
dev->drawimage = fz_drawdrawimage;
dev->drawshade = fz_drawdrawshade;
diff --git a/fitz/dev_trace.c b/fitz/dev_trace.c
index 4816bf10..f02aa035 100644
--- a/fitz/dev_trace.c
+++ b/fitz/dev_trace.c
@@ -8,7 +8,11 @@ static void fz_tracematrix(fz_matrix ctm)
static void fz_tracecolor(fz_colorspace *colorspace, float *color, float alpha)
{
- printf("... setcolor\n");
+ int i;
+ printf("/%s setcolorspace\n", colorspace->name);
+ for (i = 0; i < colorspace->n; i++)
+ printf("%g ", color[i]);
+ printf("setcolor\n");
printf("%g setalpha\n", alpha);
}
@@ -91,7 +95,7 @@ void fz_traceignoretext(void *user, fz_text *text)
printf("invisibletext\n");
}
-void fz_tracedrawimage(void *user, fz_image *image, fz_matrix ctm)
+void fz_tracedrawimage(void *user, fz_pixmap *image, fz_matrix ctm)
{
fz_tracematrix(ctm);
printf("drawimage\n");
@@ -111,6 +115,8 @@ void fz_tracepopclip(void *user)
fz_device *fz_newtracedevice(void)
{
fz_device *dev = fz_malloc(sizeof(fz_device));
+ memset(dev, 0, sizeof(dev));
+
dev->user = nil;
dev->fillpath = fz_tracefillpath;
diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h
index 67665204..8c683114 100644
--- a/fitz/fitz_base.h
+++ b/fitz/fitz_base.h
@@ -299,17 +299,23 @@ conversions and rescaling.
*/
typedef struct fz_pixmap_s fz_pixmap;
-typedef unsigned char fz_sample;
+typedef struct fz_colorspace_s fz_colorspace;
+
+extern fz_colorspace *pdf_devicegray;
+extern fz_colorspace *pdf_devicergb;
+extern fz_colorspace *pdf_devicecmyk;
+extern fz_colorspace *pdf_devicelab;
+extern fz_colorspace *pdf_devicepattern;
struct fz_pixmap_s
{
int x, y, w, h, n;
- fz_sample *samples;
+ fz_colorspace *colorspace;
+ unsigned char *samples;
};
-fz_pixmap * fz_newpixmapwithrect(fz_irect bbox, int n);
-fz_pixmap * fz_newpixmap(int x, int y, int w, int h, int n);
-fz_pixmap * fz_newpixmapcopy(fz_pixmap *old);
+fz_pixmap * fz_newpixmapwithrect(fz_colorspace *, fz_irect bbox);
+fz_pixmap * fz_newpixmap(fz_colorspace *, int x, int y, int w, int h);
void fz_debugpixmap(fz_pixmap *map, char *prefix);
void fz_clearpixmap(fz_pixmap *map, unsigned char value);
diff --git a/fitz/fitz_res.h b/fitz/fitz_res.h
index 64e796b7..27612008 100644
--- a/fitz/fitz_res.h
+++ b/fitz/fitz_res.h
@@ -5,9 +5,7 @@
typedef struct fz_path_s fz_path;
typedef struct fz_text_s fz_text;
typedef struct fz_font_s fz_font;
-typedef struct fz_image_s fz_image;
typedef struct fz_shade_s fz_shade;
-typedef struct fz_colorspace_s fz_colorspace;
typedef struct fz_device_s fz_device;
@@ -24,7 +22,9 @@ struct fz_device_s
void (*cliptext)(void *, fz_text *);
void (*ignoretext)(void *, fz_text *);
- void (*drawimage)(void *, fz_image *img, fz_matrix ctm);
+ void (*fillimagemask)(void *, fz_pixmap *img, fz_matrix ctm, fz_colorspace *, float *color);
+ void (*clipimagemask)(void *, fz_pixmap *img, fz_matrix ctm);
+ void (*drawimage)(void *, fz_pixmap *img, fz_matrix ctm);
void (*drawshade)(void *, fz_shade *shd, fz_matrix ctm);
void (*popclip)(void *);
@@ -238,24 +238,6 @@ void fz_debugfont(fz_font *font);
void fz_setfontbbox(fz_font *font, int xmin, int ymin, int xmax, int ymax);
/*
- * Images are a right mess now. Most of the code is in the pdf interpreter.
- */
-
-/* loadtile will fill a pixmap with the pixel samples. non-premultiplied alpha. */
-
-struct fz_image_s
-{
- int refs;
- fz_error (*loadtile)(fz_image*,fz_pixmap*);
- void (*freefunc)(fz_image*);
- fz_colorspace *cs;
- int w, h, n, a;
-};
-
-fz_image *fz_keepimage(fz_image *img);
-void fz_dropimage(fz_image *img);
-
-/*
* The shading code is in rough shape but the general architecture is sound.
*/
diff --git a/fitz/res_image.c b/fitz/res_image.c
deleted file mode 100644
index 8da98a72..00000000
--- a/fitz/res_image.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "fitz.h"
-
-fz_image *
-fz_keepimage(fz_image *image)
-{
- image->refs ++;
- return image;
-}
-
-void
-fz_dropimage(fz_image *image)
-{
- if (image && --image->refs == 0)
- {
- if (image->freefunc)
- image->freefunc(image);
- if (image->cs)
- fz_dropcolorspace(image->cs);
- fz_free(image);
- }
-}
-
diff --git a/fitzdraw/imagescale.c b/fitzdraw/imagescale.c
index 970b3468..b2a499b0 100644
--- a/fitzdraw/imagescale.c
+++ b/fitzdraw/imagescale.c
@@ -178,103 +178,6 @@ void (*fz_scol4)(byte *src, byte *dst, int w, int denom) = scol4;
void (*fz_scol5)(byte *src, byte *dst, int w, int denom) = scol5;
fz_pixmap *
-fz_newscaledpixmap(int w, int h, int n, int xdenom, int ydenom)
-{
- int ow = (w + xdenom - 1) / xdenom;
- int oh = (h + ydenom - 1) / ydenom;
- return fz_newpixmap(0, 0, ow, oh, n);
-}
-
-/* TODO: refactor */
-void
-fz_scalepixmaptile(fz_pixmap *dst, int xoffs, int yoffs, fz_pixmap *src, int xdenom, int ydenom)
-{
- unsigned char *buf;
- unsigned char *dstsamples;
- int y, iy, oy;
- int ow, oh, n;
- int remaining;
-
- void (*srowx)(byte *src, byte *dst, int w, int denom) = nil;
- void (*scolx)(byte *src, byte *dst, int w, int denom) = nil;
-
- ow = (src->w + xdenom - 1) / xdenom;
- oh = (src->h + ydenom - 1) / ydenom;
- xoffs /= xdenom;
- yoffs /= ydenom;
- n = src->n;
-
- assert(xoffs == 0); /* don't handle stride properly yet */
- assert(dst->n == n);
- assert(dst->w >= xoffs + ow && dst->h >= yoffs + oh);
-
- buf = fz_malloc(ow * n * ydenom);
-
- switch (n)
- {
- case 1: srowx = fz_srow1; scolx = fz_scol1; break;
- case 2: srowx = fz_srow2; scolx = fz_scol2; break;
- case 4: srowx = fz_srow4; scolx = fz_scol4; break;
- case 5: srowx = fz_srow5; scolx = fz_scol5; break;
- }
-
- dstsamples = dst->samples + (yoffs * dst->w + xoffs)*dst->n;
- if (srowx && scolx)
- {
- for (y = 0, oy = 0; y < (src->h / ydenom) * ydenom; y += ydenom, oy++)
- {
- for (iy = 0; iy < ydenom; iy++)
- {
- srowx(src->samples + (y + iy) * src->w * n,
- buf + iy * ow * n,
- src->w, xdenom);
- }
- scolx(buf, dstsamples + oy * dst->w * n, ow, ydenom);
- }
-
- remaining = src->h - y;
- if (remaining)
- {
- for (iy = 0; iy < remaining; iy++)
- {
- srowx(src->samples + (y + iy) * src->w * n,
- buf + iy * ow * n,
- src->w, xdenom);
- }
- scolx(buf, dstsamples + oy * dst->w * n, ow, remaining);
- }
- }
-
- else
- {
- for (y = 0, oy = 0; y < (src->h / ydenom) * ydenom; y += ydenom, oy++)
- {
- for (iy = 0; iy < ydenom; iy++)
- {
- fz_srown(src->samples + (y + iy) * src->w * n,
- buf + iy * ow * n,
- src->w, xdenom, n);
- }
- fz_scoln(buf, dstsamples + oy * dst->w * n, ow, ydenom, n);
- }
-
- remaining = src->h - y;
- if (remaining)
- {
- for (iy = 0; iy < remaining; iy++)
- {
- fz_srown(src->samples + (y + iy) * src->w * n,
- buf + iy * ow * n,
- src->w, xdenom, n);
- }
- fz_scoln(buf, dstsamples + oy * dst->w * n, ow, remaining, n);
- }
- }
-
- fz_free(buf);
-}
-
-fz_pixmap *
fz_scalepixmap(fz_pixmap *src, int xdenom, int ydenom)
{
fz_pixmap *dst;
@@ -292,7 +195,7 @@ fz_scalepixmap(fz_pixmap *src, int xdenom, int ydenom)
buf = fz_malloc(ow * n * ydenom);
- dst = fz_newpixmap(0, 0, ow, oh, src->n);
+ dst = fz_newpixmap(src->colorspace, 0, 0, ow, oh);
switch (n)
{
diff --git a/fitzdraw/meshdraw.c b/fitzdraw/meshdraw.c
index a204f889..d756db12 100644
--- a/fitzdraw/meshdraw.c
+++ b/fitzdraw/meshdraw.c
@@ -328,12 +328,12 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *destcs, fz_pixmap
if (shade->usefunction)
{
n = 3;
- temp = fz_newpixmap(dest->x, dest->y, dest->w, dest->h, 2);
+ temp = fz_newpixmap(pdf_devicegray, dest->x, dest->y, dest->w, dest->h);
}
else if (shade->cs != destcs)
{
n = 2 + shade->cs->n;
- temp = fz_newpixmap(dest->x, dest->y, dest->w, dest->h, shade->cs->n + 1);
+ temp = fz_newpixmap(shade->cs, dest->x, dest->y, dest->w, dest->h);
}
else
{
diff --git a/fitzdraw/pixmap.c b/fitzdraw/pixmap.c
index 87c136f2..539234f6 100644
--- a/fitzdraw/pixmap.c
+++ b/fitzdraw/pixmap.c
@@ -1,7 +1,7 @@
#include "fitz.h"
fz_pixmap *
-fz_newpixmap(int x, int y, int w, int h, int n)
+fz_newpixmap(fz_colorspace *colorspace, int x, int y, int w, int h)
{
fz_pixmap *pix;
@@ -10,30 +10,31 @@ fz_newpixmap(int x, int y, int w, int h, int n)
pix->y = y;
pix->w = w;
pix->h = h;
- pix->n = n;
+ pix->colorspace = nil;
+ pix->n = 1;
- pix->samples = fz_malloc(pix->w * pix->h * pix->n * sizeof(fz_sample));
+ if (colorspace)
+ {
+ pix->colorspace = fz_keepcolorspace(colorspace);
+ pix->n = 1 + colorspace->n;
+ }
- return pix;
-}
+ pix->samples = fz_malloc(pix->w * pix->h * pix->n);
-fz_pixmap *
-fz_newpixmapwithrect(fz_irect r, int n)
-{
- return fz_newpixmap(r.x0, r.y0, r.x1 - r.x0, r.y1 - r.y0, n);
+ return pix;
}
fz_pixmap *
-fz_newpixmapcopy(fz_pixmap *old)
+fz_newpixmapwithrect(fz_colorspace *colorspace, fz_irect r)
{
- fz_pixmap *pix = fz_newpixmap(old->x, old->y, old->w, old->h, old->n);
- memcpy(pix->samples, old->samples, old->w * old->h * old->n);
- return pix;
+ return fz_newpixmap(colorspace, r.x0, r.y0, r.x1 - r.x0, r.y1 - r.y0);
}
void
fz_freepixmap(fz_pixmap *pix)
{
+ if (pix->colorspace)
+ fz_dropcolorspace(pix->colorspace);
fz_free(pix->samples);
fz_free(pix);
}
@@ -41,7 +42,7 @@ fz_freepixmap(fz_pixmap *pix)
void
fz_clearpixmap(fz_pixmap *pix, unsigned char value)
{
- memset(pix->samples, value, pix->w * pix->h * pix->n * sizeof(fz_sample));
+ memset(pix->samples, value, pix->w * pix->h * pix->n);
}
void
@@ -75,6 +76,8 @@ fz_debugpixmap(fz_pixmap *pix, char *prefix)
if (!alpha)
goto cleanup;
+ fprintf(stderr, "saving debug pixmap %s - %d\n", prefix, counter);
+
if (pix->n > 1)
{
if (pix->n > 2)
diff --git a/mupdf/mupdf.h b/mupdf/mupdf.h
index 2ef8402c..74b21dd8 100644
--- a/mupdf/mupdf.h
+++ b/mupdf/mupdf.h
@@ -224,12 +224,6 @@ struct pdf_indexed_s
unsigned char *lookup;
};
-extern fz_colorspace *pdf_devicegray;
-extern fz_colorspace *pdf_devicergb;
-extern fz_colorspace *pdf_devicecmyk;
-extern fz_colorspace *pdf_devicelab;
-extern fz_colorspace *pdf_devicepattern;
-
void pdf_convcolor(fz_colorspace *ss, float *sv, fz_colorspace *ds, float *dv);
void pdf_convpixmap(fz_colorspace *ss, fz_pixmap *sp, fz_colorspace *ds, fz_pixmap *dp);
@@ -302,8 +296,10 @@ typedef struct pdf_image_s pdf_image;
struct pdf_image_s
{
- fz_image super;
- fz_image *mask; /* explicit mask with subimage */
+ int refs;
+ int w, h, n, a;
+ fz_colorspace *cs;
+ pdf_image *mask; /* explicit mask with subimage */
int usecolorkey; /* explicit color-keyed masking */
int colorkey[FZ_MAXCOLORS * 2];
pdf_indexed *indexed;
@@ -315,8 +311,9 @@ struct pdf_image_s
fz_error pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict, fz_stream *file);
fz_error pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *obj);
-fz_error pdf_loadtile(fz_image *image, fz_pixmap *tile);
-void pdf_dropimage(fz_image *img);
+fz_error pdf_loadtile(pdf_image *image, fz_pixmap *tile);
+pdf_image *pdf_keepimage(pdf_image *img);
+void pdf_dropimage(pdf_image *img);
/*
* CMap
diff --git a/mupdf/pdf_build.c b/mupdf/pdf_build.c
index 27764401..8b065f21 100644
--- a/mupdf/pdf_build.c
+++ b/mupdf/pdf_build.c
@@ -212,10 +212,19 @@ pdf_showshade(pdf_csi *csi, fz_shade *shd)
}
void
-pdf_showimage(pdf_csi *csi, pdf_image *img)
+pdf_showimage(pdf_csi *csi, pdf_image *image)
{
pdf_gstate *gstate = csi->gstate + csi->gtop;
- csi->dev->drawimage(csi->dev->user, (fz_image*)img, gstate->ctm);
+ fz_pixmap *tile = fz_newpixmap(image->cs, 0, 0, image->w, image->h);
+ fz_error error = pdf_loadtile(image, tile);
+ if (error)
+ {
+ fz_freepixmap(tile);
+ fz_catch(error, "cannot load image data");
+ return;
+ }
+ csi->dev->drawimage(csi->dev->user, tile, gstate->ctm);
+ fz_freepixmap(tile);
}
void
@@ -270,9 +279,26 @@ pdf_showpath(pdf_csi *csi, int doclose, int dofill, int dostroke, int evenodd)
if (dostroke)
{
- // TODO: indexed, pattern, shade materials
- csi->dev->strokepath(csi->dev->user, csi->path,
- gstate->stroke.cs, gstate->stroke.v, gstate->stroke.alpha);
+ switch (gstate->stroke.kind)
+ {
+ case PDF_MNONE:
+ break;
+ case PDF_MCOLOR:
+ case PDF_MINDEXED:
+ case PDF_MLAB:
+ csi->dev->strokepath(csi->dev->user, csi->path,
+ gstate->stroke.cs, gstate->stroke.v, gstate->stroke.alpha);
+ break;
+ case PDF_MPATTERN:
+ fz_warn("pattern fills not supported yet");
+ break;
+ case PDF_MSHADE:
+// csi->dev->clipstrokepath(csi->dev->user, csi->path);
+// csi->dev->clippath(csi->dev->user, csi->path);
+ // csi->dev->drawshade(csi->dev->user, gstate->stroke.shade, gstate->ctm);
+ // csi->dev->popclip(csi->dev->user);
+ break;
+ }
}
fz_resetpath(csi->path);
diff --git a/mupdf/pdf_image.c b/mupdf/pdf_image.c
index cbe9589a..00a9ee30 100644
--- a/mupdf/pdf_image.c
+++ b/mupdf/pdf_image.c
@@ -5,15 +5,27 @@
#include "fitz.h"
#include "mupdf.h"
-static void
-pdf_freeimage(fz_image *fzimg)
+pdf_image *
+pdf_keepimage(pdf_image *image)
{
- pdf_image *img = (pdf_image*)fzimg;
- fz_dropbuffer(img->samples);
- if (img->indexed)
- fz_dropcolorspace((fz_colorspace *) img->indexed);
- if (img->mask)
- fz_dropimage(img->mask);
+ image->refs ++;
+ return image;
+}
+
+void
+pdf_dropimage(pdf_image *img)
+{
+ if (img && --img->refs == 0)
+ {
+ fz_dropbuffer(img->samples);
+ if (img->cs)
+ fz_dropcolorspace(img->cs);
+ if (img->indexed)
+ fz_dropcolorspace((fz_colorspace *) img->indexed);
+ if (img->mask)
+ pdf_dropimage(img->mask);
+ fz_free(img);
+ }
}
fz_error
@@ -33,28 +45,26 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref,
pdf_logimage("load inline image %p {\n", img);
- img->super.refs = 1;
- img->super.cs = nil;
- img->super.loadtile = pdf_loadtile;
- img->super.freefunc = pdf_freeimage;
- img->super.n = 0;
- img->super.a = 0;
+ img->refs = 1;
+ img->cs = nil;
+ img->n = 0;
+ img->a = 0;
img->indexed = nil;
img->usecolorkey = 0;
img->mask = nil;
- img->super.w = fz_toint(fz_dictgetsa(dict, "Width", "W"));
- img->super.h = fz_toint(fz_dictgetsa(dict, "Height", "H"));
+ img->w = fz_toint(fz_dictgetsa(dict, "Width", "W"));
+ img->h = fz_toint(fz_dictgetsa(dict, "Height", "H"));
img->bpc = fz_toint(fz_dictgetsa(dict, "BitsPerComponent", "BPC"));
ismask = fz_tobool(fz_dictgetsa(dict, "ImageMask", "IM"));
d = fz_dictgetsa(dict, "Decode", "D");
cs = fz_dictgetsa(dict, "ColorSpace", "CS");
- if (img->super.w == 0)
+ if (img->w == 0)
fz_warn("inline image width is zero or undefined");
- if (img->super.h == 0)
+ if (img->h == 0)
fz_warn("inline image height is zero or undefined");
- pdf_logimage("size %dx%d %d\n", img->super.w, img->super.h, img->bpc);
+ pdf_logimage("size %dx%d %d\n", img->w, img->h, img->bpc);
if (cs)
{
@@ -73,45 +83,45 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref,
if (!cso)
cso = cs;
- error = pdf_loadcolorspace(&img->super.cs, xref, cso);
+ error = pdf_loadcolorspace(&img->cs, xref, cso);
if (error)
{
- pdf_freeimage((fz_image *) img);
+ pdf_dropimage(img);
return fz_rethrow(error, "cannot load colorspace");
}
- if (!img->super.cs)
+ if (!img->cs)
return fz_throw("image is missing colorspace");
- if (!strcmp(img->super.cs->name, "Indexed"))
+ if (!strcmp(img->cs->name, "Indexed"))
{
pdf_logimage("indexed\n");
- img->indexed = (pdf_indexed*)img->super.cs;
- img->super.cs = img->indexed->base;
- fz_keepcolorspace(img->super.cs);
+ img->indexed = (pdf_indexed*)img->cs;
+ img->cs = img->indexed->base;
+ fz_keepcolorspace(img->cs);
}
- pdf_logimage("colorspace %s\n", img->super.cs->name);
+ pdf_logimage("colorspace %s\n", img->cs->name);
- img->super.n = img->super.cs->n;
- img->super.a = 0;
+ img->n = img->cs->n;
+ img->a = 0;
}
if (ismask)
{
pdf_logimage("is mask\n");
- if (img->super.cs)
+ if (img->cs)
{
fz_warn("masks can not have colorspace, proceeding anyway.");
- fz_dropcolorspace(img->super.cs);
- img->super.cs = nil;
+ fz_dropcolorspace(img->cs);
+ img->cs = nil;
}
if (img->bpc != 1)
fz_warn("masks can only have one component, proceeding anyway.");
img->bpc = 1;
- img->super.n = 0;
- img->super.a = 1;
+ img->n = 0;
+ img->a = 1;
}
else if (!cs)
return fz_throw("image is missing colorspace");
@@ -123,7 +133,7 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref,
for (i = 0; i < 2; i++)
img->decode[i] = fz_toreal(fz_arrayget(d, i));
else
- for (i = 0; i < (img->super.n + img->super.a) * 2; i++)
+ for (i = 0; i < (img->n + img->a) * 2; i++)
img->decode[i] = fz_toreal(fz_arrayget(d, i));
}
else
@@ -132,27 +142,27 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref,
for (i = 0; i < 2; i++)
img->decode[i] = i & 1 ? (1 << img->bpc) - 1 : 0;
else
- for (i = 0; i < (img->super.n + img->super.a) * 2; i++)
+ for (i = 0; i < (img->n + img->a) * 2; i++)
img->decode[i] = i & 1;
}
if (img->indexed)
- img->stride = (img->super.w * img->bpc + 7) / 8;
+ img->stride = (img->w * img->bpc + 7) / 8;
else
- img->stride = (img->super.w * (img->super.n + img->super.a) * img->bpc + 7) / 8;
+ img->stride = (img->w * (img->n + img->a) * img->bpc + 7) / 8;
/* load image data */
f = fz_dictgetsa(dict, "Filter", "F");
if (!f || (fz_isarray(f) && fz_arraylen(f) == 0))
{
- img->samples = fz_newbuffer(img->super.h * img->stride);
+ img->samples = fz_newbuffer(img->h * img->stride);
- error = fz_read(&i, file, img->samples->bp, img->super.h * img->stride);
+ error = fz_read(&i, file, img->samples->bp, img->h * img->stride);
if (error)
return error;
- img->samples->wp += img->super.h * img->stride;
+ img->samples->wp += img->h * img->stride;
}
else
{
@@ -162,7 +172,7 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref,
tempfile = fz_openrfilter(filter, file);
- img->samples = fz_readall(tempfile, img->stride * img->super.h);
+ img->samples = fz_readall(tempfile, img->stride * img->h);
fz_dropstream(tempfile);
fz_dropfilter(filter);
@@ -227,7 +237,7 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict)
if ((*imgp = pdf_finditem(xref->store, PDF_KIMAGE, dict)))
{
- fz_keepimage((fz_image*)*imgp);
+ pdf_keepimage(*imgp);
return fz_okay;
}
@@ -258,7 +268,7 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict)
error = pdf_loadcolorspace(&cs, xref, obj);
if (error)
{
- fz_dropimage((fz_image *) img);
+ pdf_dropimage(img);
return fz_rethrow(error, "cannot load colorspace");
}
@@ -315,12 +325,12 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict)
if (error)
return error;
- if (mask->super.cs && mask->super.cs != pdf_devicegray)
+ if (mask->cs && mask->cs != pdf_devicegray)
return fz_throw("syntaxerror: SMask must be DeviceGray");
- mask->super.cs = nil;
- mask->super.n = 0;
- mask->super.a = 1;
+ mask->cs = nil;
+ mask->n = 0;
+ mask->a = 1;
}
obj = fz_dictgets(dict, "Mask");
@@ -337,7 +347,7 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict)
if (mask)
{
fz_warn("image has both a mask and a soft mask. ignoring the soft mask.");
- pdf_freeimage((fz_image*)mask);
+ pdf_dropimage(mask);
mask = nil;
}
error = pdf_loadimage(&mask, xref, obj);
@@ -421,18 +431,16 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict)
* Create image object
*/
- img->super.refs = 1;
- img->super.loadtile = pdf_loadtile;
- img->super.freefunc = pdf_freeimage;
- img->super.cs = cs;
- img->super.w = w;
- img->super.h = h;
- img->super.n = n;
- img->super.a = a;
+ img->refs = 1;
+ img->cs = cs;
+ img->w = w;
+ img->h = h;
+ img->n = n;
+ img->a = a;
img->indexed = indexed;
img->stride = stride;
img->bpc = bpc;
- img->mask = (fz_image*)mask;
+ img->mask = mask;
img->usecolorkey = usecolorkey;
pdf_logimage("}\n");
@@ -479,18 +487,17 @@ maskcolorkeyindexed(fz_pixmap *ind, fz_pixmap *pix, int *colorkey)
}
fz_error
-pdf_loadtile(fz_image *img, fz_pixmap *tile)
+pdf_loadtile(pdf_image *src, fz_pixmap *tile)
{
- pdf_image *src = (pdf_image*)img;
void (*tilefunc)(unsigned char*,int,unsigned char*, int, int, int, int);
assert(tile->x == 0); /* can't handle general tile yet, only y-banding */
- assert(tile->n == img->n + 1);
+ assert(tile->n == src->n + 1);
assert(tile->x >= 0);
assert(tile->y >= 0);
- assert(tile->x + tile->w <= img->w);
- assert(tile->y + tile->h <= img->h);
+ assert(tile->x + tile->w <= src->w);
+ assert(tile->y + tile->h <= src->h);
switch (src->bpc)
{
@@ -509,7 +516,7 @@ pdf_loadtile(fz_image *img, fz_pixmap *tile)
int x, y, k, i;
int bpcfact = 1;
- tmp = fz_newpixmap(tile->x, tile->y, tile->w, tile->h, 1);
+ tmp = fz_newpixmap(nil, tile->x, tile->y, tile->w, tile->h);
switch (src->bpc)
{
@@ -553,10 +560,10 @@ pdf_loadtile(fz_image *img, fz_pixmap *tile)
{
tilefunc(src->samples->rp + (tile->y * src->stride), src->stride,
tile->samples, tile->w * tile->n,
- tile->w * (img->n + img->a), tile->h, img->a ? 0 : img->n);
+ tile->w * (src->n + src->a), tile->h, src->a ? 0 : src->n);
if (src->usecolorkey)
maskcolorkey(tile, src->colorkey);
- fz_decodetile(tile, !img->a, src->decode);
+ fz_decodetile(tile, !src->a, src->decode);
}
return fz_okay;
diff --git a/mupdf/pdf_interpret.c b/mupdf/pdf_interpret.c
index 5678caf9..0b418fc5 100644
--- a/mupdf/pdf_interpret.c
+++ b/mupdf/pdf_interpret.c
@@ -225,19 +225,19 @@ pdf_runinlineimage(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_stream *file, f
error = pdf_lex(&tok, file, buf, sizeof buf, &len);
if (error)
{
- fz_dropimage((fz_image*)img);
+ pdf_dropimage(img);
return fz_rethrow(error, "syntax error after inline image");
}
if (tok != PDF_TKEYWORD || strcmp("EI", buf))
{
- fz_dropimage((fz_image*)img);
+ pdf_dropimage(img);
return fz_throw("syntax error after inline image");
}
pdf_showimage(csi, img);
- fz_dropimage((fz_image*)img);
+ pdf_dropimage(img);
return fz_okay;
}
@@ -920,7 +920,7 @@ Lsetcolor:
if (error)
return fz_rethrow(error, "cannot load image");
pdf_showimage(csi, img);
- fz_dropimage((fz_image*)img);
+ pdf_dropimage(img);
}
else
diff --git a/mupdf/pdf_store.c b/mupdf/pdf_store.c
index 09a4f849..7856c585 100644
--- a/mupdf/pdf_store.c
+++ b/mupdf/pdf_store.c
@@ -66,7 +66,7 @@ static void keepitem(pdf_itemkind kind, void *val)
case PDF_KCOLORSPACE: fz_keepcolorspace(val); break;
case PDF_KFUNCTION: pdf_keepfunction(val); break;
case PDF_KXOBJECT: pdf_keepxobject(val); break;
- case PDF_KIMAGE: fz_keepimage(val); break;
+ case PDF_KIMAGE: pdf_keepimage(val); break;
case PDF_KPATTERN: pdf_keeppattern(val); break;
case PDF_KSHADE: fz_keepshade(val); break;
case PDF_KCMAP: pdf_keepcmap(val); break;
@@ -81,7 +81,7 @@ static void dropitem(pdf_itemkind kind, void *val)
case PDF_KCOLORSPACE: fz_dropcolorspace(val); break;
case PDF_KFUNCTION: pdf_dropfunction(val); break;
case PDF_KXOBJECT: pdf_dropxobject(val); break;
- case PDF_KIMAGE: fz_dropimage(val); break;
+ case PDF_KIMAGE: pdf_dropimage(val); break;
case PDF_KPATTERN: pdf_droppattern(val); break;
case PDF_KSHADE: fz_dropshade(val); break;
case PDF_KCMAP: pdf_dropcmap(val); break;