[libpng15] Merge with libpng16/pngtest.c, pngvalid.c, gregbook, pngminim

This commit is contained in:
Glenn Randers-Pehrson 2016-10-30 08:09:54 -05:00
parent b555c55c6d
commit 5a945f3393
20 changed files with 330 additions and 282 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.5.28beta01 - August 18, 2016 Libpng 1.5.28beta01 - October 30, 2016
This is not intended to be a public release. It will be replaced 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. within a few weeks by a public version or by another test version.
@ -26,8 +26,8 @@ Other information:
Changes since the last public release (1.5.27): Changes since the last public release (1.5.27):
version 1.5.28beta01 [August 18, 2016] version 1.5.28beta01 [October 30, 2016]
Merge with current libpng16 pngvalid.c Merge with current libpng16 gregbook, pngvalid.c, pngtest.c
Fixed undefined behavior in png_push_save_buffer(). Do not call Fixed undefined behavior in png_push_save_buffer(). Do not call
memcpy() with a null source, even if count is zero (Leon Scroggins III). memcpy() with a null source, even if count is zero (Leon Scroggins III).
Added "Common linking failures" section to INSTALL. Added "Common linking failures" section to INSTALL.

View File

@ -4496,8 +4496,8 @@ version 1.5.27rc01 [May 14, 2016]
version 1.5.27 [May 26, 2016] version 1.5.27 [May 26, 2016]
No changes. No changes.
version 1.5.28beta01 [August 18, 2016] version 1.5.28beta01 [October 30, 2016]
Merge with current libpng16 pngvalid.c Merge with current libpng16 gregbook, pngvalid.c, pngtest.c
Fixed undefined behavior in png_push_save_buffer(). Do not call Fixed undefined behavior in png_push_save_buffer(). Do not call
memcpy() with a null source, even if count is zero (Leon Scroggins III). memcpy() with a null source, even if count is zero (Leon Scroggins III).
Added "Common linking failures" section to INSTALL. Added "Common linking failures" section to INSTALL.

View File

@ -59,15 +59,16 @@ INCS = $(PNGINC) $(ZINC) $(XINC)
RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm
RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm
WLIBSd = $(PNGLIBd) $(ZLIBd) -lm WLIBSd = $(PNGLIBd) $(ZLIBd) -lm
WLIBSs = $(PNGLIBs) $(ZLIBs) WLIBSs = $(PNGLIBs) $(ZLIBs) -lm
CC = gcc CC = gcc
LD = gcc LD = gcc
RM = rm -f RM = rm -f
CPPFLAGS = $(INCS) -DFEATURE_LOOP CPPFLAGS = $(INCS) -DFEATURE_LOOP
CFLAGS = -O -Wall CFLAGS = -O -Wall
#CFLAGS = -O -W -Wall -Wextra -pedantic -ansi
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")] # [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
# [-ansi, -pedantic and -W can also be used] # [-ansi, -pedantic, -Wextra, and -W can also be used]
LDFLAGS = LDFLAGS =
O = .o O = .o
E = E =

View File

@ -15,7 +15,7 @@ of PBMPLUS/NetPBM) and converts them to PNG.
The source code for all three demo programs currently compiles under The source code for all three demo programs currently compiles under
Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser, Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser,
zinser@decus.de, for making the necessary changes for OpenVMS and for zinser at decus.de, for making the necessary changes for OpenVMS and for
providing an appropriate build script.) Build instructions can be found providing an appropriate build script.) Build instructions can be found
below. below.

View File

@ -100,7 +100,8 @@ int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
/* could pass pointers to user-defined error handlers instead of NULLs: */ /* could pass pointers to user-defined error handlers instead of NULLs: */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_ptr = png_create_read_struct(png_get_libpng_ver(NULL), NULL, NULL,
NULL);
if (!png_ptr) if (!png_ptr)
return 4; /* out of memory */ return 4; /* out of memory */

View File

