From 080fecf0e460c9142bde12c152455d7cbdd4cae7 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Thu, 9 May 2013 13:31:37 -0500 Subject: [PATCH] [libpng15] Allow contrib/pnminus/pnm2png.c to compile without WRITE_INVERT and WRITE_PACK supported (writes error message that it can't read P1 or P4 PBM files). --- ANNOUNCE | 20 ++++++++++++-------- CHANGES | 4 ++++ contrib/pngminim/encoder/pngusr.dfa | 1 + contrib/pngminus/pnm2png.c | 18 ++++++++++++++++-- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index b455312b5..c139a4619 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.5.16beta05 - May 9, 2013 +Libpng 1.5.16beta06 - May 9, 2013 This is not intended to be a public release. It will be replaced within a few weeks by a public version or by another test version. @@ -9,20 +9,20 @@ Files available for download: Source files with LF line endings (for Unix/Linux) and with a "configure" script - 1.5.16beta05.tar.xz (LZMA-compressed, recommended) - 1.5.16beta05.tar.gz - 1.5.16beta05.tar.bz2 + 1.5.16beta06.tar.xz (LZMA-compressed, recommended) + 1.5.16beta06.tar.gz + 1.5.16beta06.tar.bz2 Source files with CRLF line endings (for Windows), without the "configure" script - lp1516b05.7z (LZMA-compressed, recommended) - lp1516b05.zip + lp1516b06.7z (LZMA-compressed, recommended) + lp1516b06.zip Other information: - 1.5.16beta05-README.txt - 1.5.16beta05-LICENSE.txt + 1.5.16beta06-README.txt + 1.5.16beta06-LICENSE.txt Changes since the last public release (1.5.15): @@ -55,6 +55,10 @@ Version 1.5.16beta05 [May 9, 2013] Initialize dimension values so if sscanf fails at least we have known invalid values. +Version 1.5.16beta06 [May 9, 2013] + Allow contrib/pnminus/pnm2png.c to compile without WRITE_INVERT and WRITE_PACK + supported (writes error message that it can't read P1 or P4 PBM files). + Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit https://lists.sourceforge.net/lists/listinfo/png-mng-implement diff --git a/CHANGES b/CHANGES index cb9437dbb..d65905512 100644 --- a/CHANGES +++ b/CHANGES @@ -4099,6 +4099,10 @@ Version 1.5.16beta05 [May 9, 2013] Initialize dimension values so if sscanf fails at least we have known invalid values. +Version 1.5.16beta06 [May 9, 2013] + Allow contrib/pnminus/pnm2png.c to compile without WRITE_INVERT and WRITE_PACK + supported (writes error message that it can't read P1 or P4 PBM files). + Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit https://lists.sourceforge.net/lists/listinfo/png-mng-implement diff --git a/contrib/pngminim/encoder/pngusr.dfa b/contrib/pngminim/encoder/pngusr.dfa index 3f1b0214c..b6cf53daa 100644 --- a/contrib/pngminim/encoder/pngusr.dfa +++ b/contrib/pngminim/encoder/pngusr.dfa @@ -13,6 +13,7 @@ everything = off # Switch on the write code - this makes a minimalist encoder option WRITE on +# These 2 options are required if you need to read PGM (P1 or P4) PGM files. option WRITE_INVERT on option WRITE_PACK on diff --git a/contrib/pngminus/pnm2png.c b/contrib/pngminus/pnm2png.c index 932e12877..fe7add9d9 100644 --- a/contrib/pngminus/pnm2png.c +++ b/contrib/pngminus/pnm2png.c @@ -206,7 +206,9 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, int alpha_present; int row, col; BOOL raw, alpha_raw = FALSE; +#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) BOOL packed_bitmap = FALSE; +#endif png_uint_32 tmp16; int i; @@ -219,6 +221,7 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, } else if ((type_token[1] == '1') || (type_token[1] == '4')) { +#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) raw = (type_token[1] == '4'); color_type = PNG_COLOR_TYPE_GRAY; get_token(pnm_file, width_token); @@ -227,6 +230,10 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, sscanf (height_token, "%lu", &height); bit_depth = 1; packed_bitmap = TRUE; +#else + fprintf (stderr, "PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and \n"); + fprintf (stderr, "PNG_WRITE_PACK_SUPPORTED can't read PBM (P1,P4) files\n"); +#endif } else if ((type_token[1] == '2') || (type_token[1] == '5')) { @@ -335,10 +342,12 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, alpha_present = (channels - 1) % 2; +#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) 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 +#endif /* row_bytes is the width x number of channels x (bit-depth / 8) */ row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2); @@ -350,11 +359,14 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, for (row = 0; row < height; row++) { +#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) 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 { + } else +#endif + { for (col = 0; col < width; col++) { for (i = 0; i < (channels - alpha_present); i++) @@ -405,11 +417,13 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, return FALSE; } +#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) if (packed_bitmap == TRUE) { png_set_packing (png_ptr); png_set_invert_mono (png_ptr); } +#endif /* setjmp() must be called in every function that calls a PNG-reading libpng function */ if (setjmp (png_jmpbuf(png_ptr))) @@ -446,7 +460,7 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, /* write out the entire image data in one call */ png_write_image (png_ptr, row_pointers); - /* write the additional chuncks to the PNG file (not really needed) */ + /* write the additional chunks to the PNG file (not really needed) */ png_write_end (png_ptr, info_ptr); /* clean up after the write, and free any memory allocated */