Forward port libpng16 fixes

Batched fixes from libpng16: PNG_IMAGE_PNG_SIZE_MAX macro fix, contrib/libtests
exit(77) change to just do that for configure and changes to pngstest to
(by default) make random backgrounds on a per-file, not per-session, basis.

Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
John Bowler 2016-01-28 23:11:33 -08:00
parent dcb3f792d9
commit 85cb69aa82
5 changed files with 91 additions and 21 deletions

View File

@ -36,6 +36,15 @@
# include <setjmp.h> /* because png.h did *not* include this */
#endif
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED) && defined(PNG_SEQUENTIAL_READ_SUPPORTED)\
&& (defined(PNG_READ_PNG_SUPPORTED) || PNG_LIBPNG_VER < 10700)
/* If a transform is valid on both read and write this implies that if the
@ -1682,6 +1691,6 @@ int
main(void)
{
fprintf(stderr, "pngimage: no support for png_read/write_image\n");
return 77;
return SKIP;
}
#endif

View File

@ -26,6 +26,15 @@
# include <config.h>
#endif
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
/* Define the following to use this test against your installed libpng, rather
* than the one being built here:
*/
@ -99,10 +108,18 @@ make_random_bytes(png_uint_32* seed, void* pv, size_t size)
seed[1] = u1;
}
static png_uint_32 color_seed[2];
static void
reseed(void)
{
color_seed[0] = 0x12345678U;
color_seed[1] = 0x9abcdefU;
}
static void
random_color(png_colorp color)
{
static png_uint_32 color_seed[2] = { 0x12345678, 0x9abcdef };
make_random_bytes(color_seed, color, sizeof *color);
}
@ -316,6 +333,9 @@ compare_16bit(int v1, int v2, int error_limit, int multiple_algorithms)
#define ACCUMULATE 64
#define FAST_WRITE 128
#define sRGB_16BIT 256
#define NO_RESEED 512 /* do not reseed on each new file */
#define GBG_ERROR 1024 /* do not ignore the gamma+background_rgb_to_gray
* libpng warning. */
static void
print_opts(png_uint_32 opts)
@ -324,8 +344,8 @@ print_opts(png_uint_32 opts)
printf(" --file");
if (opts & USE_STDIO)
printf(" --stdio");
if (opts & STRICT)
printf(" --strict");
if (!(opts & STRICT))
printf(" --nostrict");
if (opts & VERBOSE)
printf(" --verbose");
if (opts & KEEP_TMPFILES)
@ -338,6 +358,12 @@ print_opts(png_uint_32 opts)
printf(" --slow");
if (opts & sRGB_16BIT)
printf(" --sRGB-16bit");
if (opts & NO_RESEED)
printf(" --noreseed");
#if PNG_LIBPNG_VER < 10700 /* else on by default */
if (opts & GBG_ERROR)
printf(" --fault-gbg-warning");
#endif
}
#define FORMAT_NO_CHANGE 0x80000000 /* additional flag */
@ -741,8 +767,15 @@ checkopaque(Image *image)
return logerror(image, image->file_name, ": opaque not NULL", "");
}
else if (image->image.warning_or_error != 0 && (image->opts & STRICT) != 0)
return logerror(image, image->file_name, " --strict", "");
/* Separate out the gamma+background_rgb_to_gray warning because it may
* produce opaque component errors:
*/
else if (image->image.warning_or_error != 0 &&
(strcmp(image->image.message,
"libpng does not support gamma+background+rgb_to_gray") == 0 ?
(image->opts & GBG_ERROR) != 0 : (image->opts & STRICT) != 0))
return logerror(image, image->file_name, (image->opts & GBG_ERROR) != 0 ?
" --fault-gbg-warning" : " --strict", "");
else
return 1;
@ -3198,9 +3231,11 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
if (png_image_write_get_memory_size(image->image, size, convert_to_8bit,
image->buffer+16, (png_int_32)image->stride, image->colormap))
{
/* This is non-fatal: */
/* This is non-fatal but ignoring it was causing serious problems in
* the macro to be ignored:
*/
if (size > PNG_IMAGE_PNG_SIZE_MAX(image->image))
logerror(image, "memory", ": PNG_IMAGE_SIZE_MAX wrong", "");
return logerror(image, "memory", ": PNG_IMAGE_SIZE_MAX wrong", "");
initimage(output, image->opts, "memory", image->stride_extra);
output->input_memory = malloc(size);
@ -3213,9 +3248,10 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
&output->input_memory_size, convert_to_8bit, image->buffer+16,
(png_int_32)image->stride, image->colormap))
{
/* This is also non-fatal (maybe): */
/* This is also non-fatal but it safes safer to error out anyway:
*/
if (size != output->input_memory_size)
logerror(image, "memory", ": memory size wrong", "");
return logerror(image, "memory", ": memory size wrong", "");
}
else
@ -3403,6 +3439,8 @@ test_one_file(const char *file_name, format_list *formats, png_uint_32 opts,
int result;
Image image;
if (!(opts & NO_RESEED))
reseed(); /* ensure that the random numbers don't depend on file order */
newimage(&image);
initimage(&image, opts, file_name, stride_extra);
result = read_one_file(&image);
@ -3440,7 +3478,7 @@ test_one_file(const char *file_name, format_list *formats, png_uint_32 opts,
int
main(int argc, char **argv)
{
png_uint_32 opts = FAST_WRITE;
png_uint_32 opts = FAST_WRITE | STRICT;
format_list formats;
const char *touch = NULL;
int log_pass = 0;
@ -3449,11 +3487,17 @@ main(int argc, char **argv)
int retval = 0;
int c;
#if PNG_LIBPNG_VER >= 10700
/* This error should not exist in 1.7 or later: */
opts |= GBG_ERROR;
#endif
init_sRGB_to_d();
#if 0
init_error_via_linear();
#endif
format_init(&formats);
reseed(); /* initialize random number seeds */
for (c=1; c<argc; ++c)
{
@ -3470,7 +3514,7 @@ main(int argc, char **argv)
# ifdef PNG_STDIO_SUPPORTED
opts |= USE_FILE;
# else
return 77; /* skipped: no support */
return SKIP; /* skipped: no support */
# endif
else if (strcmp(arg, "--memory") == 0)
opts &= ~USE_FILE;
@ -3478,7 +3522,7 @@ main(int argc, char **argv)
# ifdef PNG_STDIO_SUPPORTED
opts |= USE_STDIO;
# else
return 77; /* skipped: no support */
return SKIP; /* skipped: no support */
# endif
else if (strcmp(arg, "--name") == 0)
opts &= ~USE_STDIO;
@ -3504,10 +3548,16 @@ main(int argc, char **argv)
opts &= ~KEEP_GOING;
else if (strcmp(arg, "--strict") == 0)
opts |= STRICT;
else if (strcmp(arg, "--nostrict") == 0)
opts &= ~STRICT;
else if (strcmp(arg, "--sRGB-16bit") == 0)
opts |= sRGB_16BIT;
else if (strcmp(arg, "--linear-16bit") == 0)
opts &= ~sRGB_16BIT;
else if (strcmp(arg, "--noreseed") == 0)
opts |= NO_RESEED;
else if (strcmp(arg, "--fault-gbg-warning") == 0)
opts |= GBG_ERROR;
else if (strcmp(arg, "--tmpfile") == 0)
{
if (c+1 < argc)
@ -3764,6 +3814,6 @@ int main(void)
{
fprintf(stderr, "pngstest: no read support in libpng, test skipped\n");
/* So the test is skipped: */
return 77;
return SKIP;
}
#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */

View File

@ -30,6 +30,16 @@
# include "../../png.h"
#endif
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
/* Since this program tests the ability to change the unknown chunk handling
* these must be defined:
*/
@ -1260,7 +1270,7 @@ main(void)
fprintf(stderr,
" test ignored: no support to find out about unknown chunks\n");
/* So the test is skipped: */
return 77;
return SKIP;
}
#endif /* READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS */
@ -1271,6 +1281,6 @@ main(void)
fprintf(stderr,
" test ignored: no support to modify unknown chunk handling\n");
/* So the test is skipped: */
return 77;
return SKIP;
}
#endif /* SET_UNKNOWN_CHUNKS && READ*/

View File

@ -62,10 +62,10 @@
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER < 10601
# define SKIP 0
#else
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
/* pngvalid requires write support and one of the fixed or floating point APIs.

5
png.h
View File

@ -3569,8 +3569,9 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\
((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\
(((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\
12U+PNG_IMAGE_COLORMAP_SIZE(image)/*PLTE+tRNS data*/+\
(((image).format&PNG_FORMAT_FLAG_ALPHA)?12U/*tRNS*/:0U):0U)+\
12U+3U*(image).colormap_entries/*PLTE data*/+\
(((image).format&PNG_FORMAT_FLAG_ALPHA)?\
12U/*tRNS*/+(image).colormap_entries:0U):0U)+\
12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size))
/* A helper for the following macro; if your compiler cannot handle the
* following macro use this one with the result of