@ -4,7 +4,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. Copyright (c) 1998-2015 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind, This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors express or implied. In no event shall the author or contributors
@ -51,6 +51,11 @@
along with this program; if not, write to the Free Software Foundation, along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
---------------------------------------------------------------------------
Changelog:
2015-11-12 - Check return value of png_get_bKGD() (Glenn R-P)
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
@ -69,6 +74,7 @@ static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass); png_uint_32 row_num, int pass);
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr); static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg); static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);
static void readpng2_warning_handler(png_structp png_ptr, png_const_charp msg);
@ -103,8 +109,8 @@ int readpng2_init(mainprog_info *mainprog_ptr)
/* could also replace libpng warning-handler (final NULL), but no need: */ /* could also replace libpng warning-handler (final NULL), but no need: */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, png_ptr = png_create_read_struct(png_get_libpng_ver(NULL), mainprog_ptr,
readpng2_error_handler, NULL); readpng2_error_handler, readpng2_warning_handler);
if (!png_ptr) if (!png_ptr)
return 4; /* out of memory */ return 4; /* out of memory */
@ -136,29 +142,23 @@ int readpng2_init(mainprog_info *mainprog_ptr)
* used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT, * used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT,
* IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */ * IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */
{ {
/* These byte strings were copied from png.h. If a future libpng /* These byte strings were copied from png.h. If a future version
* version recognizes more chunks, add them to this list. If a * of readpng2.c recognizes more chunks, add them to this list.
* future version of readpng2.c recognizes more chunks, delete them */
* from this list. */ static PNG_CONST png_byte chunks_to_process[] = {
static /* const */ png_byte chunks_to_ignore[] = { 98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */ 103, 65, 77, 65, '\0', /* gAMA */
104, 73, 83, 84, '\0', /* hIST */ 115, 82, 71, 66, '\0', /* sRGB */
105, 67, 67, 80, '\0', /* iCCP */ };
105, 84, 88, 116, '\0', /* iTXt */
111, 70, 70, 115, '\0', /* oFFs */
112, 67, 65, 76, '\0', /* pCAL */
112, 72, 89, 115, '\0', /* pHYs */
115, 66, 73, 84, '\0', /* sBIT */
115, 67, 65, 76, '\0', /* sCAL */
115, 80, 76, 84, '\0', /* sPLT */
115, 84, 69, 82, '\0', /* sTER */
116, 69, 88, 116, '\0', /* tEXt */
116, 73, 77, 69, '\0', /* tIME */
122, 84, 88, 116, '\0' /* zTXt */
};
png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */, /* Ignore all chunks except for IHDR, PLTE, tRNS, IDAT, and IEND */
chunks_to_ignore, sizeof(chunks_to_ignore)/5); png_set_keep_unknown_chunks(png_ptr, -1 /* PNG_HANDLE_CHUNK_NEVER */,
NULL, -1);
/* But do not ignore chunks in the "chunks_to_process" list */
png_set_keep_unknown_chunks(png_ptr,
0 /* PNG_HANDLE_CHUNK_AS_DEFAULT */, chunks_to_process,
sizeof(chunks_to_process)/5);
} }
#endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */ #endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */
@ -266,36 +266,38 @@ static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)
/* since we know we've read all of the PNG file's "header" (i.e., up /* since we know we've read all of the PNG file's "header" (i.e., up
* to IDAT), we can check for a background color here */ * to IDAT), we can check for a background color here */
if (mainprog_ptr->need_bgcolor && if (mainprog_ptr->need_bgcolor)
png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
{ {
png_color_16p pBackground; png_color_16p pBackground;
/* it is not obvious from the libpng documentation, but this function /* it is not obvious from the libpng documentation, but this function
* takes a pointer to a pointer, and it always returns valid red, * takes a pointer to a pointer, and it always returns valid red,
* green and blue values, regardless of color_type: */ * green and blue values, regardless of color_type: */
png_get_bKGD(png_ptr, info_ptr, &pBackground); if (png_get_bKGD(png_ptr, info_ptr, &pBackground))
{
/* however, it always returns the raw bKGD data, regardless of any /* however, it always returns the raw bKGD data, regardless of any
* bit-depth transformations, so check depth and adjust if necessary */ * bit-depth transformations, so check depth and adjust if necessary
if (bit_depth == 16) { */
mainprog_ptr->bg_red = pBackground->red >> 8; if (bit_depth == 16) {
mainprog_ptr->bg_green = pBackground->green >> 8; mainprog_ptr->bg_red = pBackground->red >> 8;
mainprog_ptr->bg_blue = pBackground->blue >> 8; mainprog_ptr->bg_green = pBackground->green >> 8;
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { mainprog_ptr->bg_blue = pBackground->blue >> 8;
if (bit_depth == 1) } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
mainprog_ptr->bg_red = mainprog_ptr->bg_green = if (bit_depth == 1)
mainprog_ptr->bg_blue = pBackground->gray? 255 : 0; mainprog_ptr->bg_red = mainprog_ptr->bg_green =
else if (bit_depth == 2) mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
mainprog_ptr->bg_red = mainprog_ptr->bg_green = else if (bit_depth == 2)
mainprog_ptr->bg_blue = (255/3) * pBackground->gray; mainprog_ptr->bg_red = mainprog_ptr->bg_green =
else /* bit_depth == 4 */ mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
mainprog_ptr->bg_red = mainprog_ptr->bg_green = else /* bit_depth == 4 */
mainprog_ptr->bg_blue = (255/15) * pBackground->gray; mainprog_ptr->bg_red = mainprog_ptr->bg_green =
} else { mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
mainprog_ptr->bg_red = (uch)pBackground->red; } else {
mainprog_ptr->bg_green = (uch)pBackground->green; mainprog_ptr->bg_red = (uch)pBackground->red;
mainprog_ptr->bg_blue = (uch)pBackground->blue; mainprog_ptr->bg_green = (uch)pBackground->green;
mainprog_ptr->bg_blue = (uch)pBackground->blue;
}
} }
} }
@ -453,6 +455,8 @@ static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
/* all done */ /* all done */
(void)info_ptr; /* Unused */
return; return;
} }
@ -473,7 +477,12 @@ void readpng2_cleanup(mainprog_info *mainprog_ptr)
} }
static void readpng2_warning_handler(png_structp png_ptr, png_const_charp msg)
{
fprintf(stderr, "readpng2 libpng warning: %s\n", msg);
fflush(stderr);
(void)png_ptr; /* Unused */
}
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg) static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)

View File

@ -163,8 +163,12 @@ uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
/* now we can go ahead and just read the whole image */ /* now we can go ahead and just read the whole image */
fread(image_data, 1L, rowbytes*height, saved_infile); if (fread(image_data, 1L, rowbytes*height, saved_infile) <
rowbytes*height) {
free (image_data);
image_data = NULL;
return NULL;
}
return image_data; return image_data;
} }

View File

@ -182,7 +182,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
#ifndef __CYGWIN__ #ifndef __CYGWIN__
/* First reenable console output, which normally goes to the bit bucket /* First reenable console output, which normally goes to the bit bucket
* for windowed apps. Closing the console window will terminate the * for windowed apps. Closing the console window will terminate the
* app. Thanks to David.Geldreich@realviz.com for supplying the magical * app. Thanks to David.Geldreich at realviz.com for supplying the magical
* incantation. */ * incantation. */
AllocConsole(); AllocConsole();

View File

@ -26,6 +26,8 @@
- 1.14: added support for X resources (thanks to Gerhard Niklasch) - 1.14: added support for X resources (thanks to Gerhard Niklasch)
- 2.00: dual-licensed (added GNU GPL) - 2.00: dual-licensed (added GNU GPL)
- 2.01: fixed improper display of usage screen on PNG error(s) - 2.01: fixed improper display of usage screen on PNG error(s)
- 2.02: Added "void(argc);" statement to quiet pedantic compiler warnings
about unused variable (GR-P)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@ -80,7 +82,7 @@
#define PROGNAME "rpng-x" #define PROGNAME "rpng-x"
#define LONGNAME "Simple PNG Viewer for X" #define LONGNAME "Simple PNG Viewer for X"
#define VERSION "2.01 of 16 March 2008" #define VERSION "2.02 of 15 June 2014"
#define RESNAME "rpng" /* our X resource application name */ #define RESNAME "rpng" /* our X resource application name */
#define RESCLASS "Rpng" /* our X resource class name */ #define RESCLASS "Rpng" /* our X resource class name */
@ -279,15 +281,17 @@ int main(int argc, char **argv)
"Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n" "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n"
" xdpy\tname of the target X display (e.g., ``hostname:0'')\n" " xdpy\tname of the target X display (e.g., ``hostname:0'')\n"
" exp \ttransfer-function exponent (``gamma'') of the display\n" " exp \ttransfer-function exponent (``gamma'') of the display\n"
"\t\t system in floating-point format (e.g., ``%.1f''); equal\n" "\t\t system in floating-point format (e.g., ``%.1f''); equal\n",
PROGNAME, default_display_exponent);
fprintf(stderr, "\n"
"\t\t to the product of the lookup-table exponent (varies)\n" "\t\t to the product of the lookup-table exponent (varies)\n"
"\t\t and the CRT exponent (usually 2.2); must be positive\n" "\t\t and the CRT exponent (usually 2.2); must be positive\n"
" bg \tdesired background color in 7-character hex RGB format\n" " bg \tdesired background color in 7-character hex RGB format\n"
"\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
"\t\t used with transparent images\n" "\t\t used with transparent images\n"
"\nPress Q, Esc or mouse button 1 (within image window, after image\n" "\nPress Q, Esc or mouse button 1 (within image window, after image\n"
"is displayed) to quit.\n" "is displayed) to quit.\n");
"\n", PROGNAME, default_display_exponent);
exit(1); exit(1);
} }
@ -419,6 +423,8 @@ int main(int argc, char **argv)
rpng_x_cleanup(); rpng_x_cleanup();
(void)argc; /* Unused */
return 0; return 0;
} }

