mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
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:
parent
23324b8559
commit
eab2c419fa
@ -1362,19 +1362,16 @@ insert_hIST(png_structp png_ptr, png_infop info_ptr, int nparams,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static png_byte
|
static png_byte
|
||||||
bval(png_charp param)
|
bval(png_const_structrp png_ptr, png_charp param, unsigned int maxval)
|
||||||
{
|
{
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
unsigned long int l = strtoul(param, &endptr, 0/*base*/);
|
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;
|
return (png_byte)l;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
png_error(png_ptr, "sBIT: invalid sBIT value");
|
||||||
fprintf(stderr, "sBIT: invalid sBIT value '%s'\n", param);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1382,32 +1379,31 @@ insert_sBIT(png_structp png_ptr, png_infop info_ptr, int nparams,
|
|||||||
png_charpp params)
|
png_charpp params)
|
||||||
{
|
{
|
||||||
const int ct = png_get_color_type(png_ptr, info_ptr);
|
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;
|
png_color_8 sBIT;
|
||||||
|
|
||||||
if (nparams != c)
|
if (nparams != c)
|
||||||
{
|
png_error(png_ptr, "sBIT: incorrect parameter count");
|
||||||
fprintf(stderr, "sBIT: expected parameter count %d, not %d\n", c,
|
|
||||||
nparams);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ct & PNG_COLOR_MASK_COLOR)
|
if (ct & PNG_COLOR_MASK_COLOR)
|
||||||
{
|
{
|
||||||
sBIT.red = bval(params[0]);
|
sBIT.red = bval(png_ptr, params[0], maxval);
|
||||||
sBIT.green = bval(params[1]);
|
sBIT.green = bval(png_ptr, params[1], maxval);
|
||||||
sBIT.blue = bval(params[2]);
|
sBIT.blue = bval(png_ptr, params[2], maxval);
|
||||||
sBIT.gray = 42;
|
sBIT.gray = 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sBIT.red = sBIT.green = sBIT.blue = 42;
|
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)
|
if (ct & PNG_COLOR_MASK_ALPHA)
|
||||||
sBIT.alpha = bval(params[nparams-1]);
|
sBIT.alpha = bval(png_ptr, params[nparams-1], maxval);
|
||||||
|
|
||||||
else
|
else
|
||||||
sBIT.alpha = 42;
|
sBIT.alpha = 42;
|
||||||
|
@ -15,10 +15,22 @@
|
|||||||
# ones that extend the code-coverage of libpng from the existing test files in
|
# ones that extend the code-coverage of libpng from the existing test files in
|
||||||
# contrib/pngsuite.
|
# contrib/pngsuite.
|
||||||
test -n "$MAKEPNG" || MAKEPNG=./makepng
|
test -n "$MAKEPNG" || MAKEPNG=./makepng
|
||||||
|
if test "$1" = "-v"
|
||||||
|
then
|
||||||
|
verbose=1
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
verbose=
|
||||||
|
fi
|
||||||
|
what="$1"
|
||||||
|
shift
|
||||||
|
cmdline="$@"
|
||||||
opts=
|
opts=
|
||||||
|
|
||||||
mp(){
|
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(){
|
mpg(){
|
||||||
@ -39,7 +51,7 @@ mptrans(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$what" in
|
||||||
--small)
|
--small)
|
||||||
opts="--small";;&
|
opts="--small";;&
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user