Skip to content

Commit

Permalink
[libpng16] test: Fix "make check" in all branches beyond 'libpng16'
Browse files Browse the repository at this point in the history
This corrects the checks to that libpng 10800 does not turn on the
enhanced transform checks in either pngvalid or pngstest.  The correct
fix is to change the 10700 code for comments which explain what aspect
or aspects of the transforms are broken (ideally) or at least state that
the transforms are broken.

This is a cherry-pick of commit aec888a
from branch 'libpng18'.

Reviewed-by: Cosmin Truta <[email protected]>
Signed-off-by: John Bowler <[email protected]>
Signed-off-by: Cosmin Truta <[email protected]>
  • Loading branch information
jbowler authored and ctruta committed Sep 20, 2024
1 parent 529e69e commit b8a0a54
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion contrib/libtests/pngstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,7 @@ main(int argc, char **argv)
int retval = 0;
int c;

#if PNG_LIBPNG_VER >= 10700
#if PNG_LIBPNG_VER == 10700
/* This error should not exist in 1.7 or later: */
opts |= GBG_ERROR;
#endif
Expand Down
52 changes: 26 additions & 26 deletions contrib/libtests/pngvalid.c
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,7 @@ modifier_init(png_modifier *pm)
* in the rgb_to_gray check, replacing it with an exact copy of the libpng 1.5
* algorithm.
*/
#define DIGITIZE PNG_LIBPNG_VER < 10700
#define DIGITIZE PNG_LIBPNG_VER != 10700

/* If pm->calculations_use_input_precision is set then operations will happen
* with the precision of the input, not the precision of the output depth.
Expand Down Expand Up @@ -3986,7 +3986,7 @@ transform_row(png_const_structp pp, png_byte buffer[TRANSFORM_ROWMAX],
# define check_interlace_type(type) ((void)(type))
# define set_write_interlace_handling(pp,type) png_set_interlace_handling(pp)
# define do_own_interlace 0
#elif PNG_LIBPNG_VER < 10700
#elif PNG_LIBPNG_VER != 10700
# define set_write_interlace_handling(pp,type) (1)
static void
check_interlace_type(int const interlace_type)
Expand Down Expand Up @@ -4014,7 +4014,7 @@ check_interlace_type(int const interlace_type)
# define do_own_interlace 1
#endif /* WRITE_INTERLACING tests */

#if PNG_LIBPNG_VER >= 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED
#if PNG_LIBPNG_VER == 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED
# define CAN_WRITE_INTERLACE 1
#else
# define CAN_WRITE_INTERLACE 0
Expand Down Expand Up @@ -4633,10 +4633,10 @@ static const struct
{
/* no warnings makes these errors undetectable prior to 1.7.0 */
{ sBIT0_error_fn, "sBIT(0): failed to detect error",
PNG_LIBPNG_VER < 10700 },
PNG_LIBPNG_VER != 10700 },

{ sBIT_error_fn, "sBIT(too big): failed to detect error",
PNG_LIBPNG_VER < 10700 },
PNG_LIBPNG_VER != 10700 },
};

