[libpng16] tests backported from libpng 1.7

This updates libpng16 with all the test changes from libpng17,
including changes to pngvalid.c to ensure that the original,
distributed, version of contrib/visupng/cexcept.h can be used.

pngvalid contains the correction to the use of SAVE/STORE_
UNKNOWN_CHUNKS; a bug revealed by changes in libpng 1.7.  More
tests contain the --strict option to detect warnings and the
pngvalid-standard test has been corrected so that it does not
turn on progresive-read (there is a separate test which does
that.)

Some signed/unsigned fixes have been made.

Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
John Bowler 2015-09-15 15:38:52 -07:00
parent 1e16e8829d
commit c3e7e7d715
19 changed files with 687 additions and 467 deletions

View File

@ -87,7 +87,7 @@ print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
*/ */
case PNG_COLOR_TYPE_PALETTE: case PNG_COLOR_TYPE_PALETTE:
{ {
PNG_CONST unsigned int index = component(row, x, 0, bit_depth, 1); PNG_CONST int index = component(row, x, 0, bit_depth, 1);
png_colorp palette = NULL; png_colorp palette = NULL;
int num_palette = 0; int num_palette = 0;

View File

@ -107,7 +107,7 @@ typedef struct chunk_insert
png_charp parameters[1]; png_charp parameters[1];
} chunk_insert; } chunk_insert;
static int static unsigned int
channels_of_type(int color_type) channels_of_type(int color_type)
{ {
if (color_type & PNG_COLOR_MASK_PALETTE) if (color_type & PNG_COLOR_MASK_PALETTE)
@ -128,7 +128,7 @@ channels_of_type(int color_type)
} }
} }
static int static unsigned int
pixel_depth_of_type(int color_type, int bit_depth) pixel_depth_of_type(int color_type, int bit_depth)
{ {
return channels_of_type(color_type) * bit_depth; return channels_of_type(color_type) * bit_depth;
@ -682,7 +682,11 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, filters); png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, filters);
{ {
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
int passes = png_set_interlace_handling(png_ptr); int passes = png_set_interlace_handling(png_ptr);
# else /* !WRITE_INTERLACING */
int passes = 1;
# endif /* !WRITE_INTERLACING */
int pass; int pass;
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr); png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);

View File

