summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-10-10 10:26:48 +0100
committerRobin Watts <robin.watts@artifex.com>2013-10-10 11:16:52 +0100
commitf7098ecf6d5fccf6b3283d497e3c9b1f14470e1e (patch)
tree5b7d82dbce877d297210242fa173cb7c40047e01 /source
parent5f83e5ec5c1717117e9ef97f7f3bb23bc1ec9689 (diff)
downloadmupdf-f7098ecf6d5fccf6b3283d497e3c9b1f14470e1e.tar.xz
Add fz_new_png_from_pixmap
This accompanies the function formerly known as fz_image_as_png (now renamed to fz_new_png_from_image).
Diffstat (limited to 'source')
-rw-r--r--source/fitz/pixmap.c32
-rw-r--r--source/fitz/stext-output.c2
-rw-r--r--source/fitz/svg-device.c4
3 files changed, 28 insertions, 10 deletions
diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c
index 3c99d724..3f580c9e 100644
--- a/source/fitz/pixmap.c
+++ b/source/fitz/pixmap.c
@@ -804,24 +804,28 @@ fz_output_png_trailer(fz_output *out, fz_png_output_context *poc)
putchunk("IEND", block, 0, out);
}
-
-fz_buffer *
-fz_image_as_png(fz_context *ctx, fz_image *image, int w, int h)
+/* We use an auxiliary function to do pixmap_as_png, as it can enable us to
+ * drop pix early in the case where we have to convert, potentially saving
+ * us having to have 2 copies of the pixmap and a buffer open at once. */
+static fz_buffer *
+png_from_pixmap(fz_context *ctx, fz_pixmap *pix, int drop)
{
- fz_pixmap *pix = fz_image_get_pixmap(ctx, image, image->w, image->h);
fz_buffer *buf = NULL;
fz_output *out;
+ fz_pixmap *pix2 = NULL;
fz_var(buf);
fz_var(out);
+ fz_var(pix2);
fz_try(ctx)
{
if (pix->colorspace && pix->colorspace != fz_device_gray(ctx) && pix->colorspace != fz_device_rgb(ctx))
{
- fz_pixmap *pix2 = fz_new_pixmap(ctx, fz_device_rgb(ctx), pix->w, pix->h);
+ pix2 = fz_new_pixmap(ctx, fz_device_rgb(ctx), pix->w, pix->h);
fz_convert_pixmap(ctx, pix2, pix);
- fz_drop_pixmap(ctx, pix);
+ if (drop)
+ fz_drop_pixmap(ctx, pix);
pix = pix2;
}
buf = fz_new_buffer(ctx, 1024);
@@ -830,8 +834,8 @@ fz_image_as_png(fz_context *ctx, fz_image *image, int w, int h)
}
fz_always(ctx)
{
+ fz_drop_pixmap(ctx, drop ? pix : pix2);
fz_close_output(out);
- fz_drop_pixmap(ctx, pix);
}
fz_catch(ctx)
{
@@ -841,6 +845,20 @@ fz_image_as_png(fz_context *ctx, fz_image *image, int w, int h)
return buf;
}
+fz_buffer *
+fz_new_png_from_image(fz_context *ctx, fz_image *image, int w, int h)
+{
+ fz_pixmap *pix = fz_image_get_pixmap(ctx, image, image->w, image->h);
+
+ return png_from_pixmap(ctx, pix, 1);
+}
+
+fz_buffer *
+fz_new_png_from_pixmap(fz_context *ctx, fz_pixmap *pix)
+{
+ return png_from_pixmap(ctx, pix, 0);
+}
+
/*
* Write pixmap to TGA file (with or without alpha channel)
*/
diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c
index d3241131..6ed595fc 100644
--- a/source/fitz/stext-output.c
+++ b/source/fitz/stext-output.c
@@ -258,7 +258,7 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page)
break;
default:
{
- fz_buffer *buf = fz_image_as_png(ctx, image->image, image->image->w, image->image->h);
+ fz_buffer *buf = fz_new_png_from_image(ctx, image->image, image->image->w, image->image->h);
fz_printf(out, "image/png;base64,");
send_data_base64(out, buf);
fz_drop_buffer(ctx, buf);
diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c
index 11194abc..d76f14b3 100644
--- a/source/fitz/svg-device.c
+++ b/source/fitz/svg-device.c
@@ -700,7 +700,7 @@ svg_dev_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float
break;
default:
{
- fz_buffer *buf = fz_image_as_png(ctx, image, image->w, image->h);
+ fz_buffer *buf = fz_new_png_from_image(ctx, image, image->w, image->h);
fz_printf(out, "image/png;base64,");
send_data_base64(out, buf);
fz_drop_buffer(ctx, buf);
@@ -742,7 +742,7 @@ fz_colorspace *colorspace, float *color, float alpha)
break;
default:
{
- fz_buffer *buf = fz_image_as_png(ctx, image, image->w, image->h);
+ fz_buffer *buf = fz_new_png_from_image(ctx, image, image->w, image->h);
fz_printf(out, "image/png;base64,");
send_data_base64(out, buf);
fz_drop_buffer(ctx, buf);