diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-10-11 21:10:21 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-10-12 12:37:48 +0100 |
commit | 80308eae9964e71b66a18f3de6ebcd2ebf0d306b (patch) | |
tree | 6aa51f6f53fca59d3c7afcb727f36cf627249e7a /source/fitz/output.c | |
parent | 7de80f5eea6c9475b1db2b4fd905fd69ed3795e7 (diff) | |
download | mupdf-80308eae9964e71b66a18f3de6ebcd2ebf0d306b.tar.xz |
Regularize band writer interface.
We have various functions that, for different image formats,
write a header, then a band, then (sometimes) a trailer.
Push them all through a single interface.
This change also fixes potential problems caused by the trailer
writing being an implicit destructor, which can cause problems
in cleanup code if the trailer writing throws an error.
Diffstat (limited to 'source/fitz/output.c')
-rw-r--r-- | source/fitz/output.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/source/fitz/output.c b/source/fitz/output.c index 0fc4fc09..d5dfb47e 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -292,3 +292,51 @@ fz_save_buffer(fz_context *ctx, fz_buffer *buf, const char *filename) fz_catch(ctx) fz_rethrow(ctx); } + +fz_band_writer *fz_new_band_writer_of_size(fz_context *ctx, size_t size, fz_output *out) +{ + fz_band_writer *writer = fz_calloc(ctx, size, 1); + + assert(size >= sizeof(*writer)); + + writer->out = out; + + return writer; +} + +void fz_write_header(fz_context *ctx, fz_band_writer *writer, int w, int h, int n, int alpha, int xres, int yres, int pagenum) +{ + if (writer == NULL || writer->band == NULL) + return; + writer->w = w; + writer->h = h; + writer->n = n; + writer->alpha = alpha; + writer->xres = xres; + writer->yres = yres; + writer->pagenum = pagenum; + writer->header(ctx, writer); +} + +void fz_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_start, int band_height, const unsigned char *samples) +{ + if (writer == NULL || writer->band == NULL) + return; + writer->band(ctx, writer, stride, band_start, band_height, samples); +} + +void fz_write_trailer(fz_context *ctx, fz_band_writer *writer) +{ + if (writer == NULL || writer->trailer == NULL) + return; + writer->trailer(ctx, writer); +} + +void fz_drop_band_writer(fz_context *ctx, fz_band_writer *writer) +{ + if (writer == NULL) + return; + if (writer->drop != NULL) + writer->drop(ctx, writer); + fz_free(ctx, writer); +} |