From d63dc50e7d0ac6f1adccd9507b41410e0cbb0faf Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 16 Nov 2010 15:20:19 +0000 Subject: Add a function fz_newpixmapwithdata that lets clients create pixmaps with a custom backing store. --- fitz/fitz.h | 13 ++++--------- fitz/res_pixmap.c | 22 +++++++++++++++++++--- 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,11 +21,26 @@ 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) { @@ -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); } } -- cgit v1.2.3