@ -2,7 +2,7 @@
* *
* Copyright (c) 2015 John Cunningham Bowler * Copyright (c) 2015 John Cunningham Bowler
* *
* Last changed in libpng 1.6.18 [July 23, 2015] * Last changed in libpng 1.6.18 [(PENDING RELEASE)]
* *
* 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
@ -236,10 +236,12 @@ static struct transform_info
*/ */
#endif #endif
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
T(SCALE_16, NONE, X, X, 16, R) T(SCALE_16, NONE, X, X, 16, R),
/* scales 16-bit components to 8-bits. */ /* scales 16-bit components to 8-bits. */
#endif #endif
{ NULL /*name*/, 0, 0, 0, 0, 0, 0, 0/*!tested*/ }
#undef T #undef T
}; };
@ -294,7 +296,7 @@ transform_name(int t)
t &= -t; /* first set bit */ t &= -t; /* first set bit */
for (i=0; i<TTABLE_SIZE; ++i) for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
{ {
if ((transform_info[i].transform & t) != 0) if ((transform_info[i].transform & t) != 0)
return transform_info[i].name; return transform_info[i].name;
@ -315,7 +317,7 @@ validate_T(void)
{ {
unsigned int i; unsigned int i;
for (i=0; i<TTABLE_SIZE; ++i) for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
{ {
if (transform_info[i].when & TRANSFORM_R) if (transform_info[i].when & TRANSFORM_R)
read_transforms |= transform_info[i].transform; read_transforms |= transform_info[i].transform;
@ -505,6 +507,7 @@ typedef enum
#define SKIP_BUGS 0x100 /* Skip over known bugs */ #define SKIP_BUGS 0x100 /* Skip over known bugs */
#define LOG_SKIPPED 0x200 /* Log skipped bugs */ #define LOG_SKIPPED 0x200 /* Log skipped bugs */
#define FIND_BAD_COMBOS 0x400 /* Attempt to deduce bad combos */ #define FIND_BAD_COMBOS 0x400 /* Attempt to deduce bad combos */
#define LIST_COMBOS 0x800 /* List combos by name */
/* Result masks apply to the result bits in the 'results' field below; these /* Result masks apply to the result bits in the 'results' field below; these
* bits are simple 1U<<error_level. A pass requires either nothing worse than * bits are simple 1U<<error_level. A pass requires either nothing worse than
@ -690,7 +693,35 @@ display_log(struct display *dp, error_level level, const char *fmt, ...)
int tr = dp->transforms; int tr = dp->transforms;
if (is_combo(tr)) if (is_combo(tr))
{
if (dp->options & LIST_COMBOS)
{
int trx = tr;
fprintf(stderr, "(");
if (trx)
{
int start = 0;
while (trx)
{
int trz = trx & -trx;
if (start) fprintf(stderr, "+");
fprintf(stderr, "%s", transform_name(trz));
start = 1;
trx &= ~trz;
}
}
else
fprintf(stderr, "-");
fprintf(stderr, ")");
}
else
fprintf(stderr, "(0x%x)", tr); fprintf(stderr, "(0x%x)", tr);
}
else else
fprintf(stderr, "(%s)", transform_name(tr)); fprintf(stderr, "(%s)", transform_name(tr));
@ -910,7 +941,7 @@ update_display(struct display *dp)
int bd = dp->bit_depth; int bd = dp->bit_depth;
unsigned int i; unsigned int i;
for (i=0; i<TTABLE_SIZE; ++i) for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
{ {
int transform = transform_info[i].transform; int transform = transform_info[i].transform;
@ -935,9 +966,6 @@ update_display(struct display *dp)
dp->active_transforms = active; dp->active_transforms = active;
dp->ignored_transforms = inactive; /* excluding write-only transforms */ dp->ignored_transforms = inactive; /* excluding write-only transforms */
if (active == 0)
display_log(dp, INTERNAL_ERROR, "bad transform table");
} }
} }
@ -1588,6 +1616,12 @@ main(const int argc, const char * const * const argv)
else if (strcmp(name, "--nofind-bad-combos") == 0) else if (strcmp(name, "--nofind-bad-combos") == 0)
d.options &= ~FIND_BAD_COMBOS; d.options &= ~FIND_BAD_COMBOS;
else if (strcmp(name, "--list-combos") == 0)
d.options |= LIST_COMBOS;
else if (strcmp(name, "--nolist-combos") == 0)
d.options &= ~LIST_COMBOS;
else if (name[0] == '-' && name[1] == '-') else if (name[0] == '-' && name[1] == '-')
{ {
fprintf(stderr, "pngimage: %s: unknown option\n", name); fprintf(stderr, "pngimage: %s: unknown option\n", name);

View File

@ -363,7 +363,7 @@ ancillary(const char *name)
return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3])); return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));
} }
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED #ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
static int static int
ancillaryb(const png_byte *name) ancillaryb(const png_byte *name)
{ {
@ -554,7 +554,7 @@ read_callback(png_structp pp, png_unknown_chunkp pc)
/* However if there is no support to store unknown chunks don't ask libpng to /* However if there is no support to store unknown chunks don't ask libpng to
* do it; there will be an png_error. * do it; there will be an png_error.
*/ */
# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
return discard; return discard;
# else # else
return 1; /*handled; discard*/ return 1; /*handled; discard*/
@ -562,7 +562,7 @@ read_callback(png_structp pp, png_unknown_chunkp pc)
} }
#endif /* READ_USER_CHUNKS_SUPPORTED */ #endif /* READ_USER_CHUNKS_SUPPORTED */
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED #ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
static png_uint_32 static png_uint_32
get_unknown(display *d, png_infop info_ptr, int after_IDAT) get_unknown(display *d, png_infop info_ptr, int after_IDAT)
{ {
@ -722,11 +722,17 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
* in this case, so we just check the arguments! This could * in this case, so we just check the arguments! This could
* be improved in the future by using the read callback. * be improved in the future by using the read callback.
*/ */
# if PNG_LIBPNG_VER >= 10700 &&\
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
{
png_byte name[5]; png_byte name[5];
memcpy(name, chunk_info[chunk].name, 5); memcpy(name, chunk_info[chunk].name, 5);
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1); png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
chunk_info[chunk].keep = option; chunk_info[chunk].keep = option;
}
continue; continue;
} }
@ -735,7 +741,12 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
case 7: /* default */ case 7: /* default */
if (memcmp(argv[i], "default", 7) == 0) if (memcmp(argv[i], "default", 7) == 0)
{ {
# if PNG_LIBPNG_VER >= 10700 &&\
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0); png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);
d->keep = option; d->keep = option;
continue; continue;
} }
@ -745,7 +756,12 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
case 3: /* all */ case 3: /* all */
if (memcmp(argv[i], "all", 3) == 0) if (memcmp(argv[i], "all", 3) == 0)
{ {
# if PNG_LIBPNG_VER >= 10700 &&\
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1); png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
d->keep = option; d->keep = option;
for (chunk = 0; chunk < NINFO; ++chunk) for (chunk = 0; chunk < NINFO; ++chunk)

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,13 @@
# include "../../png.h" # include "../../png.h"
#endif #endif
#if PNG_LIBPNG_VER < 10700
/* READ_INTERLACING was used instead of READ_DEINTERLACE. */
# ifdef PNG_READ_INTERLACING_SUPPORTED
# define PNG_READ_DEINTERLACE_SUPPORTED
# endif
#endif
static int static int
read_png(FILE *fp) read_png(FILE *fp)
{ {
@ -70,7 +77,12 @@ read_png(FILE *fp)
{ {
png_uint_32 height = png_get_image_height(png_ptr, info_ptr); png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
# ifdef PNG_READ_DEINTERLACE_SUPPORTED
int passes = png_set_interlace_handling(png_ptr); int passes = png_set_interlace_handling(png_ptr);
# else
int passes = png_get_interlace_type(png_ptr, info_ptr) ==
PNG_INTERLACE_ADAM7 ? PNG_INTERLACE_ADAM7_PASSES : 1;
# endif
int pass; int pass;
png_start_read_image(png_ptr); png_start_read_image(png_ptr);
@ -79,6 +91,11 @@ read_png(FILE *fp)
{ {
png_uint_32 y = height; png_uint_32 y = height;
# ifndef PNG_READ_DEINTERLACE_SUPPORTED
if (passes == PNG_INTERLACE_ADAM7_PASSES)
y = PNG_PASS_ROWS(y, pass);
# endif
/* NOTE: this trashes the row each time; interlace handling won't /* NOTE: this trashes the row each time; interlace handling won't
* work, but this avoids memory thrashing for speed testing. * work, but this avoids memory thrashing for speed testing.
*/ */

View File

@ -52,7 +52,10 @@
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
#include <setjmp.h> #include <setjmp.h>
#if defined(PNG_READ_SUPPORTED) && defined(PNG_EASY_ACCESS_SUPPORTED) #if defined(PNG_READ_SUPPORTED) && defined(PNG_EASY_ACCESS_SUPPORTED) &&\
(defined(PNG_READ_DEINTERLACE_SUPPORTED) ||\
defined(PNG_READ_INTERLACING_SUPPORTED))
/* zlib.h defines the structure z_stream, an instance of which is included /* zlib.h defines the structure z_stream, an instance of which is included
* in this structure and is required for decompressing the LZ compressed * in this structure and is required for decompressing the LZ compressed
* data in PNG files. * data in PNG files.
@ -4030,7 +4033,7 @@ main(void)
int int
main(void) main(void)
{ {
fprintf(stderr, "pngfix does not work without read support\n"); fprintf(stderr, "pngfix does not work without read deinterlace support\n");
return 77; return 77;
} }
#endif /* PNG_READ_SUPPORTED && PNG_EASY_ACCESS_SUPPORTED */ #endif /* PNG_READ_SUPPORTED && PNG_EASY_ACCESS_SUPPORTED */

View File

@ -136,7 +136,7 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
/* create the two png(-info) structures */ /* create the two png(-info) structures */
png_ptr = png_create_read_struct(png_get_libpng_ver(NULL), NULL, png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL); (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
if (!png_ptr) if (!png_ptr)
{ {
@ -313,7 +313,7 @@ BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
/* prepare the standard PNG structures */ /* prepare the standard PNG structures */
png_ptr = png_create_write_struct(png_get_libpng_ver(NULL), NULL, png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL); (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
if (!png_ptr) if (!png_ptr)
{ {

View File

@ -1,12 +1,11 @@
/*=== /*===
cexcept.h 2.0.1 (2008-Jul-19-Sat, modified 2015-Jun-03-Mon) cexcept.h 2.0.1 (2008-Jul-19-Sat)
http://www.nicemice.net/cexcept/ http://www.nicemice.net/cexcept/
Adam M. Costello Adam M. Costello
http://www.nicemice.net/amc/ http://www.nicemice.net/amc/
An interface for exception-handling in ANSI C (C89 and subsequent ISO An interface for exception-handling in ANSI C (C89 and subsequent ISO
standards), developed jointly with Cosmin Truta. Revised by John Bowler, standards), developed jointly with Cosmin Truta.
June 2015, to declare exception_env and exception_prev "volatile".
Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta. Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta.
This software may be modified only if its author and version This software may be modified only if its author and version
@ -211,7 +210,7 @@ struct exception_context { \
#define Try \ #define Try \
{ \ { \
jmp_buf * volatile exception__prev, exception__env; \ jmp_buf *exception__prev, exception__env; \
exception__prev = the_exception_context->penv; \ exception__prev = the_exception_context->penv; \
the_exception_context->penv = &exception__env; \ the_exception_context->penv = &exception__env; \
if (setjmp(exception__env) == 0) { \ if (setjmp(exception__env) == 0) { \

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngimage --exhaustive --log "${srcdir}/contrib/pngsuite/"*.png exec ./pngimage --exhaustive --list-combos --log "${srcdir}/contrib/pngsuite/"*.png

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngimage --log "${srcdir}/contrib/pngsuite/"*.png exec ./pngimage --list-combos --log "${srcdir}/contrib/pngsuite/"*.png

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngunknown default=discard IDAT=save "${srcdir}/pngtest.png" exec ./pngunknown --strict default=discard IDAT=save "${srcdir}/pngtest.png"

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngunknown default=discard "${srcdir}/pngtest.png" exec ./pngunknown --strict default=discard "${srcdir}/pngtest.png"

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngunknown default=if-safe "${srcdir}/pngtest.png" exec ./pngunknown --strict default=if-safe "${srcdir}/pngtest.png"

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngunknown bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save "${srcdir}/pngtest.png" exec ./pngunknown --strict bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save "${srcdir}/pngtest.png"

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngunknown sTER=if-safe "${srcdir}/pngtest.png" exec ./pngunknown --strict sTER=if-safe "${srcdir}/pngtest.png"

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngunknown default=save "${srcdir}/pngtest.png" exec ./pngunknown --strict default=save "${srcdir}/pngtest.png"

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngunknown vpAg=if-safe "${srcdir}/pngtest.png" exec ./pngunknown --strict vpAg=if-safe "${srcdir}/pngtest.png"

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
exec ./pngvalid --standard --progressive-read exec ./pngvalid --standard