diff --git a/ANNOUNCE b/ANNOUNCE index 038f7ea4a6053a5ab657be0bafe0ce0281d80e12..fb838ecf55fab07cd8b5dcb48d39c6eb22aff9d8 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -51,8 +51,6 @@ Version 1.6.3beta05 [May 8, 2013] the windowBits setting in the zlib header. Zlib-1.2.8 and earlier don't allow us to decrease the windowBits, so undid the improvement in beta04. - Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart). - Ignore "#" delimited comments in input file to pnm2png.c. Added an option to force maximum window size for inflating. For inflate, reverted previous fixes. Added fixitxt and pngdeflate to the built programs and removed warnings @@ -64,6 +62,13 @@ Version 1.6.3beta05 [May 8, 2013] 1.6 and later. Fixed gnu issues: g++ needs a static_cast, gcc 4.4.7 has a broken warning message which it is easier to work round than ignore. + Updated contrib/pngminus/pnm2png.c (Paul Stewart): + Check for EOF + Ignore "#" delimited comments in input file to pnm2png.c. + Fixed whitespace handling + Added a call to png_set_packing() + Initialize dimension values so if sscanf fails at least we have known + invalid values. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index a02553d24167aa0793836fa4f4b381e6adcfa8d0..b7cd0a9e2ccb600987b0a3342b08b88cb508cff3 100644 --- a/CHANGES +++ b/CHANGES @@ -4534,8 +4534,6 @@ Version 1.6.3beta05 [May 8, 2013] the windowBits setting in the zlib header. Zlib-1.2.8 and earlier don't allow us to decrease the windowBits, so undid the improvement in beta04. - Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart). - Ignore "#" delimited comments in input file to pnm2png.c. Added an option to force maximum window size for inflating. For inflate, reverted previous fixes. Added fixitxt and pngdeflate to the built programs and removed warnings @@ -4547,6 +4545,13 @@ Version 1.6.3beta05 [May 8, 2013] 1.6 and later. Fixed gnu issues: g++ needs a static_cast, gcc 4.4.7 has a broken warning message which it is easier to work round than ignore. + Updated contrib/pngminus/pnm2png.c (Paul Stewart): + Check for EOF + Ignore "#" delimited comments in input file to pnm2png.c. + Fixed whitespace handling + Added a call to png_set_packing() + Initialize dimension values so if sscanf fails at least we have known + invalid values. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/contrib/pngminim/encoder/pngusr.dfa b/contrib/pngminim/encoder/pngusr.dfa index 88d8b2a07ab2770b560b264f50ba298758f4b6b8..3f1b0214c1a882bbf3a9bb4d3231511c5def9672 100644 --- a/contrib/pngminim/encoder/pngusr.dfa +++ b/contrib/pngminim/encoder/pngusr.dfa @@ -13,6 +13,8 @@ everything = off # Switch on the write code - this makes a minimalist encoder option WRITE on +option WRITE_INVERT on +option WRITE_PACK on # You must choose fixed or floating point arithmetic: # option FLOATING_POINT on diff --git a/contrib/pngminus/pnm2png.c b/contrib/pngminus/pnm2png.c index 9530112230b7b302880f2b02a8d9b8482c47340d..ea3ef4d7821ba06ad0b264dee9c7e7d83c63c8b4 100644 --- a/contrib/pngminus/pnm2png.c +++ b/contrib/pngminus/pnm2png.c @@ -198,9 +198,9 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, char height_token[16]; char maxval_token[16]; int color_type; - unsigned long ul_width, ul_alpha_width; - unsigned long ul_height, ul_alpha_height; - unsigned long ul_maxval; + unsigned long ul_width=0, ul_alpha_width=0; + unsigned long ul_height=0, ul_alpha_height=0; + unsigned long ul_maxval=0; png_uint_32 width, alpha_width; png_uint_32 height, alpha_height; png_uint_32 maxval; @@ -210,6 +210,7 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, int alpha_present; int row, col; BOOL raw, alpha_raw = FALSE; + BOOL packed_bitmap = FALSE; png_uint_32 tmp16; int i; @@ -224,7 +225,14 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, { raw = (type_token[1] == '4'); color_type = PNG_COLOR_TYPE_GRAY; + get_token(pnm_file, width_token); + sscanf (width_token, "%lu", &ul_width); + width = (png_uint_32) ul_width; + get_token(pnm_file, height_token); + sscanf (height_token, "%lu", &ul_height); + height = (png_uint_32) ul_height; bit_depth = 1; + packed_bitmap = TRUE; } else if ((type_token[1] == '2') || (type_token[1] == '5')) { @@ -343,8 +351,12 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, alpha_present = (channels - 1) % 2; - /* row_bytes is the width x number of channels x (bit-depth / 8) */ - row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2); + if (packed_bitmap) + /* row data is as many bytes as can fit width x channels x bit_depth */ + row_bytes = (width * channels * bit_depth + 7) / 8; + else + /* row_bytes is the width x number of channels x (bit-depth / 8) */ + row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2); if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL) return FALSE; @@ -354,40 +366,45 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, for (row = 0; row < height; row++) { - for (col = 0; col < width; col++) - { - for (i = 0; i < (channels - alpha_present); i++) + if (packed_bitmap) { + for (i = 0; i < row_bytes; i++) + /* png supports this format natively so no conversion is needed */ + *pix_ptr++ = get_data (pnm_file, 8); + } else { + for (col = 0; col < width; col++) { - if (raw) - *pix_ptr++ = get_data (pnm_file, bit_depth); - else - if (bit_depth <= 8) - *pix_ptr++ = get_value (pnm_file, bit_depth); + for (i = 0; i < (channels - alpha_present); i++) + { + if (raw) + *pix_ptr++ = get_data (pnm_file, bit_depth); else - { - tmp16 = get_value (pnm_file, bit_depth); - *pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF); - pix_ptr++; - *pix_ptr = (png_byte) (tmp16 & 0xFF); - pix_ptr++; - } - } - - if (alpha) /* read alpha-channel from pgm file */ - { - if (alpha_raw) - *pix_ptr++ = get_data (alpha_file, alpha_depth); - else - if (alpha_depth <= 8) - *pix_ptr++ = get_value (alpha_file, bit_depth); + if (bit_depth <= 8) + *pix_ptr++ = get_value (pnm_file, bit_depth); + else + { + tmp16 = get_value (pnm_file, bit_depth); + *pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF); + pix_ptr++; + *pix_ptr = (png_byte) (tmp16 & 0xFF); + pix_ptr++; + } + } + + if (alpha) /* read alpha-channel from pgm file */ + { + if (alpha_raw) + *pix_ptr++ = get_data (alpha_file, alpha_depth); else - { - tmp16 = get_value (alpha_file, bit_depth); - *pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF); - *pix_ptr++ = (png_byte) (tmp16 & 0xFF); - } - } /* if alpha */ - + if (alpha_depth <= 8) + *pix_ptr++ = get_value (alpha_file, bit_depth); + else + { + tmp16 = get_value (alpha_file, bit_depth); + *pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF); + *pix_ptr++ = (png_byte) (tmp16 & 0xFF); + } + } /* if alpha */ + } /* if packed_bitmap */ } /* end for col */ } /* end for row */ @@ -404,6 +421,12 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, return FALSE; } + if (packed_bitmap == TRUE) + { + png_set_packing (png_ptr); + png_set_invert_mono (png_ptr); + } + /* setjmp() must be called in every function that calls a PNG-reading libpng function */ if (setjmp (png_jmpbuf(png_ptr))) {