Skip to content

Commit

Permalink
Merge tag 'v1.6.46' into libpng18
Browse files Browse the repository at this point in the history
Sync with libpng version 1.6.46
  • Loading branch information
ctruta committed Jan 27, 2025
2 parents 1c56ac6 + 0024abd commit d60d888
Show file tree
Hide file tree
Showing 34 changed files with 898 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ indent_style = space
max_doc_length = 100
max_line_length = 100

[{Makefile.in,ltmain.sh}]
[{Makefile.in,aclocal.m4,ltmain.sh}]
indent_size = unset
indent_style = unset
insert_final_newline = unset
Expand Down
10 changes: 10 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6229,6 +6229,16 @@ Version 1.6.45 [January 7, 2025]
Raised the minimum required CMake version from 3.6 to 3.14.
Forked off a development branch for libpng version 1.8.

Version 1.6.46 [January 23, 2025]
Added support for the mDCV and cLLI chunks.
(Contributed by John Bowler)
Fixed a build issue affecting C89 compilers.
This was a regression introduced in libpng-1.6.45.
(Contributed by John Bowler)
Added makefile.c89, specifically for testing C89 compilers.
Cleaned up contrib/pngminus: corrected an old typo, removed an old
workaround, and updated the CMake file.

Version 1.8.0 [TODO]

Send comments/corrections/commendations to png-mng-implement at lists.sf.net.
Expand Down
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile.am, the source file for Makefile.in (and hence Makefile), is
#
# Copyright (c) 2018-2024 Cosmin Truta
# Copyright (c) 2018-2025 Cosmin Truta
# Copyright (c) 2004-2016 Glenn Randers-Pehrson
#
# This code is released under the libpng license.
Expand Down Expand Up @@ -159,7 +159,7 @@ MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess config.h.in \
config.sub configure depcomp install-sh ltmain.sh missing

# PNG_COPTS give extra options for the C compiler to be used on all compilation
# steps (unless targe_CFLAGS is specified; that will take precedence over
# steps (unless target_CFLAGS is specified; that will take precedence over
# AM_CFLAGS)
PNG_COPTS = @PNG_COPTS@
AM_CFLAGS = ${PNG_COPTS}
Expand Down
25 changes: 25 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Scripts for the Continuous Integration of the PNG Reference Library
===================================================================

Copyright Notice
----------------

Copyright (c) 2019-2024 Cosmin Truta.

Use, modification and distribution are subject to the MIT License.
Please see the accompanying file `LICENSE_MIT.txt` or visit
https://opensource.org/license/mit

File List
---------

