提交 c3e7e7d7 编写于 作者: J John Bowler

[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: NJohn Bowler <jbowler@acm.org>
上级 1e16e882
......@@ -87,7 +87,7 @@ print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
*/
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;
int num_palette = 0;
......
......@@ -107,7 +107,7 @@ typedef struct chunk_insert
png_charp parameters[1];
} chunk_insert;
static int
static unsigned int
channels_of_type(int color_type)
{
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)
{
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);
{
int passes = png_set_interlace_handling(png_ptr);
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
int passes = png_set_interlace_handling(png_ptr);
# else /* !WRITE_INTERLACING */
int passes = 1;
# endif /* !WRITE_INTERLACING */
int pass;
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
......
......@@ -2,7 +2,7 @@
*
* 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.
* For conditions of distribution and use, see the disclaimer
......@@ -236,10 +236,12 @@ static struct transform_info
*/
#endif
#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. */
#endif
{ NULL /*name*/, 0, 0, 0, 0, 0, 0, 0/*!tested*/ }
#undef T
};
......@@ -294,7 +296,7 @@ transform_name(int t)
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)
return transform_info[i].name;
......@@ -315,7 +317,7 @@ validate_T(void)
{
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)
read_transforms |= transform_info[i].transform;
......@@ -505,6 +507,7 @@ typedef enum
#define SKIP_BUGS 0x100 /* Skip over known bugs */
#define LOG_SKIPPED 0x200 /* Log skipped bugs */
#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
* 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;
if (is_combo(tr))
fprintf(stderr, "(0x%x)", 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);
}
else
fprintf(stderr, "(%s)", transform_name(tr));
......@@ -910,7 +941,7 @@ update_display(struct display *dp)
int bd = dp->bit_depth;
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;
......@@ -935,9 +966,6 @@ update_display(struct display *dp)
dp->active_transforms = active;
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)
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] == '-')
{
fprintf(stderr, "pngimage: %s: unknown option\n", name);
......
......@@ -363,7 +363,7 @@ ancillary(const char *name)
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
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
* do it; there will be an png_error.
*/
# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
return discard;
# else
return 1; /*handled; discard*/
......@@ -562,7 +562,7 @@ read_callback(png_structp pp, png_unknown_chunkp pc)
}
#endif /* READ_USER_CHUNKS_SUPPORTED */
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
static png_uint_32
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
* be improved in the future by using the read callback.
*/
png_byte name[5];
memcpy(name, chunk_info[chunk].name, 5);
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
chunk_info[chunk].keep = option;
# 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];
memcpy(name, chunk_info[chunk].name, 5);
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
chunk_info[chunk].keep = option;
}
continue;
}
......@@ -735,7 +741,12 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
case 7: /* default */
if (memcmp(argv[i], "default", 7) == 0)
{
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 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);
d->keep = option;
continue;
}
......@@ -745,7 +756,12 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
case 3: /* all */
if (memcmp(argv[i], "all", 3) == 0)
{
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
# 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);
d->keep = option;
for (chunk = 0; chunk < NINFO; ++chunk)
......@@ -1242,4 +1258,4 @@ main(void)
/* So the test is skipped: */
return 77;
}
#endif /* SET_UNKNOWN_CHUNKS && READ */
#endif /* SET_UNKNOWN_CHUNKS && READ*/
此差异已折叠。
......@@ -31,6 +31,13 @@
# include "../../png.h"
#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
read_png(FILE *fp)
{
......@@ -70,7 +77,12 @@ read_png(FILE *fp)
{
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
int passes = png_set_interlace_handling(png_ptr);
# ifdef PNG_READ_DEINTERLACE_SUPPORTED
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;
png_start_read_image(png_ptr);
......@@ -79,6 +91,11 @@ read_png(FILE *fp)
{
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
* work, but this avoids memory thrashing for speed testing.
*/
......
......@@ -52,7 +52,10 @@
#ifdef PNG_SETJMP_SUPPORTED
#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
* in this structure and is required for decompressing the LZ compressed
* data in PNG files.
......@@ -667,7 +670,7 @@ IDAT_list_extend(struct IDAT_list *tail)
if (length < tail->length) /* arithmetic overflow */
length = tail->length;
next = voidcast(IDAT_list*, malloc(IDAT_list_size(NULL, length)));
CLEAR(*next);
......@@ -921,7 +924,7 @@ emit_string(const char *str, FILE *out)
else if (isspace(UCHAR_MAX & *str))
putc('_', out);
else
fprintf(out, "\\%.3o", *str);
}
......@@ -1945,7 +1948,7 @@ process_IDAT(struct file *file)
list->count = 0;
file->idat->idat_list_tail = list;
}
/* And fill in the next IDAT information buffer. */
list->lengths[(list->count)++] = file->chunk->chunk_length;
......@@ -2585,7 +2588,7 @@ zlib_run(struct zlib *zlib)
{
struct chunk *chunk = zlib->chunk;
int rc;
assert(zlib->rewrite_offset < chunk->chunk_length);
rc = zlib_advance(zlib, chunk->chunk_length - zlib->rewrite_offset);
......@@ -4030,7 +4033,7 @@ main(void)
int
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;
}
#endif /* PNG_READ_SUPPORTED && PNG_EASY_ACCESS_SUPPORTED */
......
......@@ -136,7 +136,7 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
/* 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);
if (!png_ptr)
{
......@@ -313,7 +313,7 @@ BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
/* 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);
if (!png_ptr)
{
......
/*===
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/
Adam M. Costello
http://www.nicemice.net/amc/
An interface for exception-handling in ANSI C (C89 and subsequent ISO
standards), developed jointly with Cosmin Truta. Revised by John Bowler,
June 2015, to declare exception_env and exception_prev "volatile".
standards), developed jointly with Cosmin Truta.
Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta.
This software may be modified only if its author and version
......@@ -211,7 +210,7 @@ struct exception_context { \
#define Try \
{ \
jmp_buf * volatile exception__prev, exception__env; \
jmp_buf *exception__prev, exception__env; \
exception__prev = the_exception_context->penv; \
the_exception_context->penv = &exception__env; \
if (setjmp(exception__env) == 0) { \
......
#!/bin/sh
exec ./pngimage --exhaustive --log "${srcdir}/contrib/pngsuite/"*.png
exec ./pngimage --exhaustive --list-combos --log "${srcdir}/contrib/pngsuite/"*.png
#!/bin/sh
exec ./pngimage --log "${srcdir}/contrib/pngsuite/"*.png
exec ./pngimage --list-combos --log "${srcdir}/contrib/pngsuite/"*.png
#!/bin/sh
exec ./pngunknown default=discard IDAT=save "${srcdir}/pngtest.png"
exec ./pngunknown --strict default=discard IDAT=save "${srcdir}/pngtest.png"
#!/bin/sh
exec ./pngunknown default=discard "${srcdir}/pngtest.png"
exec ./pngunknown --strict default=discard "${srcdir}/pngtest.png"
#!/bin/sh
exec ./pngunknown default=if-safe "${srcdir}/pngtest.png"
exec ./pngunknown --strict default=if-safe "${srcdir}/pngtest.png"
#!/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"
#!/bin/sh
exec ./pngunknown sTER=if-safe "${srcdir}/pngtest.png"
exec ./pngunknown --strict sTER=if-safe "${srcdir}/pngtest.png"
#!/bin/sh
exec ./pngunknown default=save "${srcdir}/pngtest.png"
exec ./pngunknown --strict default=save "${srcdir}/pngtest.png"
#!/bin/sh
exec ./pngunknown vpAg=if-safe "${srcdir}/pngtest.png"
exec ./pngunknown --strict vpAg=if-safe "${srcdir}/pngtest.png"
#!/bin/sh
exec ./pngvalid --standard --progressive-read
exec ./pngvalid --standard
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册