diff options
Diffstat (limited to 'converter/other')
-rw-r--r-- | converter/other/pngx.c | 24 | ||||
-rw-r--r-- | converter/other/pngx.h | 7 |
2 files changed, 24 insertions, 7 deletions
diff --git a/converter/other/pngx.c b/converter/other/pngx.c index b4a00c5f..fb6b71f8 100644 --- a/converter/other/pngx.c +++ b/converter/other/pngx.c @@ -1,3 +1,4 @@ +#include <stdbool.h> #include <assert.h> #include <png.h> #include "pm_c_util.h" @@ -59,6 +60,7 @@ pngx_create(struct pngx ** const pngxPP, if (!pngxP) pm_error("Failed to allocate memory for PNG object"); else { + pngxP->infoPrepared = false; pngxP->numPassesRequired = 1; switch(rw) { @@ -490,14 +492,14 @@ pngx_setInterlaceHandling(struct pngx * const pngxP) { times into the same buffer, with the pixels that belong to each subimage being filled in on each pass. - But there's a problem: Dcumentation says this returns 7 if the - compressor is interlacing, but it always returns 1 in practice. - - If the program does 1 pass as directed by libpng, the image won't - decompress - libpng says "Not enough image data". If the program does - 7 passes as makes sense, the image won't decompress because "too many - IDAT's found." + Note that the only kind of interlacing that exists today is ADAM7 and + consequently, the number of passes is always 1 (for no interlacing) or + 7 (for interlacing). */ + if (!pngxP->infoPrepared) + pm_error("pngx_setInterlaceHandling must not be called before " + "pngx_writeInfo or pngx_readInfo"); + pngxP->numPassesRequired = png_set_interlace_handling(pngxP->png_ptr); } @@ -506,6 +508,10 @@ pngx_setInterlaceHandling(struct pngx * const pngxP) { void pngx_setPacking(struct pngx * const pngxP) { + if (!pngxP->infoPrepared) + pm_error("pngx_setPacking must not be called before " + "pngx_writeInfo or pngx_readInfo"); + png_set_packing(pngxP->png_ptr); } @@ -682,6 +688,8 @@ void pngx_readInfo(struct pngx * const pngxP) { png_read_info(pngxP->png_ptr, pngxP->info_ptr); + + pngxP->infoPrepared = true; } @@ -690,6 +698,8 @@ void pngx_writeInfo(struct pngx * const pngxP) { png_write_info(pngxP->png_ptr, pngxP->info_ptr); + + pngxP->infoPrepared = true; } diff --git a/converter/other/pngx.h b/converter/other/pngx.h index 90b320a0..25f0cdcc 100644 --- a/converter/other/pngx.h +++ b/converter/other/pngx.h @@ -1,6 +1,7 @@ #ifndef PNGX_H_INCLUDED #define PNGX_H_INCLUDED +#include <stdbool.h> #include <png.h> /* This includes the Zlib interface header file zlib.h because libpng uses libz and some of the Zlib interface, e.g. the Z_DEFLATED constant, @@ -57,6 +58,12 @@ struct pngx { compressor. This is more than one when the compressor is set up to do an interlaced format. */ + bool infoPrepared; + /* png_write_info or png_read_info has been called, so libpng is in a + state in which things such as png_set_interlace_handling will work. + These functions use information in *png_ptr that is set by + png_XXX_info. + */ }; void |