summaryrefslogtreecommitdiff
path: root/fitz
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
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')
-rw-r--r--fitz/fitz.h13
-rw-r--r--fitz/res_pixmap.c22
2 files changed, 23 insertions, 12 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 0608a453..57161305 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -445,15 +445,10 @@ char *fz_objkindstr(fz_obj *obj);
/*
* Data buffers.
- *
- * A buffer owns the memory it has allocated, unless ownsdata is false,
- * in which case the creator of the buffer owns it.
*/
typedef struct fz_buffer_s fz_buffer;
-#define FZ_BUFSIZE (8 * 1024)
-
struct fz_buffer_s
{
int refs;
@@ -462,14 +457,12 @@ struct fz_buffer_s
};
fz_buffer * fz_newbuffer(int size);
-fz_buffer * fz_newbufferwithmemory(unsigned char *data, int size);
+fz_buffer *fz_keepbuffer(fz_buffer *buf);
+void fz_dropbuffer(fz_buffer *buf);
void fz_resizebuffer(fz_buffer *buf, int size);
void fz_growbuffer(fz_buffer *buf);
-fz_buffer *fz_keepbuffer(fz_buffer *buf);
-void fz_dropbuffer(fz_buffer *buf);
-
/*
* Buffered reader.
* Only the data between rp and wp is valid data.
@@ -598,8 +591,10 @@ struct fz_pixmap_s
fz_pixmap *mask; /* explicit soft/image mask */
fz_colorspace *colorspace;
unsigned char *samples;
+ int freesamples;
};
+fz_pixmap *fz_newpixmapwithdata(fz_colorspace *colorspace, int x, int y, int w, int h, unsigned char *samples);
fz_pixmap * fz_newpixmapwithrect(fz_colorspace *, fz_bbox bbox);
fz_pixmap * fz_newpixmap(fz_colorspace *, int x, int y, int w, int h);
fz_pixmap *fz_keeppixmap(fz_pixmap *pix);
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);
}
}