View File

@ -33,6 +33,8 @@
- 2.02: fixed improper display of usage screen on PNG error(s); fixed - 2.02: fixed improper display of usage screen on PNG error(s); fixed
unexpected-EOF and file-read-error cases unexpected-EOF and file-read-error cases
- 2.03: removed runtime MMX-enabling/disabling and obsolete -mmx* options - 2.03: removed runtime MMX-enabling/disabling and obsolete -mmx* options
- 2.04:
(GR-P)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@ -299,7 +301,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
#ifndef __CYGWIN__ #ifndef __CYGWIN__
/* Next reenable console output, which normally goes to the bit bucket /* Next reenable console output, which normally goes to the bit bucket
* for windowed apps. Closing the console window will terminate the * for windowed apps. Closing the console window will terminate the
* app. Thanks to David.Geldreich@realviz.com for supplying the magical * app. Thanks to David.Geldreich at realviz.com for supplying the magical
* incantation. */ * incantation. */
AllocConsole(); AllocConsole();

View File

@ -90,7 +90,7 @@ int writepng_init(mainprog_info *mainprog_ptr)
/* could also replace libpng warning-handler (final NULL), but no need: */ /* could also replace libpng warning-handler (final NULL), but no need: */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, png_ptr = png_create_write_struct(png_get_libpng_ver(NULL), mainprog_ptr,
writepng_error_handler, NULL); writepng_error_handler, NULL);
if (!png_ptr) if (!png_ptr)
return 4; /* out of memory */ return 4; /* out of memory */

View File