static void
Expand Down Expand Up @@ -6236,7 +6236,7 @@ image_pixel_add_alpha(image_pixel *this, const standard_display *display,
{
if (this->colour_type == PNG_COLOR_TYPE_GRAY)
{
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
if (!for_background && this->bit_depth < 8)
this->bit_depth = this->sample_depth = 8;
# endif
Expand All @@ -6246,7 +6246,7 @@ image_pixel_add_alpha(image_pixel *this, const standard_display *display,
/* After 1.7 the expansion of bit depth only happens if there is a
* tRNS chunk to expand at this point.
*/
# if PNG_LIBPNG_VER >= 10700
# if PNG_LIBPNG_VER == 10700
if (!for_background && this->bit_depth < 8)
this->bit_depth = this->sample_depth = 8;
# endif
Expand Down Expand Up @@ -7127,7 +7127,7 @@ image_transform_png_set_tRNS_to_alpha_mod(const image_transform *this,
image_pixel *that, png_const_structp pp,
const transform_display *display)
{
#if PNG_LIBPNG_VER < 10700
#if PNG_LIBPNG_VER != 10700
/* LIBPNG BUG: this always forces palette images to RGB. */
if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
image_pixel_convert_PLTE(that);
Expand All @@ -7137,13 +7137,13 @@ image_transform_png_set_tRNS_to_alpha_mod(const image_transform *this,
* convert to an alpha channel.
*/
if (that->have_tRNS)
# if PNG_LIBPNG_VER >= 10700
# if PNG_LIBPNG_VER == 10700
if (that->colour_type != PNG_COLOR_TYPE_PALETTE &&
(that->colour_type & PNG_COLOR_MASK_ALPHA) == 0)
# endif
image_pixel_add_alpha(that, &display->this, 0/*!for background*/);

#if PNG_LIBPNG_VER < 10700
#if PNG_LIBPNG_VER != 10700
/* LIBPNG BUG: otherwise libpng still expands to 8 bits! */
else
{
Expand Down Expand Up @@ -7172,7 +7172,7 @@ image_transform_png_set_tRNS_to_alpha_add(image_transform *this,
* any action on a palette image.
*/
return
# if PNG_LIBPNG_VER >= 10700
# if PNG_LIBPNG_VER == 10700
colour_type != PNG_COLOR_TYPE_PALETTE &&
# endif
(colour_type & PNG_COLOR_MASK_ALPHA) == 0;
Expand Down Expand Up @@ -7313,7 +7313,7 @@ image_transform_png_set_expand_gray_1_2_4_to_8_mod(
const image_transform *this, image_pixel *that, png_const_structp pp,
const transform_display *display)
{
#if PNG_LIBPNG_VER < 10700
#if PNG_LIBPNG_VER != 10700
image_transform_png_set_expand_mod(this, that, pp, display);
#else
/* Only expand grayscale of bit depth less than 8: */
Expand All @@ -7329,7 +7329,7 @@ static int
image_transform_png_set_expand_gray_1_2_4_to_8_add(image_transform *this,
const image_transform **that, png_byte colour_type, png_byte bit_depth)
{
#if PNG_LIBPNG_VER < 10700
#if PNG_LIBPNG_VER != 10700
return image_transform_png_set_expand_add(this, that, colour_type,
bit_depth);
#else
Expand Down Expand Up @@ -7359,7 +7359,7 @@ image_transform_png_set_expand_16_set(const image_transform *this,
png_set_expand_16(pp);

/* NOTE: prior to 1.7 libpng does SET_EXPAND as well, so tRNS is expanded. */
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
if (that->this.has_tRNS)
that->this.is_transparent = 1;
# endif
Expand Down Expand Up @@ -7412,7 +7412,7 @@ image_transform_png_set_scale_16_set(const image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_scale_16(pp);
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
/* libpng will limit the gamma table size: */
that->max_gamma_8 = PNG_MAX_GAMMA_8;
# endif
Expand Down Expand Up @@ -7460,7 +7460,7 @@ image_transform_png_set_strip_16_set(const image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_strip_16(pp);
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
/* libpng will limit the gamma table size: */
that->max_gamma_8 = PNG_MAX_GAMMA_8;
# endif
Expand Down Expand Up @@ -7647,7 +7647,7 @@ image_transform_png_set_rgb_to_gray_ini(const image_transform *this,
else
{
/* The default (built in) coefficients, as above: */
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
data.red_coefficient = 6968 / 32768.;
data.green_coefficient = 23434 / 32768.;
data.blue_coefficient = 2366 / 32768.;
Expand Down Expand Up @@ -7730,7 +7730,7 @@ image_transform_png_set_rgb_to_gray_ini(const image_transform *this,
* conversion adds another +/-2 in the 16-bit case and
* +/-(1<<(15-PNG_MAX_GAMMA_8)) in the 8-bit case.
*/
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
if (that->this.bit_depth < 16)
that->max_gamma_8 = PNG_MAX_GAMMA_8;
# endif
Expand Down Expand Up @@ -7907,7 +7907,7 @@ image_transform_png_set_rgb_to_gray_mod(const image_transform *this,
{
double gray, err;

# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
image_pixel_convert_PLTE(that);
# endif
Expand Down Expand Up @@ -8094,7 +8094,7 @@ image_transform_png_set_rgb_to_gray_mod(const image_transform *this,
double b = that->bluef;
double be = that->bluee;

# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
/* The true gray case involves no math in earlier versions (not
* true, there was some if gamma correction was happening too.)
*/
Expand Down Expand Up @@ -9873,7 +9873,7 @@ gamma_component_validate(const char *name, const validate_info *vi,
* lost. This can result in up to a +/-1 error in the presence of
* an sbit less than the bit depth.
*/
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
# define SBIT_ERROR .5
# else
# define SBIT_ERROR 1.
Expand Down Expand Up @@ -10733,7 +10733,7 @@ static void perform_gamma_scale16_tests(png_modifier *pm)
# ifndef PNG_MAX_GAMMA_8
# define PNG_MAX_GAMMA_8 11
# endif
# if defined PNG_MAX_GAMMA_8 || PNG_LIBPNG_VER < 10700
# if defined PNG_MAX_GAMMA_8 || PNG_LIBPNG_VER != 10700
# define SBIT_16_TO_8 PNG_MAX_GAMMA_8
# else
# define SBIT_16_TO_8 16
Expand Down Expand Up @@ -11736,7 +11736,7 @@ int main(int argc, char **argv)
* code that 16-bit arithmetic is used for 8-bit samples when it would make a
* difference.
*/
pm.assume_16_bit_calculations = PNG_LIBPNG_VER >= 10700;
pm.assume_16_bit_calculations = PNG_LIBPNG_VER == 10700;

/* Currently 16 bit expansion happens at the end of the pipeline, so the
* calculations are done in the input bit depth not the output.
Expand All @@ -11760,13 +11760,13 @@ int main(int argc, char **argv)
pm.test_lbg_gamma_threshold = 1;
pm.test_lbg_gamma_transform = PNG_LIBPNG_VER >= 10600;
pm.test_lbg_gamma_sbit = 1;
pm.test_lbg_gamma_composition = PNG_LIBPNG_VER >= 10700;
pm.test_lbg_gamma_composition = PNG_LIBPNG_VER == 10700;

/* And the test encodings */
pm.encodings = test_encodings;
pm.nencodings = ARRAY_SIZE(test_encodings);

# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
pm.sbitlow = 8U; /* because libpng doesn't do sBIT below 8! */
# else
pm.sbitlow = 1U;
Expand Down Expand Up @@ -11796,7 +11796,7 @@ int main(int argc, char **argv)
pm.maxout16 = .499; /* Error in *encoded* value */
pm.maxabs16 = .00005;/* 1/20000 */
pm.maxcalc16 =1./65535;/* +/-1 in 16 bits for compose errors */
# if PNG_LIBPNG_VER < 10700
# if PNG_LIBPNG_VER != 10700
pm.maxcalcG = 1./((1<<PNG_MAX_GAMMA_8)-1);
# else
pm.maxcalcG = 1./((1<<16)-1);
Expand Down

0 comments on commit b8a0a54

Please sign in to comment.