summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/draw-device.c2
-rw-r--r--source/fitz/output-cbz.c4
-rw-r--r--source/fitz/output-png.c68
-rw-r--r--source/fitz/writer.c4
4 files changed, 74 insertions, 4 deletions
diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c
index f725fd41..126f715d 100644
--- a/source/fitz/draw-device.c
+++ b/source/fitz/draw-device.c
@@ -9,7 +9,7 @@ const char *fz_draw_options_usage =
"\theight=N: render pages to fit N pixels tall (ignore resolution option)\n"
"\tcolorspace=(gray|rgb|cmyk): render using specified colorspace\n"
"\talpha: render pages with alpha channel and transparent background\n"
- ;
+ "\n";
static int opteq(const char *a, const char *b)
{
diff --git a/source/fitz/output-cbz.c b/source/fitz/output-cbz.c
index ebfded4c..ba7ca196 100644
--- a/source/fitz/output-cbz.c
+++ b/source/fitz/output-cbz.c
@@ -7,10 +7,10 @@ typedef struct fz_cbz_writer_s fz_cbz_writer;
struct fz_cbz_writer_s
{
fz_document_writer super;
- fz_zip_writer *zip;
fz_draw_options options;
fz_pixmap *pixmap;
int count;
+ fz_zip_writer *zip;
};
const char *fz_cbz_write_options_usage = "";
@@ -72,7 +72,7 @@ fz_new_cbz_writer(fz_context *ctx, const char *path, const char *options)
fz_try(ctx)
{
fz_parse_draw_options(ctx, &wri->options, options);
- wri->zip = fz_new_zip_writer(ctx, path);
+ wri->zip = fz_new_zip_writer(ctx, path ? path : "out.cbz");
}
fz_catch(ctx)
{
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;
+}
diff --git a/source/fitz/writer.c b/source/fitz/writer.c
index 2a344e52..927ddffe 100644
--- a/source/fitz/writer.c
+++ b/source/fitz/writer.c
@@ -54,12 +54,14 @@ fz_new_document_writer(fz_context *ctx, const char *path, const char *format, co
if (!fz_strcasecmp(format, "cbz"))
return fz_new_cbz_writer(ctx, path, options);
+ if (!fz_strcasecmp(format, "png"))
+ return fz_new_png_writer(ctx, path, options);
#if FZ_ENABLE_PDF
if (!fz_strcasecmp(format, "pdf"))
return fz_new_pdf_writer(ctx, path, options);
#endif
- fz_throw(ctx, FZ_ERROR_GENERIC, "unknown document format: %s", format);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown output document format: %s", format);
}
void