LICENSE_MIT.txt ==> The License file
README.md ==> This file
ci_lint.sh ==> Lint the source code
ci_shellify.sh ==> Convert select definitions to shell syntax
ci_verify_cmake.sh ==> Verify the build driven by CMakeLists.txt
ci_verify_configure.sh ==> Verify the build driven by configure
ci_verify_makefiles.sh ==> Verify the build driven by scripts/makefile.*
ci_verify_version.sh ==> Verify the consistency of version definitions
lib/ci.lib.sh ==> Shell utilities for the main ci_*.sh scripts
targets/*/ci_env.*.sh ==> Shell environments for cross-platform testing
24 changes: 24 additions & 0 deletions contrib/libtests/pngunknown.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ typedef png_byte *png_const_bytep;
#define png_PLTE PNG_U32( 80, 76, 84, 69)
#define png_bKGD PNG_U32( 98, 75, 71, 68)
#define png_cHRM PNG_U32( 99, 72, 82, 77)
#define png_cICP PNG_U32( 99, 73, 67, 80) /* PNGv3 */
#define png_cLLI PNG_U32( 99, 76, 76, 73) /* PNGv3 */
#define png_eXIf PNG_U32(101, 88, 73, 102) /* registered July 2017 */
#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
#define png_gAMA PNG_U32(103, 65, 77, 65)
Expand All @@ -121,6 +123,7 @@ typedef png_byte *png_const_bytep;
#define png_hIST PNG_U32(104, 73, 83, 84)
#define png_iCCP PNG_U32(105, 67, 67, 80)
#define png_iTXt PNG_U32(105, 84, 88, 116)
#define png_mDCV PNG_U32(109, 68, 67, 86) /* PNGv3 */
#define png_oFFs PNG_U32(111, 70, 70, 115)
#define png_pCAL PNG_U32(112, 67, 65, 76)
#define png_pHYs PNG_U32(112, 72, 89, 115)
Expand Down Expand Up @@ -205,6 +208,20 @@ static struct
0,
# else
1,
# endif
1, START, 0 },
{ "cICP", PNG_INFO_cICP, png_cICP,
# ifdef PNG_READ_cICP_SUPPORTED
0,
# else
1,
# endif
1, START, 0 },
{ "cLLI", PNG_INFO_cLLI, png_cLLI,
# ifdef PNG_READ_cLLI_SUPPORTED
0,
# else
1,
# endif
1, START, 0 },
{ "eXIf", PNG_INFO_eXIf, png_eXIf,
Expand Down Expand Up @@ -242,6 +259,13 @@ static struct
1,
# endif
1, ABSENT, 0 },
{ "mDCV", PNG_INFO_mDCV, png_mDCV,
# ifdef PNG_READ_mDCV_SUPPORTED
0,
# else
1,
# endif
1, START, 0 },
{ "oFFs", PNG_INFO_oFFs, png_oFFs,
# ifdef PNG_READ_oFFs_SUPPORTED
0,
Expand Down
29 changes: 29 additions & 0 deletions contrib/pngminus/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = unset
indent_size = unset
indent_style = space
insert_final_newline = true
max_doc_length = 79
max_line_length = 79
trim_trailing_whitespace = true

[*.[ch]]
indent_size = 2
indent_style = space

[CMakeLists.txt]
indent_size = 4
indent_style = space
max_doc_length = 79
max_line_length = 99

[{Makefile,makevms.com}]
indent_size = unset
indent_style = unset
max_doc_length = 79
max_line_length = 99
1 change: 1 addition & 0 deletions contrib/pngminus/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ version 1.0 - 1999.10.15 - First version.
1.6 - 2018.08.05 - Improve portability and fix style (Cosmin Truta)
1.7 - 2019.01.22 - Change license to MIT (Willem van Schaik)
1.8 - 2024.01.09 - Fix, improve, modernize (Cosmin Truta)
1.9 - 2025.01.10 - Delete conditionally-compiled code (Cosmin Truta)
4 changes: 2 additions & 2 deletions contrib/pngminus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) 2018-2024 Cosmin Truta
# Copyright (c) 2018-2025 Cosmin Truta
#
# This software is released under the MIT license. For conditions of
# distribution and use, see the LICENSE file part of this package.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.14)

project(PNGMINUS C)

Expand Down
18 changes: 1 addition & 17 deletions contrib/pngminus/png2pnm.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main (int argc, char *argv[])
if ((fp_al = fopen (argv[argi], "wb")) == NULL)
{
fname_al = argv[argi];
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: cannot create alpha-channel file %s\n",
argv[argi]);
exit (1);
Expand Down Expand Up @@ -235,22 +235,6 @@ BOOL do_png2pnm (png_struct *png_ptr, png_info *info_ptr,
/* set up (if applicable) the expansion of grayscale images to bit-depth 8 */
png_set_expand_gray_1_2_4_to_8 (png_ptr);

#ifdef NJET
/* downgrade 16-bit images to 8-bit */
if (bit_depth == 16)
png_set_strip_16 (png_ptr);
/* transform grayscale images into full-color */
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb (png_ptr);
/* if the PNG image has a gAMA chunk then gamma-correct the output image */
{
double file_gamma;
if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
png_set_gamma (png_ptr, (double) 2.2, file_gamma);
}
#endif

/* read the image file, with all of the above image transforms applied */
png_read_png (png_ptr, info_ptr, 0, NULL);

Expand Down
2 changes: 1 addition & 1 deletion manuals/libpng-manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ libpng-manual.txt - A description on how to use and modify libpng

Based on:

libpng version 1.6.36, December 2018, through 1.6.45 - January 2025
libpng version 1.6.36, December 2018, through 1.6.46 - January 2025
Updated and distributed by Cosmin Truta
Copyright (c) 2018-2025 Cosmin Truta

Expand Down
6 changes: 3 additions & 3 deletions manuals/libpng.3
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.TH LIBPNG 3 "January 7, 2025"
.TH LIBPNG 3 "January 23, 2025"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.45
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.46

.SH SYNOPSIS
\fB#include <png.h>\fP
Expand Down Expand Up @@ -518,7 +518,7 @@ libpng-manual.txt - A description on how to use and modify libpng

Based on:

libpng version 1.6.36, December 2018, through 1.6.45 - January 2025
libpng version 1.6.36, December 2018, through 1.6.46 - January 2025
Updated and distributed by Cosmin Truta
Copyright (c) 2018-2025 Cosmin Truta

Expand Down
2 changes: 1 addition & 1 deletion manuals/png.5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH PNG 5 "January 7, 2025"
.TH PNG 5 "January 23, 2025"
.SH NAME
png \- Portable Network Graphics (PNG) format

Expand Down
113 changes: 68 additions & 45 deletions png.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,56 +1521,59 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)
* Adobe Wide Gamut RGB
* 0.258728243040113 0.724682314948566 0.016589442011321
*/
int error = 0;

