From eab2c419fa8bb6a37a4a6e8b513dc8f2e71da2bb Mon Sep 17 00:00:00 2001 From: John Bowler Date: Sat, 26 Sep 2015 16:44:29 -0700 Subject: [PATCH] makepng fixes for the palette case Also allow extra command line arguments; convenient for testing odd things. Signed-off-by: John Bowler --- contrib/libtests/makepng.c | 30 +++++++++++++----------------- contrib/testpngs/makepngs.sh | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/contrib/libtests/makepng.c b/contrib/libtests/makepng.c index 8f009a507..1d3a0addd 100644 --- a/contrib/libtests/makepng.c +++ b/contrib/libtests/makepng.c @@ -1362,19 +1362,16 @@ insert_hIST(png_structp png_ptr, png_infop info_ptr, int nparams, } static png_byte -bval(png_charp param) +bval(png_const_structrp png_ptr, png_charp param, unsigned int maxval) { char *endptr = NULL; unsigned long int l = strtoul(param, &endptr, 0/*base*/); - if (param[0] && *endptr == 0 && l <= 255) + if (param[0] && *endptr == 0 && l <= maxval) return (png_byte)l; else - { - fprintf(stderr, "sBIT: invalid sBIT value '%s'\n", param); - exit(1); - } + png_error(png_ptr, "sBIT: invalid sBIT value"); } static void @@ -1382,32 +1379,31 @@ insert_sBIT(png_structp png_ptr, png_infop info_ptr, int nparams, png_charpp params) { const int ct = png_get_color_type(png_ptr, info_ptr); - const int c = channels_of_type(ct); + const int c = (ct & PNG_COLOR_MASK_COLOR ? 3 : 1) + + (ct & PNG_COLOR_MASK_ALPHA ? 1 : 0); + const unsigned int maxval = + ct & PNG_COLOR_MASK_PALETTE ? 8U : png_get_bit_depth(png_ptr, info_ptr); png_color_8 sBIT; if (nparams != c) - { - fprintf(stderr, "sBIT: expected parameter count %d, not %d\n", c, - nparams); - exit(1); - } + png_error(png_ptr, "sBIT: incorrect parameter count"); if (ct & PNG_COLOR_MASK_COLOR) { - sBIT.red = bval(params[0]); - sBIT.green = bval(params[1]); - sBIT.blue = bval(params[2]); + sBIT.red = bval(png_ptr, params[0], maxval); + sBIT.green = bval(png_ptr, params[1], maxval); + sBIT.blue = bval(png_ptr, params[2], maxval); sBIT.gray = 42; } else { sBIT.red = sBIT.green = sBIT.blue = 42; - sBIT.gray = bval(params[0]); + sBIT.gray = bval(png_ptr, params[0], maxval); } if (ct & PNG_COLOR_MASK_ALPHA) - sBIT.alpha = bval(params[nparams-1]); + sBIT.alpha = bval(png_ptr, params[nparams-1], maxval); else sBIT.alpha = 42; diff --git a/contrib/testpngs/makepngs.sh b/contrib/testpngs/makepngs.sh index 761288ea6..caf54ef66 100755 --- a/contrib/testpngs/makepngs.sh +++ b/contrib/testpngs/makepngs.sh @@ -15,10 +15,22 @@ # ones that extend the code-coverage of libpng from the existing test files in # contrib/pngsuite. test -n "$MAKEPNG" || MAKEPNG=./makepng +if test "$1" = "-v" +then + verbose=1 + shift +else + verbose= +fi +what="$1" +shift +cmdline="$@" opts= mp(){ - ${MAKEPNG} $opts $1 "$3" "$4" "$3-$4$2.png" + test -n "$verbose" && + echo ${MAKEPNG} $opts $cmdline $1 "$3" "$4" "$3-$4$2.png" + ${MAKEPNG} $opts $cmdline $1 "$3" "$4" "$3-$4$2.png" } mpg(){ @@ -39,7 +51,7 @@ mptrans(){ fi } -case "$1" in +case "$what" in --small) opts="--small";;&