@ -1,9 +1,8 @@
/* pngvalid.c - validate libpng by constructing then reading png files. /* pngvalid.c - validate libpng by constructing then reading png files.
* *
* Last changed in libpng 1.6.24 [(PENDING RELEASE)] * Last changed in libpng 1.6.26 [October 20, 2016]
* Copyright (c) 2014-2016 Glenn Randers-Pehrson * Copyright (c) 2014-2016 John Cunningham Bowler
* Written by John Cunningham Bowler
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer * For conditions of distribution and use, see the disclaimer
@ -1115,7 +1114,7 @@ store_warning(png_structp ppIn, png_const_charp message)
if (!ps->expect_warning) if (!ps->expect_warning)
store_log(ps, pp, message, 0 /* warning */); store_log(ps, pp, message, 0 /* warning */);
else else
ps->saw_warning = 1; ps->saw_warning = 1;
} }
/* These somewhat odd functions are used when reading an image to ensure that /* These somewhat odd functions are used when reading an image to ensure that
@ -1242,7 +1241,7 @@ store_image_check(const png_store* ps, png_const_structp pp, int iImage)
image += 2; /* skip image first row markers */ image += 2; /* skip image first row markers */
while (rows-- > 0) for (; rows > 0; --rows)
{ {
if (image[-2] != 190 || image[-1] != 239) if (image[-2] != 190 || image[-1] != 239)
png_error(pp, "row start overwritten"); png_error(pp, "row start overwritten");
@ -11427,23 +11426,36 @@ perform_interlace_macro_validation(void)
*/ */
for (v=0;;) for (v=0;;)
{ {
/* The first two tests overflow if the pass row or column is outside
* the possible range for a 32-bit result. In fact the values should
* never be outside the range for a 31-bit result, but checking for 32
* bits here ensures that if an app uses a bogus pass row or column
* (just so long as it fits in a 32 bit integer) it won't get a
* possibly dangerous overflow.
*/
/* First the base 0 stuff: */ /* First the base 0 stuff: */
m = PNG_ROW_FROM_PASS_ROW(v, pass); if (v < png_pass_rows(0xFFFFFFFFU, pass))
f = png_row_from_pass_row(v, pass);
if (m != f)
{ {
fprintf(stderr, "PNG_ROW_FROM_PASS_ROW(%u, %d) = %u != %x\n", m = PNG_ROW_FROM_PASS_ROW(v, pass);
v, pass, m, f); f = png_row_from_pass_row(v, pass);
exit(99); if (m != f)
{
fprintf(stderr, "PNG_ROW_FROM_PASS_ROW(%u, %d) = %u != %x\n",
v, pass, m, f);
exit(99);
}
} }
m = PNG_COL_FROM_PASS_COL(v, pass); if (v < png_pass_cols(0xFFFFFFFFU, pass))
f = png_col_from_pass_col(v, pass);
if (m != f)
{ {
fprintf(stderr, "PNG_COL_FROM_PASS_COL(%u, %d) = %u != %x\n", m = PNG_COL_FROM_PASS_COL(v, pass);
v, pass, m, f); f = png_col_from_pass_col(v, pass);
exit(99); if (m != f)
{
fprintf(stderr, "PNG_COL_FROM_PASS_COL(%u, %d) = %u != %x\n",
v, pass, m, f);
exit(99);
}
} }
m = PNG_ROW_IN_INTERLACE_PASS(v, pass); m = PNG_ROW_IN_INTERLACE_PASS(v, pass);

View File

@ -1,3 +1,4 @@
This demonstrates the use of PNG_USER_CONFIG, pngusr.h and pngusr.dfa This demonstrates the use of PNG_USER_CONFIG, pngusr.h and pngusr.dfa
to build minimal decoder, encoder, and progressive reader applications. to build minimal decoder, encoder, and progressive reader applications.

View File

@ -1,6 +1,6 @@
# pngminim/decoder/pngusr.dfa # pngminim/decoder/pngusr.dfa
# #
# Copyright (c) 2010-2011 Glenn Randers-Pehrson # Copyright (c) 2010-2013 Glenn Randers-Pehrson
# #
# This code is released under the libpng license. # This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer # For conditions of distribution and use, see the disclaimer
@ -37,3 +37,4 @@ option SETJMP on
option STDIO on option STDIO on
option READ_EXPAND on option READ_EXPAND on
option READ_STRIP_16_TO_8 on option READ_STRIP_16_TO_8 on
option USER_LIMITS on

View File

@ -1,6 +1,6 @@
/* minrdpngconf.h: headers to make a minimal png-read-only library /* minrdpngconf.h: headers to make a minimal png-read-only library
* *
* Copyright (c) 2007, 2010-2011 Glenn Randers-Pehrson * Copyright (c) 2007, 2010-2013 Glenn Randers-Pehrson
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer * For conditions of distribution and use, see the disclaimer
@ -18,7 +18,6 @@
* affect the API (so are not recorded in pnglibconf.h) * affect the API (so are not recorded in pnglibconf.h)
*/ */
#define PNG_NO_WARNINGS
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE #define PNG_ALIGN_TYPE PNG_ALIGN_NONE
#endif /* MINRDPNGCONF_H */ #endif /* MINRDPNGCONF_H */

View File

@ -13,7 +13,8 @@ everything = off
# Switch on the write code - this makes a minimalist encoder # Switch on the write code - this makes a minimalist encoder
option WRITE on option WRITE on
# These 2 options are required if you need to read PGM (P1 or P4) PGM files.
# These 2 options are required if you need to read PBM (P1 or P4) files.
option WRITE_INVERT on option WRITE_INVERT on
option WRITE_PACK on option WRITE_PACK on

View File

@ -1,6 +1,6 @@
/* minwrpngconf.h: headers to make a minimal png-write-only library /* minwrpngconf.h: headers to make a minimal png-write-only library
* *
* Copyright (c) 2007, 2010-2011 Glenn Randers-Pehrson * Copyright (c) 2007, 2010-2013 Glenn Randers-Pehrson
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer * For conditions of distribution and use, see the disclaimer
@ -18,7 +18,6 @@
* affect the API (so are not recorded in pnglibconf.h) * affect the API (so are not recorded in pnglibconf.h)
*/ */
#define PNG_NO_WARNINGS
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE #define PNG_ALIGN_TYPE PNG_ALIGN_NONE
#endif /* MINWRPNGCONF_H */ #endif /* MINWRPNGCONF_H */

View File

@ -1,6 +1,6 @@
# pngminim/preader/pngusr.dfa # pngminim/preader/pngusr.dfa
# #
# Copyright (c) 2010-2011 Glenn Randers-Pehrson # Copyright (c) 2010-2013 Glenn Randers-Pehrson
# #
# This code is released under the libpng license. # This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer # For conditions of distribution and use, see the disclaimer

View File

@ -1,6 +1,6 @@
/* minrdpngconf.h: headers to make a minimal png-read-only library /* minrdpngconf.h: headers to make a minimal png-read-only library
* *
* Copyright (c) 2009, 2010-2011 Glenn Randers-Pehrson * Copyright (c) 2009, 2010-2013 Glenn Randers-Pehrson
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer * For conditions of distribution and use, see the disclaimer
@ -18,7 +18,6 @@
* affect the API (so are not recorded in pnglibconf.h) * affect the API (so are not recorded in pnglibconf.h)
*/ */
#define PNG_NO_WARNINGS
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE #define PNG_ALIGN_TYPE PNG_ALIGN_NONE
#endif /* MINPRDPNGCONF_H */ #endif /* MINPRDPNGCONF_H */

391
pngtest.c
View File

@ -1,8 +1,8 @@
/* pngtest.c - a simple test program to test libpng /* pngtest.c - a simple test program to test libpng
* *
* Last changed in libpng 1.5.25 [December 3, 2015] * Last changed in libpng 1.6.26 [October 20, 2016]
* Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@ -130,13 +130,13 @@ static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
static int static int
tIME_to_str(png_structp png_ptr, png_charp ts, png_const_timep t) tIME_to_str(png_structp png_ptr, png_charp ts, png_const_timep t)
{ {
png_const_charp str = png_convert_to_rfc1123(png_ptr, t); png_const_charp str = png_convert_to_rfc1123(png_ptr, t);
if (str == NULL) if (str == NULL)
return 0; return 0;
strcpy(ts, str); strcpy(ts, str);
return 1; return 1;
} }
#endif /* older libpng */ #endif /* older libpng */
#endif #endif
@ -240,95 +240,95 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
* png_byte pixel_depth bits per pixel (depth*channels) * png_byte pixel_depth bits per pixel (depth*channels)
*/ */
/* Counts the number of zero samples (or zero pixels if color_type is 3 */ /* Counts the number of zero samples (or zero pixels if color_type is 3 */
if (row_info->color_type == 0 || row_info->color_type == 3) if (row_info->color_type == 0 || row_info->color_type == 3)
{ {
int pos = 0; int pos = 0;
png_uint_32 n, nstop; png_uint_32 n, nstop;
for (n = 0, nstop=row_info->width; n<nstop; n++) for (n = 0, nstop=row_info->width; n<nstop; n++)
{ {
if (row_info->bit_depth == 1) if (row_info->bit_depth == 1)
{ {
if (((*dp << pos++ ) & 0x80) == 0) if (((*dp << pos++ ) & 0x80) == 0)
zero_samples++; zero_samples++;
if (pos == 8) if (pos == 8)
{ {
pos = 0; pos = 0;
dp++; dp++;
} }
} }
if (row_info->bit_depth == 2) if (row_info->bit_depth == 2)
{ {
if (((*dp << (pos+=2)) & 0xc0) == 0) if (((*dp << (pos+=2)) & 0xc0) == 0)
zero_samples++; zero_samples++;
if (pos == 8) if (pos == 8)
{ {
pos = 0; pos = 0;
dp++; dp++;
} }
} }
if (row_info->bit_depth == 4) if (row_info->bit_depth == 4)
{ {
if (((*dp << (pos+=4)) & 0xf0) == 0) if (((*dp << (pos+=4)) & 0xf0) == 0)
zero_samples++; zero_samples++;
if (pos == 8) if (pos == 8)
{ {
pos = 0; pos = 0;
dp++; dp++;
} }
} }
if (row_info->bit_depth == 8) if (row_info->bit_depth == 8)
if (*dp++ == 0) if (*dp++ == 0)
zero_samples++; zero_samples++;
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
{ {
if ((*dp | *(dp+1)) == 0) if ((*dp | *(dp+1)) == 0)
zero_samples++; zero_samples++;
dp+=2; dp+=2;
} }
} }
} }
else /* Other color types */ else /* Other color types */
{ {
png_uint_32 n, nstop; png_uint_32 n, nstop;
int channel; int channel;
int color_channels = row_info->channels; int color_channels = row_info->channels;
if (row_info->color_type > 3) if (row_info->color_type > 3)
color_channels--; color_channels--;
for (n = 0, nstop=row_info->width; n<nstop; n++) for (n = 0, nstop=row_info->width; n<nstop; n++)
{ {
for (channel = 0; channel < color_channels; channel++) for (channel = 0; channel < color_channels; channel++)
{ {
if (row_info->bit_depth == 8) if (row_info->bit_depth == 8)
if (*dp++ == 0) if (*dp++ == 0)
zero_samples++; zero_samples++;
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
{ {
if ((*dp | *(dp+1)) == 0) if ((*dp | *(dp+1)) == 0)
zero_samples++; zero_samples++;
dp+=2; dp+=2;
} }
} }
if (row_info->color_type > 3) if (row_info->color_type > 3)
{ {
dp++; dp++;
if (row_info->bit_depth == 16) if (row_info->bit_depth == 16)
dp++; dp++;
} }
} }
} }
} }
#endif /* WRITE_USER_TRANSFORM */ #endif /* WRITE_USER_TRANSFORM */
@ -345,10 +345,10 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
#ifdef PNG_IO_STATE_SUPPORTED #ifdef PNG_IO_STATE_SUPPORTED
void void
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length, pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
png_uint_32 io_op); png_uint_32 io_op);
void void
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length, pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
png_uint_32 io_op) png_uint_32 io_op)
{ {
png_uint_32 io_state = png_get_io_state(png_ptr); png_uint_32 io_state = png_get_io_state(png_ptr);
int err = 0; int err = 0;
@ -532,7 +532,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
memory_infop pinfo; memory_infop pinfo;
png_set_mem_fn(png_ptr, NULL, NULL, NULL); png_set_mem_fn(png_ptr, NULL, NULL, NULL);
pinfo = (memory_infop)png_malloc(png_ptr, pinfo = (memory_infop)png_malloc(png_ptr,
(sizeof *pinfo)); (sizeof *pinfo));
pinfo->size = size; pinfo->size = size;
current_allocation += size; current_allocation += size;
total_allocation += size; total_allocation += size;
@ -562,7 +562,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
if (verbose != 0) if (verbose != 0)
printf("png_malloc %lu bytes at %p\n", (unsigned long)size, printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
pinfo->pointer); pinfo->pointer);
return (png_voidp)(pinfo->pointer); return (png_voidp)(pinfo->pointer);
} }
@ -769,9 +769,9 @@ write_vpAg_chunk(png_structp write_ptr)
if (verbose != 0) if (verbose != 0)
fprintf(STDERR, " vpAg = %lu x %lu, units = %d\n", fprintf(STDERR, " vpAg = %lu x %lu, units = %d\n",
(unsigned long)user_chunk_data.vpAg_width, (unsigned long)user_chunk_data.vpAg_width,
(unsigned long)user_chunk_data.vpAg_height, (unsigned long)user_chunk_data.vpAg_height,
user_chunk_data.vpAg_units); user_chunk_data.vpAg_units);
png_save_uint_32(vpag_chunk_data, user_chunk_data.vpAg_width); png_save_uint_32(vpag_chunk_data, user_chunk_data.vpAg_width);
png_save_uint_32(vpag_chunk_data + 4, user_chunk_data.vpAg_height); png_save_uint_32(vpag_chunk_data + 4, user_chunk_data.vpAg_height);
@ -812,7 +812,7 @@ write_chunks(png_structp write_ptr, int location)
#ifdef PNG_TEXT_SUPPORTED #ifdef PNG_TEXT_SUPPORTED
static void static void
pngtest_check_text_support(png_structp png_ptr, png_textp text_ptr, pngtest_check_text_support(png_structp png_ptr, png_textp text_ptr,
int num_text) int num_text)
{ {
while (num_text > 0) while (num_text > 0)
{ {
@ -894,26 +894,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
pngtest_debug("Allocating read and write structures"); pngtest_debug("Allocating read and write structures");
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
read_ptr = read_ptr =
png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL, png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
NULL, NULL, NULL, png_debug_malloc, png_debug_free); NULL, NULL, NULL, png_debug_malloc, png_debug_free);
#else #else
read_ptr = read_ptr =
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif #endif
png_set_error_fn(read_ptr, &error_parameters, pngtest_error, png_set_error_fn(read_ptr, &error_parameters, pngtest_error,
pngtest_warning); pngtest_warning);
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
write_ptr = write_ptr =
png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL, png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
NULL, NULL, NULL, png_debug_malloc, png_debug_free); NULL, NULL, NULL, png_debug_malloc, png_debug_free);
#else #else
write_ptr = write_ptr =
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif #endif
png_set_error_fn(write_ptr, &error_parameters, pngtest_error, png_set_error_fn(write_ptr, &error_parameters, pngtest_error,
pngtest_warning); pngtest_warning);
#endif #endif
pngtest_debug("Allocating read_info, write_info and end_info structures"); pngtest_debug("Allocating read_info, write_info and end_info structures");
read_info_ptr = png_create_info_struct(read_ptr); read_info_ptr = png_create_info_struct(read_ptr);
@ -926,7 +926,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
init_callback_info(read_info_ptr); init_callback_info(read_info_ptr);
png_set_read_user_chunk_fn(read_ptr, &user_chunk_data, png_set_read_user_chunk_fn(read_ptr, &user_chunk_data,
read_user_chunk_callback); read_user_chunk_callback);
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
@ -964,15 +964,16 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif #endif
#endif #endif
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
if (strict != 0) if (strict != 0)
{ {
/* Treat png_benign_error() as errors on read */ /* Treat png_benign_error() as errors on read */
png_set_benign_errors(read_ptr, 0); png_set_benign_errors(read_ptr, 0);
#ifdef PNG_WRITE_SUPPORTED # ifdef PNG_WRITE_SUPPORTED
/* Treat them as errors on write */ /* Treat them as errors on write */
png_set_benign_errors(write_ptr, 0); png_set_benign_errors(write_ptr, 0);
#endif # endif
/* if strict is not set, then app warnings and errors are treated as /* if strict is not set, then app warnings and errors are treated as
* warnings in release builds, but not in unstable builds; this can be * warnings in release builds, but not in unstable builds; this can be
@ -985,10 +986,15 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
/* Allow application (pngtest) errors and warnings to pass */ /* Allow application (pngtest) errors and warnings to pass */
png_set_benign_errors(read_ptr, 1); png_set_benign_errors(read_ptr, 1);
#ifdef PNG_WRITE_SUPPORTED /* Turn off CRC and ADLER32 checking while reading */
png_set_crc_action(read_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
# ifdef PNG_WRITE_SUPPORTED
png_set_benign_errors(write_ptr, 1); png_set_benign_errors(write_ptr, 1);
#endif # endif
} }
#endif /* BENIGN_ERRORS */
pngtest_debug("Initializing input and output streams"); pngtest_debug("Initializing input and output streams");
#ifdef PNG_STDIO_SUPPORTED #ifdef PNG_STDIO_SUPPORTED
@ -1001,9 +1007,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
# ifdef PNG_WRITE_SUPPORTED # ifdef PNG_WRITE_SUPPORTED
png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data, png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data,
# ifdef PNG_WRITE_FLUSH_SUPPORTED # ifdef PNG_WRITE_FLUSH_SUPPORTED
pngtest_flush); pngtest_flush);
# else # else
NULL); NULL);
# endif # endif
# endif # endif
#endif #endif
@ -1043,11 +1049,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
*/ */
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED #ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
NULL, 0); NULL, 0);
#endif #endif
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS,
NULL, 0); NULL, 0);
#endif #endif
#endif #endif
@ -1071,7 +1077,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
&color_type, &interlace_type, &compression_type, &filter_type) != 0) &color_type, &interlace_type, &compression_type, &filter_type) != 0)
{ {
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
color_type, interlace_type, compression_type, filter_type); color_type, interlace_type, compression_type, filter_type);
/* num_passes may not be available below if interlace support is not /* num_passes may not be available below if interlace support is not
* provided by libpng for both read and write. * provided by libpng for both read and write.
*/ */
@ -1098,13 +1104,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#ifdef PNG_cHRM_SUPPORTED #ifdef PNG_cHRM_SUPPORTED
{ {
png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x, png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
blue_y; blue_y;
if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,
&red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0) &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
{ {
png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x, png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
red_y, green_x, green_y, blue_x, blue_y); red_y, green_x, green_y, blue_x, blue_y);
} }
} }
#endif #endif
@ -1121,13 +1127,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#ifdef PNG_cHRM_SUPPORTED #ifdef PNG_cHRM_SUPPORTED
{ {
double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
blue_y; blue_y;
if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
&red_y, &green_x, &green_y, &blue_x, &blue_y) != 0) &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
{ {
png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
red_y, green_x, green_y, blue_x, blue_y); red_y, green_x, green_y, blue_x, blue_y);
} }
} }
#endif #endif
@ -1149,10 +1155,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int compression_type; int compression_type;
if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
&profile, &proflen) != 0) &profile, &proflen) != 0)
{ {
png_set_iCCP(write_ptr, write_info_ptr, name, compression_type, png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
profile, proflen); profile, proflen);
} }
} }
#endif #endif
@ -1209,10 +1215,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int type, nparams; int type, nparams;
if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
&nparams, &units, &params) != 0) &nparams, &units, &params) != 0)
{ {
png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
nparams, units, params); nparams, units, params);
} }
} }
#endif #endif
@ -1242,7 +1248,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
double scal_width, scal_height; double scal_width, scal_height;
if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,
&scal_height) != 0) &scal_height) != 0)
{ {
png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);
} }
@ -1254,7 +1260,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_charp scal_width, scal_height; png_charp scal_width, scal_height;
if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,
&scal_height) != 0) &scal_height) != 0)
{ {
png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
scal_height); scal_height);
@ -1295,7 +1301,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
for (i=0; i<num_text; i++) for (i=0; i<num_text; i++)
{ {
printf(" Text compression[%d]=%d\n", printf(" Text compression[%d]=%d\n",
i, text_ptr[i].compression); i, text_ptr[i].compression);
} }
} }
@ -1332,7 +1338,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_color_16p trans_color; png_color_16p trans_color;
if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans, if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,
&trans_color) != 0) &trans_color) != 0)
{ {
int sample_max = (1 << bit_depth); int sample_max = (1 << bit_depth);
/* libpng doesn't reject a tRNS chunk with out-of-range samples */ /* libpng doesn't reject a tRNS chunk with out-of-range samples */
@ -1351,12 +1357,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{ {
png_unknown_chunkp unknowns; png_unknown_chunkp unknowns;
int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr, int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,
&unknowns); &unknowns);
if (num_unknowns != 0) if (num_unknowns != 0)
{ {
png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns, png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
num_unknowns); num_unknowns);
#if PNG_LIBPNG_VER < 10600 #if PNG_LIBPNG_VER < 10600
/* Copy the locations from the read_info_ptr. The automatically /* Copy the locations from the read_info_ptr. The automatically
* generated locations in write_end_info_ptr are wrong prior to 1.6.0 * generated locations in write_end_info_ptr are wrong prior to 1.6.0
@ -1366,7 +1372,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int i; int i;
for (i = 0; i < num_unknowns; i++) for (i = 0; i < num_unknowns; i++)
png_set_unknown_chunk_location(write_ptr, write_info_ptr, i, png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
unknowns[i].location); unknowns[i].location);
} }
#endif #endif
} }
@ -1386,12 +1392,17 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_write_info(write_ptr, write_info_ptr); png_write_info(write_ptr, write_info_ptr);
write_chunks(write_ptr, before_IDAT); /* after PLTE */ write_chunks(write_ptr, before_IDAT); /* after PLTE */
#ifdef PNG_COMPRESSION_COMPAT
/* Test the 'compatibility' setting here, if it is available. */
png_set_compression(write_ptr, PNG_COMPRESSION_COMPAT);
#endif
#endif #endif
#ifdef SINGLE_ROWBUF_ALLOC #ifdef SINGLE_ROWBUF_ALLOC
pngtest_debug("Allocating row buffer..."); pngtest_debug("Allocating row buffer...");
row_buf = (png_bytep)png_malloc(read_ptr, row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr)); png_get_rowbytes(read_ptr, read_info_ptr));
pngtest_debug1("\t0x%08lx", (unsigned long)row_buf); pngtest_debug1("\t0x%08lx", (unsigned long)row_buf);
#endif /* SINGLE_ROWBUF_ALLOC */ #endif /* SINGLE_ROWBUF_ALLOC */
@ -1405,10 +1416,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
*/ */
if (png_set_interlace_handling(read_ptr) != num_passes) if (png_set_interlace_handling(read_ptr) != num_passes)
png_error(write_ptr, png_error(write_ptr,
"png_set_interlace_handling(read): wrong pass count "); "png_set_interlace_handling(read): wrong pass count ");
if (png_set_interlace_handling(write_ptr) != num_passes) if (png_set_interlace_handling(write_ptr) != num_passes)
png_error(write_ptr, png_error(write_ptr,
"png_set_interlace_handling(write): wrong pass count "); "png_set_interlace_handling(write): wrong pass count ");
#else /* png_set_interlace_handling not called on either read or write */ #else /* png_set_interlace_handling not called on either read or write */
# define calc_pass_height # define calc_pass_height
#endif /* not using libpng interlace handling */ #endif /* not using libpng interlace handling */
@ -1445,10 +1456,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y); pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);
row_buf = (png_bytep)png_malloc(read_ptr, row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr)); png_get_rowbytes(read_ptr, read_info_ptr));
pngtest_debug2("\t0x%08lx (%lu bytes)", (unsigned long)row_buf, pngtest_debug2("\t0x%08lx (%lu bytes)", (unsigned long)row_buf,
(unsigned long)png_get_rowbytes(read_ptr, read_info_ptr)); (unsigned long)png_get_rowbytes(read_ptr, read_info_ptr));
#endif /* !SINGLE_ROWBUF_ALLOC */ #endif /* !SINGLE_ROWBUF_ALLOC */
png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1); png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
@ -1506,7 +1517,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
for (i=0; i<num_text; i++) for (i=0; i<num_text; i++)
{ {
printf(" Text compression[%d]=%d\n", printf(" Text compression[%d]=%d\n",
i, text_ptr[i].compression); i, text_ptr[i].compression);
} }
} }
@ -1540,12 +1551,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{ {
png_unknown_chunkp unknowns; png_unknown_chunkp unknowns;
int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr, int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,
&unknowns); &unknowns);
if (num_unknowns != 0) if (num_unknowns != 0)
{ {
png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns, png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
num_unknowns); num_unknowns);
#if PNG_LIBPNG_VER < 10600 #if PNG_LIBPNG_VER < 10600
/* Copy the locations from the read_info_ptr. The automatically /* Copy the locations from the read_info_ptr. The automatically
* generated locations in write_end_info_ptr are wrong prior to 1.6.0 * generated locations in write_end_info_ptr are wrong prior to 1.6.0
@ -1555,7 +1566,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int i; int i;
for (i = 0; i < num_unknowns; i++) for (i = 0; i < num_unknowns; i++)
png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i, png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
unknowns[i].location); unknowns[i].location);
} }
#endif #endif
} }
@ -1589,7 +1600,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
iwidth = png_get_image_width(write_ptr, write_info_ptr); iwidth = png_get_image_width(write_ptr, write_info_ptr);
iheight = png_get_image_height(write_ptr, write_info_ptr); iheight = png_get_image_height(write_ptr, write_info_ptr);
fprintf(STDERR, "\n Image width = %lu, height = %lu\n", fprintf(STDERR, "\n Image width = %lu, height = %lu\n",
(unsigned long)iwidth, (unsigned long)iheight); (unsigned long)iwidth, (unsigned long)iheight);
} }
#endif #endif
@ -1622,7 +1633,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
* above, but this is safe. * above, but this is safe.
*/ */
fprintf(STDERR, "\n %s: %d libpng errors found (%d warnings)", fprintf(STDERR, "\n %s: %d libpng errors found (%d warnings)",
inname, error_count, warning_count); inname, error_count, warning_count);
if (strict != 0) if (strict != 0)
return (1); return (1);
@ -1633,14 +1644,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
else if (unsupported_chunks > 0) else if (unsupported_chunks > 0)
{ {
fprintf(STDERR, "\n %s: unsupported chunks (%d)%s", fprintf(STDERR, "\n %s: unsupported chunks (%d)%s",
inname, unsupported_chunks, strict ? ": IGNORED --strict!" : ""); inname, unsupported_chunks, strict ? ": IGNORED --strict!" : "");
} }
# endif # endif
else if (warning_count > 0) else if (warning_count > 0)
{ {
fprintf(STDERR, "\n %s: %d libpng warnings found", fprintf(STDERR, "\n %s: %d libpng warnings found",
inname, warning_count); inname, warning_count);
if (strict != 0) if (strict != 0)
return (1); return (1);
@ -1676,18 +1687,19 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (num_in != num_out) if (num_in != num_out)
{ {
fprintf(STDERR, "\nFiles %s and %s are of a different size\n", fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
inname, outname); inname, outname);
if (wrote_question == 0 && unsupported_chunks == 0) if (wrote_question == 0 && unsupported_chunks == 0)
{ {
fprintf(STDERR, fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),", " Was %s written with the same maximum IDAT"
inname, PNG_ZBUF_SIZE); " chunk size (%d bytes),",
inname, PNG_ZBUF_SIZE);
fprintf(STDERR, fprintf(STDERR,
"\n filtering heuristic (libpng default), compression"); "\n filtering heuristic (libpng default), compression");
fprintf(STDERR, fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n", " level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION); ZLIB_VERSION);
wrote_question = 1; wrote_question = 1;
} }
@ -1707,17 +1719,18 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (memcmp(inbuf, outbuf, num_in)) if (memcmp(inbuf, outbuf, num_in))
{ {
fprintf(STDERR, "\nFiles %s and %s are different\n", inname, fprintf(STDERR, "\nFiles %s and %s are different\n", inname,
outname); outname);
if (wrote_question == 0 && unsupported_chunks == 0) if (wrote_question == 0 && unsupported_chunks == 0)
{ {
fprintf(STDERR, fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),", " Was %s written with the same maximum"
" IDAT chunk size (%d bytes),",
inname, PNG_ZBUF_SIZE); inname, PNG_ZBUF_SIZE);
fprintf(STDERR, fprintf(STDERR,
"\n filtering heuristic (libpng default), compression"); "\n filtering heuristic (libpng default), compression");
fprintf(STDERR, fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n", " level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION); ZLIB_VERSION);
wrote_question = 1; wrote_question = 1;
} }
@ -1768,12 +1781,12 @@ main(int argc, char *argv[])
fprintf(STDERR, "%s", png_get_copyright(NULL)); fprintf(STDERR, "%s", png_get_copyright(NULL));
/* Show the version of libpng used in building the library */ /* Show the version of libpng used in building the library */
fprintf(STDERR, " library (%lu):%s", fprintf(STDERR, " library (%lu):%s",
(unsigned long)png_access_version_number(), (unsigned long)png_access_version_number(),
png_get_header_version(NULL)); png_get_header_version(NULL));
/* Show the version of libpng used in building the application */ /* Show the version of libpng used in building the application */
fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
PNG_HEADER_VERSION_STRING); PNG_HEADER_VERSION_STRING);
/* Do some consistency checking on the memory allocation settings, I'm /* Do some consistency checking on the memory allocation settings, I'm
* not sure this matters, but it is nice to know, the first of these * not sure this matters, but it is nice to know, the first of these
@ -1791,7 +1804,7 @@ main(int argc, char *argv[])
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING)) if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
{ {
fprintf(STDERR, fprintf(STDERR,
"Warning: versions are different between png.h and png.c\n"); "Warning: versions are different between png.h and png.c\n");
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING); fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver); fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
++ierror; ++ierror;
@ -1846,19 +1859,19 @@ main(int argc, char *argv[])
} }
if (multiple == 0 && argc == 3 + verbose) if (multiple == 0 && argc == 3 + verbose)
outname = argv[2 + verbose]; outname = argv[2 + verbose];
if ((multiple == 0 && argc > 3 + verbose) || if ((multiple == 0 && argc > 3 + verbose) ||
(multiple != 0 && argc < 2)) (multiple != 0 && argc < 2))
{ {
fprintf(STDERR, fprintf(STDERR,
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
argv[0], argv[0]); argv[0], argv[0]);
fprintf(STDERR, fprintf(STDERR,
" reads/writes one PNG file (without -m) or multiple files (-m)\n"); " reads/writes one PNG file (without -m) or multiple files (-m)\n");
fprintf(STDERR, fprintf(STDERR,
" with -m %s is used as a temporary file\n", outname); " with -m %s is used as a temporary file\n", outname);
exit(1); exit(1);
} }
if (multiple != 0) if (multiple != 0)
@ -1879,7 +1892,7 @@ main(int argc, char *argv[])
{ {
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
fprintf(STDERR, "\n PASS (%lu zero samples)\n", fprintf(STDERR, "\n PASS (%lu zero samples)\n",
(unsigned long)zero_samples); (unsigned long)zero_samples);
#else #else
fprintf(STDERR, " PASS\n"); fprintf(STDERR, " PASS\n");
#endif #endif
@ -1899,20 +1912,20 @@ main(int argc, char *argv[])
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
if (allocation_now != current_allocation) if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
current_allocation - allocation_now); current_allocation - allocation_now);
if (current_allocation != 0) if (current_allocation != 0)
{ {
memory_infop pinfo = pinformation; memory_infop pinfo = pinformation;
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
current_allocation); current_allocation);
while (pinfo != NULL) while (pinfo != NULL)
{ {
fprintf(STDERR, " %lu bytes at %p\n", fprintf(STDERR, " %lu bytes at %p\n",
(unsigned long)pinfo->size, (unsigned long)pinfo->size,
pinfo->pointer); pinfo->pointer);
pinfo = pinfo->next; pinfo = pinfo->next;
} }
} }
@ -1920,13 +1933,13 @@ main(int argc, char *argv[])
} }
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
fprintf(STDERR, " Current memory allocation: %10d bytes\n", fprintf(STDERR, " Current memory allocation: %10d bytes\n",
current_allocation); current_allocation);
fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
maximum_allocation); maximum_allocation);
fprintf(STDERR, " Total memory allocation: %10d bytes\n", fprintf(STDERR, " Total memory allocation: %10d bytes\n",
total_allocation); total_allocation);
fprintf(STDERR, " Number of allocations: %10d\n", fprintf(STDERR, " Number of allocations: %10d\n",
num_allocations); num_allocations);
#endif #endif
} }
@ -1961,7 +1974,7 @@ main(int argc, char *argv[])
{ {
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
fprintf(STDERR, "\n PASS (%lu zero samples)\n", fprintf(STDERR, "\n PASS (%lu zero samples)\n",
(unsigned long)zero_samples); (unsigned long)zero_samples);
#else #else
fprintf(STDERR, " PASS\n"); fprintf(STDERR, " PASS\n");
#endif #endif
@ -1988,19 +2001,19 @@ main(int argc, char *argv[])
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
if (allocation_now != current_allocation) if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
current_allocation - allocation_now); current_allocation - allocation_now);
if (current_allocation != 0) if (current_allocation != 0)
{ {
memory_infop pinfo = pinformation; memory_infop pinfo = pinformation;
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
current_allocation); current_allocation);
while (pinfo != NULL) while (pinfo != NULL)
{ {
fprintf(STDERR, " %lu bytes at %p\n", fprintf(STDERR, " %lu bytes at %p\n",
(unsigned long)pinfo->size, pinfo->pointer); (unsigned long)pinfo->size, pinfo->pointer);
pinfo = pinfo->next; pinfo = pinfo->next;
} }
} }
@ -2008,13 +2021,13 @@ main(int argc, char *argv[])
} }
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
fprintf(STDERR, " Current memory allocation: %10d bytes\n", fprintf(STDERR, " Current memory allocation: %10d bytes\n",
current_allocation); current_allocation);
fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
maximum_allocation); maximum_allocation);
fprintf(STDERR, " Total memory allocation: %10d bytes\n", fprintf(STDERR, " Total memory allocation: %10d bytes\n",
total_allocation); total_allocation);
fprintf(STDERR, " Number of allocations: %10d\n", fprintf(STDERR, " Number of allocations: %10d\n",
num_allocations); num_allocations);
#endif #endif
} }
@ -2023,13 +2036,13 @@ main(int argc, char *argv[])
t_misc += (t_stop - t_start); t_misc += (t_stop - t_start);
t_start = t_stop; t_start = t_stop;
fprintf(STDERR, " CPU time used = %.3f seconds", fprintf(STDERR, " CPU time used = %.3f seconds",
(t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC); (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
fprintf(STDERR, " (decoding %.3f,\n", fprintf(STDERR, " (decoding %.3f,\n",
t_decode/(float)CLOCKS_PER_SEC); t_decode/(float)CLOCKS_PER_SEC);
fprintf(STDERR, " encoding %.3f ,", fprintf(STDERR, " encoding %.3f ,",
t_encode/(float)CLOCKS_PER_SEC); t_encode/(float)CLOCKS_PER_SEC);
fprintf(STDERR, " other %.3f seconds)\n\n", fprintf(STDERR, " other %.3f seconds)\n\n",
t_misc/(float)CLOCKS_PER_SEC); t_misc/(float)CLOCKS_PER_SEC);
#endif #endif
if (ierror == 0) if (ierror == 0)
@ -2041,19 +2054,19 @@ main(int argc, char *argv[])
dummy_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); dummy_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
fprintf(STDERR, " Default limits:\n"); fprintf(STDERR, " Default limits:\n");
fprintf(STDERR, " width_max = %lu\n", fprintf(STDERR, " width_max = %lu\n",
(unsigned long) png_get_user_width_max(dummy_ptr)); (unsigned long) png_get_user_width_max(dummy_ptr));
fprintf(STDERR, " height_max = %lu\n", fprintf(STDERR, " height_max = %lu\n",
(unsigned long) png_get_user_height_max(dummy_ptr)); (unsigned long) png_get_user_height_max(dummy_ptr));
if (png_get_chunk_cache_max(dummy_ptr) == 0) if (png_get_chunk_cache_max(dummy_ptr) == 0)
fprintf(STDERR, " cache_max = unlimited\n"); fprintf(STDERR, " cache_max = unlimited\n");
else else
fprintf(STDERR, " cache_max = %lu\n", fprintf(STDERR, " cache_max = %lu\n",
(unsigned long) png_get_chunk_cache_max(dummy_ptr)); (unsigned long) png_get_chunk_cache_max(dummy_ptr));
if (png_get_chunk_malloc_max(dummy_ptr) == 0) if (png_get_chunk_malloc_max(dummy_ptr) == 0)
fprintf(STDERR, " malloc_max = unlimited\n"); fprintf(STDERR, " malloc_max = unlimited\n");
else else
fprintf(STDERR, " malloc_max = %lu\n", fprintf(STDERR, " malloc_max = %lu\n",
(unsigned long) png_get_chunk_malloc_max(dummy_ptr)); (unsigned long) png_get_chunk_malloc_max(dummy_ptr));
png_destroy_read_struct(&dummy_ptr, NULL, NULL); png_destroy_read_struct(&dummy_ptr, NULL, NULL);
return (int)(ierror != 0); return (int)(ierror != 0);
@ -2063,7 +2076,7 @@ int
main(void) main(void)
{ {
fprintf(STDERR, fprintf(STDERR,
" test ignored because libpng was not built with read support\n"); " test ignored because libpng was not built with read support\n");
/* And skip this test */ /* And skip this test */
return PNG_LIBPNG_VER < 10600 ? 0 : 77; return PNG_LIBPNG_VER < 10600 ? 0 : 77;
} }