pngstest: options to fix per-file seed
Also avoid command output substition in tests/pngstest and fix the collation locale to ASCII/C/POSIX Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
parent
74e481c743
commit
e717842a54
@ -108,10 +108,18 @@ make_random_bytes(png_uint_32* seed, void* pv, size_t size)
|
|||||||
seed[1] = u1;
|
seed[1] = u1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static png_uint_32 color_seed[2];
|
||||||
|
|
||||||
|
static void
|
||||||
|
reseed(void)
|
||||||
|
{
|
||||||
|
color_seed[0] = 0x12345678U;
|
||||||
|
color_seed[1] = 0x9abcdefU;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
random_color(png_colorp color)
|
random_color(png_colorp color)
|
||||||
{
|
{
|
||||||
static png_uint_32 color_seed[2] = { 0x12345678, 0x9abcdef };
|
|
||||||
make_random_bytes(color_seed, color, sizeof *color);
|
make_random_bytes(color_seed, color, sizeof *color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,6 +333,9 @@ compare_16bit(int v1, int v2, int error_limit, int multiple_algorithms)
|
|||||||
#define ACCUMULATE 64
|
#define ACCUMULATE 64
|
||||||
#define FAST_WRITE 128
|
#define FAST_WRITE 128
|
||||||
#define sRGB_16BIT 256
|
#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
|
static void
|
||||||
print_opts(png_uint_32 opts)
|
print_opts(png_uint_32 opts)
|
||||||
@ -333,8 +344,8 @@ print_opts(png_uint_32 opts)
|
|||||||
printf(" --file");
|
printf(" --file");
|
||||||
if (opts & USE_STDIO)
|
if (opts & USE_STDIO)
|
||||||
printf(" --stdio");
|
printf(" --stdio");
|
||||||
if (opts & STRICT)
|
if (!(opts & STRICT))
|
||||||
printf(" --strict");
|
printf(" --nostrict");
|
||||||
if (opts & VERBOSE)
|
if (opts & VERBOSE)
|
||||||
printf(" --verbose");
|
printf(" --verbose");
|
||||||
if (opts & KEEP_TMPFILES)
|
if (opts & KEEP_TMPFILES)
|
||||||
@ -347,6 +358,12 @@ print_opts(png_uint_32 opts)
|
|||||||
printf(" --slow");
|
printf(" --slow");
|
||||||
if (opts & sRGB_16BIT)
|
if (opts & sRGB_16BIT)
|
||||||
printf(" --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 */
|
#define FORMAT_NO_CHANGE 0x80000000 /* additional flag */
|
||||||
@ -750,8 +767,15 @@ checkopaque(Image *image)
|
|||||||
return logerror(image, image->file_name, ": opaque not NULL", "");
|
return logerror(image, image->file_name, ": opaque not NULL", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (image->image.warning_or_error != 0 && (image->opts & STRICT) != 0)
|
/* Separate out the gamma+background_rgb_to_gray warning because it may
|
||||||
return logerror(image, image->file_name, " --strict", "");
|
* 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
|
else
|
||||||
return 1;
|
return 1;
|
||||||
@ -3207,13 +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,
|
if (png_image_write_get_memory_size(image->image, size, convert_to_8bit,
|
||||||
image->buffer+16, (png_int_32)image->stride, image->colormap))
|
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))
|
if (size > PNG_IMAGE_PNG_SIZE_MAX(image->image))
|
||||||
{
|
return logerror(image, "memory", ": PNG_IMAGE_SIZE_MAX wrong", "");
|
||||||
logerror(image, "memory", ": PNG_IMAGE_SIZE_MAX wrong", "");
|
|
||||||
if ((image->opts & STRICT) != 0)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
initimage(output, image->opts, "memory", image->stride_extra);
|
initimage(output, image->opts, "memory", image->stride_extra);
|
||||||
output->input_memory = malloc(size);
|
output->input_memory = malloc(size);
|
||||||
@ -3226,14 +3248,10 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
|
|||||||
&output->input_memory_size, convert_to_8bit, image->buffer+16,
|
&output->input_memory_size, convert_to_8bit, image->buffer+16,
|
||||||
(png_int_32)image->stride, image->colormap))
|
(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)
|
if (size != output->input_memory_size)
|
||||||
{
|
return logerror(image, "memory", ": memory size wrong", "");
|
||||||
logerror(image, "memory", ": memory size wrong", "");
|
|
||||||
|
|
||||||
if ((image->opts & STRICT) != 0)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -3421,6 +3439,8 @@ test_one_file(const char *file_name, format_list *formats, png_uint_32 opts,
|
|||||||
int result;
|
int result;
|
||||||
Image image;
|
Image image;
|
||||||
|
|
||||||
|
if (!(opts & NO_RESEED))
|
||||||
|
reseed(); /* ensure that the random numbers don't depend on file order */
|
||||||
newimage(&image);
|
newimage(&image);
|
||||||
initimage(&image, opts, file_name, stride_extra);
|
initimage(&image, opts, file_name, stride_extra);
|
||||||
result = read_one_file(&image);
|
result = read_one_file(&image);
|
||||||
@ -3458,7 +3478,7 @@ test_one_file(const char *file_name, format_list *formats, png_uint_32 opts,
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
png_uint_32 opts = FAST_WRITE;
|
png_uint_32 opts = FAST_WRITE | STRICT;
|
||||||
format_list formats;
|
format_list formats;
|
||||||
const char *touch = NULL;
|
const char *touch = NULL;
|
||||||
int log_pass = 0;
|
int log_pass = 0;
|
||||||
@ -3467,11 +3487,17 @@ main(int argc, char **argv)
|
|||||||
int retval = 0;
|
int retval = 0;
|
||||||
int c;
|
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();
|
init_sRGB_to_d();
|
||||||
#if 0
|
#if 0
|
||||||
init_error_via_linear();
|
init_error_via_linear();
|
||||||
#endif
|
#endif
|
||||||
format_init(&formats);
|
format_init(&formats);
|
||||||
|
reseed(); /* initialize random number seeds */
|
||||||
|
|
||||||
for (c=1; c<argc; ++c)
|
for (c=1; c<argc; ++c)
|
||||||
{
|
{
|
||||||
@ -3522,10 +3548,16 @@ main(int argc, char **argv)
|
|||||||
opts &= ~KEEP_GOING;
|
opts &= ~KEEP_GOING;
|
||||||
else if (strcmp(arg, "--strict") == 0)
|
else if (strcmp(arg, "--strict") == 0)
|
||||||
opts |= STRICT;
|
opts |= STRICT;
|
||||||
|
else if (strcmp(arg, "--nostrict") == 0)
|
||||||
|
opts &= ~STRICT;
|
||||||
else if (strcmp(arg, "--sRGB-16bit") == 0)
|
else if (strcmp(arg, "--sRGB-16bit") == 0)
|
||||||
opts |= sRGB_16BIT;
|
opts |= sRGB_16BIT;
|
||||||
else if (strcmp(arg, "--linear-16bit") == 0)
|
else if (strcmp(arg, "--linear-16bit") == 0)
|
||||||
opts &= ~sRGB_16BIT;
|
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)
|
else if (strcmp(arg, "--tmpfile") == 0)
|
||||||
{
|
{
|
||||||
if (c+1 < argc)
|
if (c+1 < argc)
|
||||||
|
@ -17,36 +17,38 @@ gamma="$1"
|
|||||||
shift
|
shift
|
||||||
alpha="$1"
|
alpha="$1"
|
||||||
shift
|
shift
|
||||||
exec ./pngstest --tmpfile "${gamma}-${alpha}-" --log ${1+"$@"} `
|
args=
|
||||||
for f in "${srcdir}/contrib/testpngs/"*.png
|
LC_ALL="C" # fix glob sort order to ASCII:
|
||||||
do
|
for f in "${srcdir}/contrib/testpngs/"*.png
|
||||||
g=
|
do
|
||||||
case "$f" in
|
g=
|
||||||
*-linear[.-]*)
|
case "$f" in
|
||||||
test "$gamma" = "linear" && g="$f";;
|
*-linear[.-]*)
|
||||||
|
test "$gamma" = "linear" && g="$f";;
|
||||||
|
|
||||||
*-sRGB[.-]*)
|
*-sRGB[.-]*)
|
||||||
test "$gamma" = "sRGB" && g="$f";;
|
test "$gamma" = "sRGB" && g="$f";;
|
||||||
|
|
||||||
*-1.8[.-]*)
|
*-1.8[.-]*)
|
||||||
test "$gamma" = "1.8" && g="$f";;
|
test "$gamma" = "1.8" && g="$f";;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
test "$gamma" = "none" && g="$f";;
|
test "$gamma" = "none" && g="$f";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$g" in
|
case "$g" in
|
||||||
"")
|
"")
|
||||||
:;;
|
:;;
|
||||||
|
|
||||||
*-alpha[-.]*)
|
*-alpha[-.]*)
|
||||||
test "$alpha" = "alpha" && echo "$g";;
|
test "$alpha" = "alpha" && args="$args $g";;
|
||||||
|
|
||||||
*-tRNS[-.]*)
|
*-tRNS[-.]*)
|
||||||
test "$alpha" = "tRNS" -o "$alpha" = "none" && echo "$g";;
|
test "$alpha" = "tRNS" -o "$alpha" = "none" && args="$args $g";;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
test "$alpha" = "opaque" -o "$alpha" = "none" && echo "$g";;
|
test "$alpha" = "opaque" -o "$alpha" = "none" && args="$args $g";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
`
|
# This only works if the arguments don't contain spaces; they don't.
|
||||||
|
exec ./pngstest --tmpfile "${gamma}-${alpha}-" --log ${1+"$@"} $args
|
||||||
|
Loading…
Reference in New Issue
Block a user