Updated libpng to latest release.

This commit is contained in:
Stephen Anthony 2024-10-31 16:13:50 -02:30
parent f8ecf21384
commit 5ccf090154
5 changed files with 76 additions and 109 deletions

View File

@ -14,7 +14,7 @@
#include "pngpriv.h" #include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */ /* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_6_43 Your_png_h_is_not_version_1_6_43; typedef png_libpng_version_1_6_44 Your_png_h_is_not_version_1_6_44;
/* Tells libpng that we have already handled the first "num_bytes" bytes /* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another * of the PNG file signature. If the PNG data is embedded into another
@ -794,7 +794,7 @@ png_get_copyright(png_const_structrp png_ptr)
return PNG_STRING_COPYRIGHT return PNG_STRING_COPYRIGHT
#else #else
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.6.43" PNG_STRING_NEWLINE \ "libpng version 1.6.44" PNG_STRING_NEWLINE \
"Copyright (c) 2018-2024 Cosmin Truta" PNG_STRING_NEWLINE \ "Copyright (c) 2018-2024 Cosmin Truta" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson" \ "Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson" \
PNG_STRING_NEWLINE \ PNG_STRING_NEWLINE \
@ -1203,6 +1203,24 @@ png_colorspace_sync(png_const_structrp png_ptr, png_inforp info_ptr)
#endif /* GAMMA */ #endif /* GAMMA */
#ifdef PNG_COLORSPACE_SUPPORTED #ifdef PNG_COLORSPACE_SUPPORTED
static int
png_safe_add(png_int_32 *addend0_and_result, png_int_32 addend1,
png_int_32 addend2) {
/* Safely add three integers. Returns 0 on success, 1 on overlow.
* IMPLEMENTATION NOTE: ANSI requires signed overflow not to occur, therefore
* relying on addition of two positive values producing a negative one is not
* safe.
*/
int addend0 = *addend0_and_result;
if (0x7fffffff - addend0 < addend1)
return 1;
addend0 += addend1;
if (0x7fffffff - addend1 < addend2)
return 1;
*addend0_and_result = addend0 + addend2;
return 0;
}
/* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for /* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for
* cHRM, as opposed to using chromaticities. These internal APIs return * cHRM, as opposed to using chromaticities. These internal APIs return
* non-zero on a parameter error. The X, Y and Z values are required to be * non-zero on a parameter error. The X, Y and Z values are required to be
@ -1211,38 +1229,52 @@ png_colorspace_sync(png_const_structrp png_ptr, png_inforp info_ptr)
static int static int
png_xy_from_XYZ(png_xy *xy, const png_XYZ *XYZ) png_xy_from_XYZ(png_xy *xy, const png_XYZ *XYZ)
{ {
png_int_32 d, dwhite, whiteX, whiteY; png_int_32 d, dred, dgreen, dwhite, whiteX, whiteY;
d = XYZ->red_X + XYZ->red_Y + XYZ->red_Z; /* 'd' in each of the blocks below is just X+Y+Z for each component,
* x, y and z are X,Y,Z/(X+Y+Z).
*/
d = XYZ->red_X;
if (png_safe_add(&d, XYZ->red_Y, XYZ->red_Z))
return 1;
if (png_muldiv(&xy->redx, XYZ->red_X, PNG_FP_1, d) == 0) if (png_muldiv(&xy->redx, XYZ->red_X, PNG_FP_1, d) == 0)
return 1; return 1;
if (png_muldiv(&xy->redy, XYZ->red_Y, PNG_FP_1, d) == 0) if (png_muldiv(&xy->redy, XYZ->red_Y, PNG_FP_1, d) == 0)
return 1; return 1;
dwhite = d; dred = d;
whiteX = XYZ->red_X; whiteX = XYZ->red_X;
whiteY = XYZ->red_Y; whiteY = XYZ->red_Y;
d = XYZ->green_X + XYZ->green_Y + XYZ->green_Z; d = XYZ->green_X;
if (png_safe_add(&d, XYZ->green_Y, XYZ->green_Z))
return 1;
if (png_muldiv(&xy->greenx, XYZ->green_X, PNG_FP_1, d) == 0) if (png_muldiv(&xy->greenx, XYZ->green_X, PNG_FP_1, d) == 0)
return 1; return 1;
if (png_muldiv(&xy->greeny, XYZ->green_Y, PNG_FP_1, d) == 0) if (png_muldiv(&xy->greeny, XYZ->green_Y, PNG_FP_1, d) == 0)
return 1; return 1;
dwhite += d; dgreen = d;
whiteX += XYZ->green_X; whiteX += XYZ->green_X;
whiteY += XYZ->green_Y; whiteY += XYZ->green_Y;
d = XYZ->blue_X + XYZ->blue_Y + XYZ->blue_Z; d = XYZ->blue_X;
if (png_safe_add(&d, XYZ->blue_Y, XYZ->blue_Z))
return 1;
if (png_muldiv(&xy->bluex, XYZ->blue_X, PNG_FP_1, d) == 0) if (png_muldiv(&xy->bluex, XYZ->blue_X, PNG_FP_1, d) == 0)
return 1; return 1;
if (png_muldiv(&xy->bluey, XYZ->blue_Y, PNG_FP_1, d) == 0) if (png_muldiv(&xy->bluey, XYZ->blue_Y, PNG_FP_1, d) == 0)
return 1; return 1;
dwhite += d;
whiteX += XYZ->blue_X; whiteX += XYZ->blue_X;
whiteY += XYZ->blue_Y; whiteY += XYZ->blue_Y;
/* The reference white is simply the sum of the end-point (X,Y,Z) vectors, /* The reference white is simply the sum of the end-point (X,Y,Z) vectors so
* thus: * the fillowing calculates (X+Y+Z) of the reference white (media white,
* encoding white) itself:
*/ */
if (png_safe_add(&d, dred, dgreen))
return 1;
dwhite = d;
if (png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite) == 0) if (png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite) == 0)
return 1; return 1;
if (png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite) == 0) if (png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite) == 0)
@ -1257,20 +1289,6 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
png_fixed_point red_inverse, green_inverse, blue_scale; png_fixed_point red_inverse, green_inverse, blue_scale;
png_fixed_point left, right, denominator; png_fixed_point left, right, denominator;
/* Check xy and, implicitly, z. Note that wide gamut color spaces typically
* have end points with 0 tristimulus values (these are impossible end
* points, but they are used to cover the possible colors). We check
* xy->whitey against 5, not 0, to avoid a possible integer overflow.
*/
if (xy->redx < 0 || xy->redx > PNG_FP_1) return 1;
if (xy->redy < 0 || xy->redy > PNG_FP_1-xy->redx) return 1;
if (xy->greenx < 0 || xy->greenx > PNG_FP_1) return 1;
if (xy->greeny < 0 || xy->greeny > PNG_FP_1-xy->greenx) return 1;
if (xy->bluex < 0 || xy->bluex > PNG_FP_1) return 1;
if (xy->bluey < 0 || xy->bluey > PNG_FP_1-xy->bluex) return 1;
if (xy->whitex < 0 || xy->whitex > PNG_FP_1) return 1;
if (xy->whitey < 5 || xy->whitey > PNG_FP_1-xy->whitex) return 1;
/* The reverse calculation is more difficult because the original tristimulus /* The reverse calculation is more difficult because the original tristimulus
* value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8 * value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8
* derived values were recorded in the cHRM chunk; * derived values were recorded in the cHRM chunk;
@ -1451,16 +1469,16 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
* value of 2 indicates an internal error to the caller. * value of 2 indicates an internal error to the caller.
*/ */
if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 7) == 0) if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 7) == 0)
return 2; return 1;
if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 7) == 0) if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 7) == 0)
return 2; return 1;
denominator = left - right; denominator = left - right;
/* Now find the red numerator. */ /* Now find the red numerator. */
if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 7) == 0) if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 7) == 0)
return 2; return 1;
if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 7) == 0) if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 7) == 0)
return 2; return 1;
/* Overflow is possible here and it indicates an extreme set of PNG cHRM /* Overflow is possible here and it indicates an extreme set of PNG cHRM
* chunk values. This calculation actually returns the reciprocal of the * chunk values. This calculation actually returns the reciprocal of the
@ -1473,9 +1491,9 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
/* Similarly for green_inverse: */ /* Similarly for green_inverse: */
if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 7) == 0) if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 7) == 0)
return 2; return 1;
if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 7) == 0) if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 7) == 0)
return 2; return 1;
if (png_muldiv(&green_inverse, xy->whitey, denominator, left-right) == 0 || if (png_muldiv(&green_inverse, xy->whitey, denominator, left-right) == 0 ||
green_inverse <= xy->whitey) green_inverse <= xy->whitey)
return 1; return 1;
@ -1520,25 +1538,14 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
static int static int
png_XYZ_normalize(png_XYZ *XYZ) png_XYZ_normalize(png_XYZ *XYZ)
{ {
png_int_32 Y; png_int_32 Y, Ytemp;
if (XYZ->red_Y < 0 || XYZ->green_Y < 0 || XYZ->blue_Y < 0 || /* Normalize by scaling so the sum of the end-point Y values is PNG_FP_1. */
XYZ->red_X < 0 || XYZ->green_X < 0 || XYZ->blue_X < 0 || Ytemp = XYZ->red_Y;
XYZ->red_Z < 0 || XYZ->green_Z < 0 || XYZ->blue_Z < 0) if (png_safe_add(&Ytemp, XYZ->green_Y, XYZ->blue_Y))
return 1; return 1;
/* Normalize by scaling so the sum of the end-point Y values is PNG_FP_1. Y = Ytemp;
* IMPLEMENTATION NOTE: ANSI requires signed overflow not to occur, therefore
* relying on addition of two positive values producing a negative one is not
* safe.
*/
Y = XYZ->red_Y;
if (0x7fffffff - Y < XYZ->green_X)
return 1;
Y += XYZ->green_Y;
if (0x7fffffff - Y < XYZ->blue_X)
return 1;
Y += XYZ->blue_Y;
if (Y != PNG_FP_1) if (Y != PNG_FP_1)
{ {

View File

@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library /* png.h - header file for PNG reference library
* *
* libpng version 1.6.43 * libpng version 1.6.44
* *
* Copyright (c) 2018-2024 Cosmin Truta * Copyright (c) 2018-2024 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
@ -15,7 +15,7 @@
* libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger * libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.6.35, July 2018: * libpng versions 0.97, January 1998, through 1.6.35, July 2018:
* Glenn Randers-Pehrson * Glenn Randers-Pehrson
* libpng versions 1.6.36, December 2018, through 1.6.43, February 2024: * libpng versions 1.6.36, December 2018, through 1.6.44, September 2024:
* Cosmin Truta * Cosmin Truta
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
*/ */
@ -239,7 +239,7 @@
* ... * ...
* 1.5.30 15 10530 15.so.15.30[.0] * 1.5.30 15 10530 15.so.15.30[.0]
* ... * ...
* 1.6.43 16 10643 16.so.16.43[.0] * 1.6.44 16 10644 16.so.16.44[.0]
* *
* Henceforth the source version will match the shared-library major and * Henceforth the source version will match the shared-library major and
* minor numbers; the shared-library major version number will be used for * minor numbers; the shared-library major version number will be used for
@ -275,7 +275,7 @@
*/ */
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.6.43" #define PNG_LIBPNG_VER_STRING "1.6.44"
#define PNG_HEADER_VERSION_STRING " libpng version " PNG_LIBPNG_VER_STRING "\n" #define PNG_HEADER_VERSION_STRING " libpng version " PNG_LIBPNG_VER_STRING "\n"
/* The versions of shared library builds should stay in sync, going forward */ /* The versions of shared library builds should stay in sync, going forward */
@ -286,7 +286,7 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 6 #define PNG_LIBPNG_VER_MINOR 6
#define PNG_LIBPNG_VER_RELEASE 43 #define PNG_LIBPNG_VER_RELEASE 44
/* This should be zero for a public release, or non-zero for a /* This should be zero for a public release, or non-zero for a
* development version. * development version.
@ -317,7 +317,7 @@
* From version 1.0.1 it is: * From version 1.0.1 it is:
* XXYYZZ, where XX=major, YY=minor, ZZ=release * XXYYZZ, where XX=major, YY=minor, ZZ=release
*/ */
#define PNG_LIBPNG_VER 10643 /* 1.6.43 */ #define PNG_LIBPNG_VER 10644 /* 1.6.44 */
/* Library configuration: these options cannot be changed after /* Library configuration: these options cannot be changed after
* the library has been built. * the library has been built.
@ -427,7 +427,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h /* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number. * do not agree upon the version number.
*/ */
typedef char* png_libpng_version_1_6_43; typedef char* png_libpng_version_1_6_44;
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info. /* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
* *
@ -824,7 +824,7 @@ typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp,
* your compiler. This may be very difficult - try using a different compiler * your compiler. This may be very difficult - try using a different compiler
* to build the library! * to build the library!
*/ */
PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef); PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), (jmp_buf, int), typedef);
#endif #endif
/* Transform masks for the high-level interface */ /* Transform masks for the high-level interface */

View File

@ -1,7 +1,7 @@
/* pngconf.h - machine-configurable file for libpng /* pngconf.h - machine-configurable file for libpng
* *
* libpng version 1.6.43 * libpng version 1.6.44
* *
* Copyright (c) 2018-2024 Cosmin Truta * Copyright (c) 2018-2024 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson
@ -88,7 +88,7 @@
/* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect /* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect
* against legacy (pre ISOC90) compilers that did not understand function * against legacy (pre ISOC90) compilers that did not understand function
* prototypes. It is not required for modern C compilers. * prototypes. [Deprecated.]
*/ */
#ifndef PNGARG #ifndef PNGARG
# define PNGARG(arglist) arglist # define PNGARG(arglist) arglist
@ -298,7 +298,7 @@
#ifndef PNG_EXPORTA #ifndef PNG_EXPORTA
# define PNG_EXPORTA(ordinal, type, name, args, attributes) \ # define PNG_EXPORTA(ordinal, type, name, args, attributes) \
PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), PNGARG(args), \ PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), args, \
PNG_LINKAGE_API attributes) PNG_LINKAGE_API attributes)
#endif #endif
@ -316,7 +316,7 @@
#endif #endif
#ifndef PNG_CALLBACK #ifndef PNG_CALLBACK
# define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args) # define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) args
#endif #endif
/* Support for compiler specific function attributes. These are used /* Support for compiler specific function attributes. These are used

View File

@ -20,13 +20,14 @@
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr, static PNG_FUNCTION(void /* PRIVATE */,
png_const_charp error_message)),PNG_NORETURN); png_default_error,(png_const_structrp png_ptr, png_const_charp error_message),
PNG_NORETURN);
#ifdef PNG_WARNINGS_SUPPORTED #ifdef PNG_WARNINGS_SUPPORTED
static void /* PRIVATE */ static void /* PRIVATE */
png_default_warning PNGARG((png_const_structrp png_ptr, png_default_warning(png_const_structrp png_ptr,
png_const_charp warning_message)); png_const_charp warning_message);
#endif /* WARNINGS */ #endif /* WARNINGS */
/* This function is called whenever there is a fatal error. This function /* This function is called whenever there is a fatal error. This function

View File

@ -140,47 +140,6 @@
* callbacks to do this. * callbacks to do this.
*/ */
# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon # define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon
/* By default the 'intrinsics' code in arm/filter_neon_intrinsics.c is used
* if possible - if __ARM_NEON__ is set and the compiler version is not known
* to be broken. This is controlled by PNG_ARM_NEON_IMPLEMENTATION which can
* be:
*
* 1 The intrinsics code (the default with __ARM_NEON__)
* 2 The hand coded assembler (the default without __ARM_NEON__)
*
* It is possible to set PNG_ARM_NEON_IMPLEMENTATION in CPPFLAGS, however
* this is *NOT* supported and may cease to work even after a minor revision
* to libpng. It *is* valid to do this for testing purposes, e.g. speed
* testing or a new compiler, but the results should be communicated to the
* libpng implementation list for incorporation in the next minor release.
*/
# ifndef PNG_ARM_NEON_IMPLEMENTATION
# if defined(__ARM_NEON__) || defined(__ARM_NEON)
# if defined(__clang__)
/* At present it is unknown by the libpng developers which versions
* of clang support the intrinsics, however some or perhaps all
* versions do not work with the assembler so this may be
* irrelevant, so just use the default (do nothing here.)
*/
# elif defined(__GNUC__)
/* GCC 4.5.4 NEON support is known to be broken. 4.6.3 is known to
* work, so if this *is* GCC, or G++, look for a version >4.5
*/
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
# define PNG_ARM_NEON_IMPLEMENTATION 2
# endif /* no GNUC support */
# endif /* __GNUC__ */
# else /* !defined __ARM_NEON__ */
/* The 'intrinsics' code simply won't compile without this -mfpu=neon:
*/
# if !defined(__aarch64__) && !defined(_M_ARM64)
/* The assembler code currently does not work on ARM64 */
# define PNG_ARM_NEON_IMPLEMENTATION 2
# endif /* __aarch64__ */
# endif /* __ARM_NEON__ */
# endif /* !PNG_ARM_NEON_IMPLEMENTATION */
# ifndef PNG_ARM_NEON_IMPLEMENTATION # ifndef PNG_ARM_NEON_IMPLEMENTATION
/* Use the intrinsics code by default. */ /* Use the intrinsics code by default. */
# define PNG_ARM_NEON_IMPLEMENTATION 1 # define PNG_ARM_NEON_IMPLEMENTATION 1