diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-06-16 12:23:11 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-06-16 18:08:15 +0100 |
commit | adc06f3c7f4ca0acbee8b5be84d72d716b60b5a0 (patch) | |
tree | 0fab413b744abf39086e3fb9d007fe162f577f0d /source/fitz/output-png.c | |
parent | 000e932a844ecc6cd59ae9cadc3c3150d4a6bf5b (diff) | |
download | mupdf-adc06f3c7f4ca0acbee8b5be84d72d716b60b5a0.tar.xz |
Add PNG output for mutool convert.
Diffstat (limited to 'source/fitz/output-png.c')
-rw-r--r-- | source/fitz/output-png.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c index 9fe58ef0..2f19611c 100644 --- a/source/fitz/output-png.c +++ b/source/fitz/output-png.c @@ -292,3 +292,71 @@ fz_new_buffer_from_pixmap_as_png(fz_context *ctx, fz_pixmap *pix) { return png_from_pixmap(ctx, pix, 0); } + +/* PNG output writer */ + +typedef struct fz_png_writer_s fz_png_writer; + +struct fz_png_writer_s +{ + fz_document_writer super; + fz_draw_options options; + fz_pixmap *pixmap; + int count; + char *path; +}; + +const char *fz_png_write_options_usage = ""; + +static fz_device * +png_begin_page(fz_context *ctx, fz_document_writer *wri_, const fz_rect *mediabox, fz_matrix *transform) +{ + fz_png_writer *wri = (fz_png_writer*)wri_; + return fz_new_draw_device_with_options(ctx, &wri->options, mediabox, transform, &wri->pixmap); +} + +static void +png_end_page(fz_context *ctx, fz_document_writer *wri_, fz_device *dev) +{ + fz_png_writer *wri = (fz_png_writer*)wri_; + char path[PATH_MAX]; + + wri->count += 1; + + fz_format_output_path(ctx, path, sizeof path, wri->path, wri->count); + fz_save_pixmap_as_png(ctx, wri->pixmap, path); + fz_drop_pixmap(ctx, wri->pixmap); + wri->pixmap = NULL; +} + +static void +png_close(fz_context *ctx, fz_document_writer *wri_) +{ + fz_png_writer *wri = (fz_png_writer*)wri_; + fz_drop_pixmap(ctx, wri->pixmap); + fz_free(ctx, wri->path); +} + +fz_document_writer * +fz_new_png_writer(fz_context *ctx, const char *path, const char *options) +{ + fz_png_writer *wri; + + wri = fz_malloc_struct(ctx, fz_png_writer); + wri->super.begin_page = png_begin_page; + wri->super.end_page = png_end_page; + wri->super.close = png_close; + + fz_try(ctx) + { + fz_parse_draw_options(ctx, &wri->options, options); + wri->path = fz_strdup(ctx, path ? path : "out-%04d.png"); + } + fz_catch(ctx) + { + fz_free(ctx, wri); + fz_rethrow(ctx); + } + + return (fz_document_writer*)wri; +} |