mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
sBIT code coverage and fixes
Fixes for sBIT handling in the low-bit-depth gray and pngstest cases, extends sBIT handling to the colormap code in the simplified API which is separately implemented in pngread.c Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
@@ -1361,6 +1361,60 @@ insert_hIST(png_structp png_ptr, png_infop info_ptr, int nparams,
|
||||
png_set_hIST(png_ptr, info_ptr, freq);
|
||||
}
|
||||
|
||||
static png_byte
|
||||
bval(png_charp param)
|
||||
{
|
||||
char *endptr = NULL;
|
||||
unsigned long int l = strtoul(param, &endptr, 0/*base*/);
|
||||
|
||||
if (param[0] && *endptr == 0 && l <= 255)
|
||||
return (png_byte)l;
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "sBIT: invalid sBIT value '%s'\n", param);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
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);
|
||||
png_color_8 sBIT;
|
||||
|
||||
if (nparams != c)
|
||||
{
|
||||
fprintf(stderr, "sBIT: expected parameter count %d, not %d\n", c,
|
||||
nparams);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ct & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
sBIT.red = bval(params[0]);
|
||||
sBIT.green = bval(params[1]);
|
||||
sBIT.blue = bval(params[2]);
|
||||
sBIT.gray = 42;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
sBIT.red = sBIT.green = sBIT.blue = 42;
|
||||
sBIT.gray = bval(params[0]);
|
||||
}
|
||||
|
||||
if (ct & PNG_COLOR_MASK_ALPHA)
|
||||
sBIT.alpha = bval(params[nparams-1]);
|
||||
|
||||
else
|
||||
sBIT.alpha = 42;
|
||||
|
||||
png_set_sBIT(png_ptr, info_ptr, &sBIT);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
insert_sPLT(png_structp png_ptr, png_infop info_ptr, int nparams, png_charpp params)
|
||||
@@ -1488,6 +1542,11 @@ find_insert(png_const_charp what, png_charp param)
|
||||
return make_insert(what, insert_hIST, nparams, parameter_list);
|
||||
break;
|
||||
|
||||
case CHUNK(115,66,73,84): /* sBIT */
|
||||
if (nparams <= 4)
|
||||
return make_insert(what, insert_sBIT, nparams, parameter_list);
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case CHUNK(115,80,76,84): /* sPLT */
|
||||
return make_insert(what, insert_sPLT, nparams, parameter_list);
|
||||
|
||||
@@ -1949,7 +1949,7 @@ typedef struct png_modifier
|
||||
unsigned int repeat :1; /* Repeat this transform test. */
|
||||
unsigned int test_uses_encoding :1;
|
||||
|
||||
/* Lowest sbit to test (libpng fails for sbit < 8) */
|
||||
/* Lowest sbit to test (pre-1.7 libpng fails for sbit < 8) */
|
||||
png_byte sbitlow;
|
||||
|
||||
/* Error control - these are the limits on errors accepted by the gamma tests
|
||||
@@ -2036,7 +2036,7 @@ typedef struct png_modifier
|
||||
unsigned int test_gamma_expand16 :1;
|
||||
unsigned int test_exhaustive :1;
|
||||
|
||||
/* Whether or not to run the low-bit-depth grayscale tests. This fail on
|
||||
/* Whether or not to run the low-bit-depth grayscale tests. This fails on
|
||||
* gamma images in some cases because of gross inaccuracies in the grayscale
|
||||
* gamma handling for low bit depth.
|
||||
*/
|
||||
@@ -11125,7 +11125,11 @@ int main(int argc, char **argv)
|
||||
pm.encodings = test_encodings;
|
||||
pm.nencodings = ARRAY_SIZE(test_encodings);
|
||||
|
||||
pm.sbitlow = 8U; /* because libpng doesn't do sBIT below 8! */
|
||||
# if PNG_LIBPNG_VER < 10700
|
||||
pm.sbitlow = 8U; /* because libpng doesn't do sBIT below 8! */
|
||||
# else
|
||||
pm.sbitlow = 1U;
|
||||
# endif
|
||||
|
||||
/* The following allows results to pass if they correspond to anything in the
|
||||
* transformed range [input-.5,input+.5]; this is is required because of the
|
||||
|
||||
Reference in New Issue
Block a user