diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2011-04-17 00:21:47 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2011-04-17 00:21:47 +0000 |
commit | 56b5a6eaae4442ebeb73ad925d4ceaa863f4f56d (patch) | |
tree | e4681a24ed01e383ab6e8dfe448ee10fa0b3cb5e /converter/other | |
parent | 99a59c83cf845bc2859589f59ca709b92268df11 (diff) | |
download | netpbm-mirror-56b5a6eaae4442ebeb73ad925d4ceaa863f4f56d.tar.gz netpbm-mirror-56b5a6eaae4442ebeb73ad925d4ceaa863f4f56d.tar.xz netpbm-mirror-56b5a6eaae4442ebeb73ad925d4ceaa863f4f56d.zip |
Eliminate more reference to pnginfo private members
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1475 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other')
-rw-r--r-- | converter/other/pngx.c | 92 | ||||
-rw-r--r-- | converter/other/pngx.h | 34 | ||||
-rw-r--r-- | converter/other/pnmtopng.c | 57 |
3 files changed, 113 insertions, 70 deletions
diff --git a/converter/other/pngx.c b/converter/other/pngx.c index f1afd39e..81e985e1 100644 --- a/converter/other/pngx.c +++ b/converter/other/pngx.c @@ -47,6 +47,8 @@ pngx_create(struct pngx ** const pngxPP, if (!pngxP) pm_error("Failed to allocate memory for PNG object"); else { + pngxP->numPassesRequired = 1; + switch(rw) { case PNGX_READ: pngxP->png_ptr = png_create_read_struct( @@ -102,6 +104,46 @@ pngx_chunkIsPresent(struct pngx * const pngxP, void +pngx_setCompressionSize(struct pngx * const pngxP, + int const bufferSize) { + +#if PNG_LIBPNG_VER >= 10009 + png_set_compression_buffer_size(pngxP->png_ptr, bufferSize); +#else + pm_error("Your PNG library cannot set the compression buffer size. " + "You need at least Version 1.0.9 of Libpng; you have Version %s", + PNG_LIBPNG_VER_STRING); +#endif +} + + + +void +pngx_setInterlaceHandling(struct pngx * const pngxP) { + + pngxP->numPassesRequired = png_set_interlace_handling(pngxP->png_ptr); +} + + + +void +pngx_setFilter(struct pngx * const pngxP, + int const filterSet) { + + png_set_filter(pngxP->png_ptr, 0, filterSet); +} + + + +void +pngx_setPacking(struct pngx * const pngxP) { + + png_set_packing(pngxP->png_ptr); +} + + + +void pngx_setText(struct pngx * const pngxP, png_textp const textP, unsigned int const count) { @@ -128,22 +170,6 @@ pngx_setIhdr(struct pngx * const pngxP, -void -pngx_writeInfo(struct pngx * const pngxP) { - - png_write_info(pngxP->png_ptr, pngxP->info_ptr); -} - - - -void -pngx_writeEnd(struct pngx * const pngxP) { - - png_write_end(pngxP->png_ptr, pngxP->info_ptr); -} - - - png_byte pngx_colorType(struct pngx * const pngxP) { @@ -211,14 +237,6 @@ pngx_setSbit(struct pngx * const pngxP, void -pngx_setInterlaceHandling(struct pngx * const pngxP) { - - png_set_interlace_handling(pngxP->png_ptr); -} - - - -void pngx_setPlte(struct pngx * const pngxP, png_color * const palette, unsigned int const paletteSize) { @@ -301,3 +319,29 @@ pngx_setBkgdRgb(struct pngx * const pngxP, +void +pngx_writeInfo(struct pngx * const pngxP) { + + png_write_info(pngxP->png_ptr, pngxP->info_ptr); +} + + + +void +pngx_writeRow(struct pngx * const pngxP, + const png_byte * const line) { + + png_write_row(pngxP->png_ptr, (png_byte *)line); +} + + + +void +pngx_writeEnd(struct pngx * const pngxP) { + + png_write_end(pngxP->png_ptr, pngxP->info_ptr); +} + + + + diff --git a/converter/other/pngx.h b/converter/other/pngx.h index 930b84c4..dfaf2e91 100644 --- a/converter/other/pngx.h +++ b/converter/other/pngx.h @@ -34,10 +34,15 @@ struct pngx_trans { typedef enum {PNGX_READ, PNGX_WRITE} pngx_rw; struct pngx { - png_structp png_ptr; - png_infop info_ptr; - pngx_rw rw; - png_uint_16 maxval; + png_structp png_ptr; + png_infop info_ptr; + pngx_rw rw; + png_uint_16 maxval; + unsigned int numPassesRequired; + /* The number of times we have write the complete image to the + compressor. This is more than one when the compressor is set + up to do an interlaced format. + */ }; void @@ -56,6 +61,20 @@ png_byte pngx_colorType(struct pngx * const pngxP); void +pngx_setInterlaceHandling(struct pngx * const pngxP); + +void +pngx_setCompressionSize(struct pngx * const pngxP, + int const bufferSize); + +void +pngx_setFilter(struct pngx * const pngxP, + int const filterSet); + +void +pngx_setPacking(struct pngx * const pngxP); + +void pngx_setText(struct pngx * const pngxP, png_textp const textP, unsigned int const count); @@ -91,9 +110,6 @@ pngx_setSbit(struct pngx * const pngxP, png_color_8 const sbit); void -pngx_setInterlaceHandling(struct pngx * const pngxP); - -void pngx_setPlte(struct pngx * const pngxP, png_color * const palette, unsigned int const paletteSize); @@ -126,6 +142,10 @@ void pngx_writeInfo(struct pngx * const pngxP); void +pngx_writeRow(struct pngx * const pngxP, + const png_byte * const line); + +void pngx_writeEnd(struct pngx * const pngxP); #endif diff --git a/converter/other/pnmtopng.c b/converter/other/pnmtopng.c index e154c921..ffdabc87 100644 --- a/converter/other/pnmtopng.c +++ b/converter/other/pnmtopng.c @@ -2119,41 +2119,28 @@ createPngPalette(pixel palette_pnm[], static void -setCompressionSize(png_struct * const png_ptr, - int const buffer_size) { - -#if PNG_LIBPNG_VER >= 10009 - png_set_compression_buffer_size(png_ptr, buffer_size); -#else - pm_error("Your PNG library cannot set the compression buffer size. " - "You need at least Version 1.0.9 of Libpng; you have Version %s", - PNG_LIBPNG_VER_STRING); -#endif -} - - - -static void -setZlibCompression(png_struct * const png_ptr, +setZlibCompression(struct pngx * const pngxP, struct zlibCompression const zlibCompression) { if (zlibCompression.levelSpec) - png_set_compression_level(png_ptr, zlibCompression.level); + png_set_compression_level(pngxP->png_ptr, zlibCompression.level); if (zlibCompression.memLevelSpec) - png_set_compression_mem_level(png_ptr, zlibCompression.mem_level); + png_set_compression_mem_level(pngxP->png_ptr, + zlibCompression.mem_level); if (zlibCompression.strategySpec) - png_set_compression_strategy(png_ptr, zlibCompression.strategy); + png_set_compression_strategy(pngxP->png_ptr, zlibCompression.strategy); if (zlibCompression.windowBitsSpec) - png_set_compression_window_bits(png_ptr, zlibCompression.window_bits); + png_set_compression_window_bits(pngxP->png_ptr, + zlibCompression.window_bits); if (zlibCompression.methodSpec) - png_set_compression_method(png_ptr, zlibCompression.method); + png_set_compression_method(pngxP->png_ptr, zlibCompression.method); if (zlibCompression.bufferSizeSpec) { - setCompressionSize(png_ptr, zlibCompression.buffer_size); + pngx_setCompressionSize(pngxP, zlibCompression.buffer_size); } } @@ -2227,14 +2214,14 @@ writeRaster(struct pngx * const pngxP, xelval const maxval, int const format, xelval const png_maxval, - unsigned const int depth, + unsigned int const depth, bool const alpha, gray ** const alpha_mask, colorhash_table const cht, coloralphahash_table const caht ) { /*---------------------------------------------------------------------------- - Write the PNG raster via compressor *png_ptr, reading the PNM raster + Write the PNG raster via compressor *pngxP, reading the PNM raster from file *ifP, position 'rasterPos'. The PNG raster consists of IDAT chunks. @@ -2252,7 +2239,7 @@ writeRaster(struct pngx * const pngxP, if (line == NULL) pm_error("out of memory allocating PNG row buffer"); - for (pass = 0; pass < png_set_interlace_handling(pngxP->png_ptr); ++pass) { + for (pass = 0; pass < pngxP->numPassesRequired; ++pass) { unsigned int row; pm_seek2(ifP, &rasterPos, sizeof(rasterPos)); for (row = 0; row < rows; ++row) { @@ -2264,7 +2251,7 @@ writeRaster(struct pngx * const pngxP, alpha, alpha ? alpha_mask[row] : NULL, cht, caht, pngxP, png_maxval, depth); - png_write_row(pngxP->png_ptr, line); + pngx_writeRow(pngxP, line); } } pnm_freerow(xelrow); @@ -2759,31 +2746,23 @@ convertpnm(struct cmdlineInfo const cmdline, doTimeChunk(cmdline, pngxP); if (cmdline.filterSet != 0) - png_set_filter(pngxP->png_ptr, 0, cmdline.filterSet); + pngx_setFilter(pngxP, cmdline.filterSet); - setZlibCompression(pngxP->png_ptr, cmdline.zlibCompression); + setZlibCompression(pngxP, cmdline.zlibCompression); png_init_io(pngxP->png_ptr, ofP); /* write the png-info struct */ - png_write_info(pngxP->png_ptr, pngxP->info_ptr); - - if (cmdline.text || cmdline.ztxt) - /* prevent from being written twice with png_write_end */ - pngxP->info_ptr->num_text = 0; - - if (cmdline.modtime) - /* prevent from being written twice with png_write_end */ - pngxP->info_ptr->valid &= ~PNG_INFO_tIME; + pngx_writeInfo(pngxP); /* let libpng take care of, e.g., bit-depth conversions */ - png_set_packing(pngxP->png_ptr); + pngx_setPacking(pngxP); writeRaster(pngxP, ifP, rasterPos, cols, rows, maxval, format, png_maxval, depth, alpha, alpha_mask, cht, caht); - png_write_end(pngxP->png_ptr, pngxP->info_ptr); + pngx_writeEnd(pngxP); pngx_destroy(pngxP); |