makepng fixes for the palette case

Also allow extra command line arguments; convenient for testing odd things.

Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
John Bowler 2015-09-26 16:44:29 -07:00
parent 23324b8559
commit eab2c419fa
2 changed files with 27 additions and 19 deletions

View File

@ -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;

View File

@ -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";;&