summaryrefslogtreecommitdiff
path: root/fitz/res_pixmap.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-11-16 15:20:19 +0000
committerTor Andersson <tor@ghostscript.com>2010-11-16 15:20:19 +0000
commitd63dc50e7d0ac6f1adccd9507b41410e0cbb0faf (patch)
tree5488a9e978eb037eea03321fc5f3be4ebf7897eb /fitz/res_pixmap.c
parent5c6b96f6c1d965e6236bf934d730c18c6326738c (diff)
downloadmupdf-d63dc50e7d0ac6f1adccd9507b41410e0cbb0faf.tar.xz
Add a function fz_newpixmapwithdata that lets clients create pixmaps with a custom backing store.
Diffstat (limited to 'fitz/res_pixmap.c')
-rw-r--r--fitz/res_pixmap.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c
index 652d0426..4826502e 100644
--- a/fitz/res_pixmap.c
+++ b/fitz/res_pixmap.c
@@ -1,7 +1,7 @@
#include "fitz.h"
fz_pixmap *
-fz_newpixmap(fz_colorspace *colorspace, int x, int y, int w, int h)
+fz_newpixmapwithdata(fz_colorspace *colorspace, int x, int y, int w, int h, unsigned char *samples)
{
fz_pixmap *pix;
@@ -21,12 +21,27 @@ fz_newpixmap(fz_colorspace *colorspace, int x, int y, int w, int h)
pix->n = 1 + colorspace->n;
}
- pix->samples = fz_malloc(pix->w * pix->h * pix->n);
+ if (samples)
+ {
+ pix->samples = samples;
+ pix->freesamples = 0;
+ }
+ else
+ {
+ pix->samples = fz_malloc(pix->w * pix->h * pix->n);
+ pix->freesamples = 1;
+ }
return pix;
}
fz_pixmap *
+fz_newpixmap(fz_colorspace *colorspace, int x, int y, int w, int h)
+{
+ return fz_newpixmapwithdata(colorspace, x, y, w, h, NULL);
+}
+
+fz_pixmap *
fz_newpixmapwithrect(fz_colorspace *colorspace, fz_bbox r)
{
return fz_newpixmap(colorspace, r.x0, r.y0, r.x1 - r.x0, r.y1 - r.y0);
@@ -48,7 +63,8 @@ fz_droppixmap(fz_pixmap *pix)
fz_droppixmap(pix->mask);
if (pix->colorspace)
fz_dropcolorspace(pix->colorspace);
- fz_free(pix->samples);
+ if (pix->freesamples)
+ fz_free(pix->samples);
fz_free(pix);
}
}