diff --git a/ANNOUNCE b/ANNOUNCE index 20ec4cf14..a3cd3de41 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -195,7 +195,9 @@ Version 1.5.4beta01 [June 14, 2011] Version 1.5.4beta02 [June 14, 2011] Fixed and clarified LEGACY 16-to-8 scaling code. - Added png_set_chop_16() API. + Added png_set_chop_16() API, to match inaccurate results from previous + libpng versions. + Removed the ACCURATE and LEGACY options (they are no longer useable) Send comments/corrections/commendations to png-mng-implement at lists.sf.net: (subscription required; visit diff --git a/CHANGES b/CHANGES index 1b2b9b61e..b77e43da8 100644 --- a/CHANGES +++ b/CHANGES @@ -3458,7 +3458,9 @@ Version 1.5.4beta01 [June 14, 2011] Version 1.5.4beta02 [June 14, 2011] Fixed and clarified LEGACY 16-to-8 scaling code. - Added png_set_chop_16() API. + Added png_set_chop_16() API, to match inaccurate results from previous + libpng versions. + Removed the ACCURATE and LEGACY options (they are no longer useable) Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/example.c b/example.c index f15176324..2c1f27da6 100644 --- a/example.c +++ b/example.c @@ -2,7 +2,7 @@ #if 0 /* in case someone actually tries to compile this */ /* example.c - an example of using libpng - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * This file has been placed in the public domain by the authors. * Maintained 1998-2011 Glenn Randers-Pehrson * Maintained 1996, 1997 Andreas Dilger) diff --git a/png.h b/png.h index 65e407f5a..901e588a3 100644 --- a/png.h +++ b/png.h @@ -1423,6 +1423,8 @@ PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structp png_ptr, #endif #ifdef PNG_READ_16_TO_8_SUPPORTED +/* The following is always done from 1.5.4: */ +#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED /* Scale a 16-bit depth file down to 8-bit, accurately. */ PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr)); /* Strip the second byte of information from a 16-bit depth file. */ diff --git a/pngconf.h b/pngconf.h index adaf7dbc6..30e401023 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.5.4beta01 - June 14, 2011 + * libpng version 1.5.4beta02 - June 14, 2011 * * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngerror.c b/pngerror.c index 419f83a7f..c3ce2494e 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,7 +1,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) diff --git a/pngmem.c b/pngmem.c index 16161c796..7fd54eb24 100644 --- a/pngmem.c +++ b/pngmem.c @@ -1,7 +1,7 @@ /* pngmem.c - stub functions for memory allocation * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) diff --git a/pngpriv.h b/pngpriv.h index ec0b4755c..ad0ef80bc 100644 --- a/pngpriv.h +++ b/pngpriv.h @@ -6,7 +6,7 @@ * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer @@ -298,7 +298,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; #define PNG_ENCODE_ALPHA 0x800000L /* Added to libpng-1.5.3 */ #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */ #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */ - /* 0x4000000L unused */ +#define PNG_CHOP_16_TO_8 0x4000000L /* 0x8000000L unused */ /* 0x10000000L unused */ /* 0x20000000L unused */ @@ -820,8 +820,13 @@ PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, #endif #ifdef PNG_READ_16_TO_8_SUPPORTED +PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info, + png_bytep row)); + PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row)); +PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info, + png_bytep row)); #endif #ifdef PNG_READ_QUANTIZE_SUPPORTED diff --git a/pngread.c b/pngread.c index 2ef9feaa9..a39c83b99 100644 --- a/pngread.c +++ b/pngread.c @@ -1,7 +1,7 @@ /* pngread.c - read a PNG file * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) diff --git a/pngrtran.c b/pngrtran.c index 867145fea..488e7cd0f 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1453,11 +1453,7 @@ png_init_read_transformations(png_structp png_ptr) * The PNG_BACKGROUND_EXPAND code above does not expand to 16 bits at * present, so that case is ok (until do_expand_16 is moved.) */ -#ifdef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED # define CHOP(x) (x)=((png_uint_16)(((png_uint_32)(x)*255+32895) >> 16)) -#else -# define CHOP(x) ((png_uint_16)((2*(png_uint_32)(x) + 257)/514)) -#endif CHOP(png_ptr->background.red); CHOP(png_ptr->background.green); CHOP(png_ptr->background.blue); diff --git a/pngrutil.c b/pngrutil.c index e1cc84747..1c802ef26 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) diff --git a/pngstruct.h b/pngstruct.h index 60aaae2eb..4af9ba2ef 100644 --- a/pngstruct.h +++ b/pngstruct.h @@ -5,7 +5,7 @@ * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer diff --git a/pngtrans.c b/pngtrans.c index 16582d104..5dcbfb43d 100644 --- a/pngtrans.c +++ b/pngtrans.c @@ -1,7 +1,7 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) diff --git a/pngvalid.c b/pngvalid.c index d55a5d891..8a7b21614 100644 --- a/pngvalid.c +++ b/pngvalid.c @@ -1,7 +1,7 @@ /* pngvalid.c - validate libpng by constructing then reading png files. * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 2011 Glenn Randers-Pehrson * Written by John Cunningham Bowler * @@ -5265,6 +5265,8 @@ image_transform_png_set_strip_16_mod(PNG_CONST image_transform *this, # ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED /* The strip 16 algorithm drops the low 8 bits rather than calculating * 1/257, so we need to adjust the permitted errors appropriately: + * Notice that this is only relevant prior to the addition of the + * png_set_chop_16 API in 1.5.4 (but 1.5.4+ always defines the above!) */ { PNG_CONST double d = (255-128.5)/65535; @@ -5294,6 +5296,60 @@ image_transform_png_set_strip_16_add(image_transform *this, IT(strip_16); #undef PT #define PT ITSTRUCT(strip_16) + +#if PNG_LIBPNG_VER >= 10504 /* API added in 1.5.4 */ +/* png_set_chop_16 */ +static void +image_transform_png_set_chop_16_set(PNG_CONST image_transform *this, + transform_display *that, png_structp pp, png_infop pi) +{ + png_set_chop_16(pp); + this->next->set(this->next, that, pp, pi); +} + +static void +image_transform_png_set_chop_16_mod(PNG_CONST image_transform *this, + image_pixel *that, png_structp pp, PNG_CONST transform_display *display) +{ + if (that->bit_depth == 16) + { + that->sample_depth = that->bit_depth = 8; + if (that->red_sBIT > 8) that->red_sBIT = 8; + if (that->green_sBIT > 8) that->green_sBIT = 8; + if (that->blue_sBIT > 8) that->blue_sBIT = 8; + if (that->alpha_sBIT > 8) that->alpha_sBIT = 8; + + /* From 1.5.4 there is a separate API to do the low byte drop; see the + * comments above for why this requires the following: + */ + { + PNG_CONST double d = (255-128.5)/65535; + that->rede += d; + that->greene += d; + that->bluee += d; + that->alphae += d; + } + } + + this->next->mod(this->next, that, pp, display); +} + +static int +image_transform_png_set_chop_16_add(image_transform *this, + PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth) +{ + UNUSED(colour_type) + + this->next = *that; + *that = this; + + return bit_depth > 8; +} + +IT(chop_16); +#undef PT +#define PT ITSTRUCT(chop_16) +#endif /* From libpng 1.5.4 */ #endif /* PNG_READ_16_TO_8_SUPPORTED */ #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED diff --git a/pngwrite.c b/pngwrite.c index 30805eeeb..2328aa31e 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,7 +1,7 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) diff --git a/pngwtran.c b/pngwtran.c index a5003d0a5..7b4c0538c 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -1,7 +1,7 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) diff --git a/pngwutil.c b/pngwutil.c index adca5fcd7..9ecf3cea5 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,7 +1,7 @@ /* pngwutil.c - utilities to write a PNG file * - * Last changed in libpng 1.5.3 [(PENDING RELEASE)] + * Last changed in libpng 1.5.4 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) diff --git a/scripts/symbols.def b/scripts/symbols.def index 457673c94..d1787f58a 100644 --- a/scripts/symbols.def +++ b/scripts/symbols.def @@ -5,7 +5,7 @@ LIBRARY EXPORTS -;Version 1.5.4beta01 +;Version 1.5.4beta02 png_access_version_number @1 png_set_sig_bytes @2 png_sig_cmp @3 @@ -234,3 +234,4 @@ EXPORTS png_set_text_compression_method @226 png_set_alpha_mode @227 png_set_alpha_mode_fixed @228 + png_set_chop_16 @229