/* By the argument above overflow should be impossible here, however the
* code now simply returns a failure code. The xy subtracts in the arguments
* to png_muldiv are *not* checked for overflow because the checks at the
* start guarantee they are in the range 0..110000 and png_fixed_point is a
* 32-bit signed number.
*/
if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 8) == 0)
return 1;
if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 8) == 0)
return 1;
denominator = png_fp_sub(left, right, &error);
if (error) return 1;
{
int error = 0;

/* Now find the red numerator. */
if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 8) == 0)
return 1;
if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 8) == 0)
return 1;
/* By the argument above overflow should be impossible here, however the
* code now simply returns a failure code. The xy subtracts in the
* arguments to png_muldiv are *not* checked for overflow because the
* checks at the start guarantee they are in the range 0..110000 and
* png_fixed_point is a 32-bit signed number.
*/
if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 8) == 0)
return 1;
if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 8) ==
0)
return 1;
denominator = png_fp_sub(left, right, &error);
if (error) return 1;

/* Overflow is possible here and it indicates an extreme set of PNG cHRM
* chunk values. This calculation actually returns the reciprocal of the
* scale value because this allows us to delay the multiplication of white-y
* into the denominator, which tends to produce a small number.
*/
if (png_muldiv(&red_inverse, xy->whitey, denominator,
png_fp_sub(left, right, &error)) == 0 || error ||
red_inverse <= xy->whitey /* r+g+b scales = white scale */)
return 1;
/* Now find the red numerator. */
if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 8) == 0)
return 1;
if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 8) ==
0)
return 1;

/* Similarly for green_inverse: */
if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 8) == 0)
return 1;
if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 8) == 0)
return 1;
if (png_muldiv(&green_inverse, xy->whitey, denominator,
png_fp_sub(left, right, &error)) == 0 || error ||
green_inverse <= xy->whitey)
return 1;
/* Overflow is possible here and it indicates an extreme set of PNG cHRM
* chunk values. This calculation actually returns the reciprocal of the
* scale value because this allows us to delay the multiplication of
* white-y into the denominator, which tends to produce a small number.
*/
if (png_muldiv(&red_inverse, xy->whitey, denominator,
png_fp_sub(left, right, &error)) == 0 || error ||
red_inverse <= xy->whitey /* r+g+b scales = white scale */)
return 1;

/* And the blue scale, the checks above guarantee this can't overflow but it
* can still produce 0 for extreme cHRM values.
*/
blue_scale = png_fp_sub(png_fp_sub(png_reciprocal(xy->whitey),
png_reciprocal(red_inverse), &error),
png_reciprocal(green_inverse), &error);
if (error || blue_scale <= 0)
return 1;
/* Similarly for green_inverse: */
if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 8) == 0)
return 1;
if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 8) == 0)
return 1;
if (png_muldiv(&green_inverse, xy->whitey, denominator,
png_fp_sub(left, right, &error)) == 0 || error ||
green_inverse <= xy->whitey)
return 1;

/* And the blue scale, the checks above guarantee this can't overflow but
* it can still produce 0 for extreme cHRM values.
*/
blue_scale = png_fp_sub(png_fp_sub(png_reciprocal(xy->whitey),
png_reciprocal(red_inverse), &error),
png_reciprocal(green_inverse), &error);
if (error || blue_scale <= 0)
return 1;
}

/* And fill in the png_XYZ. Again the subtracts are safe because of the
* checks on the xy values at the start (the subtracts just calculate the
Expand Down Expand Up @@ -3365,6 +3368,26 @@ png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)
}
#endif

#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
!defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \
(defined(PNG_cLLI_SUPPORTED) || defined(PNG_mDCV_SUPPORTED))
png_uint_32
png_fixed_ITU(png_const_structrp png_ptr, double fp, png_const_charp text)
{
double r = floor(10000 * fp + .5);

if (r > 2147483647. || r < 0)
png_fixed_error(png_ptr, text);

# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(text)
# endif

return (png_uint_32)r;
}
#endif


#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_COLORSPACE_SUPPORTED) ||\
defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
/* muldiv functions */
Expand Down
Loading

0 comments on commit d60d888

Please sign in to comment.