summaryrefslogtreecommitdiff
path: root/source/fitz/util.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-08-01 14:11:01 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-08-09 14:02:19 +0200
commita644f7e67af05dca8601e379442690c724030738 (patch)
tree6e92f987323842dc397f48980852615f204138f7 /source/fitz/util.c
parent7f97f80d1a74a50d369b3bdf513de7fbcaed6bc3 (diff)
downloadmupdf-a644f7e67af05dca8601e379442690c724030738.tar.xz
Add common fz_write_image_as_data_uri function for HTML and SVG output.
Also ensure we don't write CMYK JPEG images.
Diffstat (limited to 'source/fitz/util.c')
-rw-r--r--source/fitz/util.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/fitz/util.c b/source/fitz/util.c
index d532734a..6f900174 100644
--- a/source/fitz/util.c
+++ b/source/fitz/util.c
@@ -548,3 +548,38 @@ fz_new_buffer_from_page_number(fz_context *ctx, fz_document *doc, int number, co
fz_rethrow(ctx);
return buf;
}
+
+void
+fz_write_image_as_data_uri(fz_context *ctx, fz_output *out, fz_image *image)
+{
+ fz_compressed_buffer *cbuf;
+ fz_buffer *buf;
+ int n;
+
+ n = fz_colorspace_n(ctx, image->colorspace);
+ cbuf = fz_compressed_image_buffer(ctx, image);
+
+ if (cbuf && cbuf->params.type == FZ_IMAGE_JPEG && (n == 1 || n == 3))
+ {
+ fz_write_string(ctx, out, "image/jpeg;base64,");
+ fz_write_base64_buffer(ctx, out, cbuf->buffer, 1);
+ return;
+ }
+ if (cbuf && cbuf->params.type == FZ_IMAGE_PNG)
+ {
+ fz_write_string(ctx, out, "image/png;base64,");
+ fz_write_base64_buffer(ctx, out, cbuf->buffer, 1);
+ return;
+ }
+
+ buf = fz_new_buffer_from_image_as_png(ctx, image, NULL);
+ fz_try(ctx)
+ {
+ fz_write_string(ctx, out, "image/png;base64,");
+ fz_write_base64_buffer(ctx, out, buf, 1);
+ }
+ fz_always(ctx)
+ fz_drop_buffer(ctx, buf);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}