summaryrefslogtreecommitdiff
path: root/png/pngwrite.c
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2025-09-07 18:06:14 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2025-09-07 18:06:39 +0200
commit27e02a1541db180e3d4260732461a080dab593a1 (patch)
tree85b14e9d0937a3c8c615c2c3ddc6644b0c58768a /png/pngwrite.c
parent1182cd66ec66cc317af2db44d21c2e56b99536e8 (diff)
Update bundled libpng to version 1.6.50 dated 2025-07-01
Diffstat (limited to 'png/pngwrite.c')
-rw-r--r--png/pngwrite.c125
1 files changed, 78 insertions, 47 deletions
diff --git a/png/pngwrite.c b/png/pngwrite.c
index 77e412f43..35a5d17b6 100644
--- a/png/pngwrite.c
+++ b/png/pngwrite.c
@@ -1,7 +1,6 @@
-
/* pngwrite.c - general routines to write a PNG file
*
- * Copyright (c) 2018-2024 Cosmin Truta
+ * Copyright (c) 2018-2025 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* Copyright (c) 1996-1997 Andreas Dilger
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -128,61 +127,93 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
* the application continues writing the PNG. So check the 'invalid'
* flag here too.
*/
-#ifdef PNG_GAMMA_SUPPORTED
-# ifdef PNG_WRITE_gAMA_SUPPORTED
- if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
- (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_gAMA) != 0 &&
- (info_ptr->valid & PNG_INFO_gAMA) != 0)
- png_write_gAMA_fixed(png_ptr, info_ptr->colorspace.gamma);
-# endif
+#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
+ /* Write unknown chunks first; PNG v3 establishes a precedence order
+ * for colourspace chunks. It is certain therefore that new
+ * colourspace chunks will have a precedence and very likely it will be
+ * higher than all known so far. Writing the unknown chunks here is
+ * most likely to present the chunks in the most convenient order.
+ *
+ * FUTURE: maybe write chunks in the order the app calls png_set_chnk
+ * to give the app control.
+ */
+ write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR);
#endif
-#ifdef PNG_COLORSPACE_SUPPORTED
- /* Write only one of sRGB or an ICC profile. If a profile was supplied
- * and it matches one of the known sRGB ones issue a warning.
- */
-# ifdef PNG_WRITE_iCCP_SUPPORTED
- if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
- (info_ptr->valid & PNG_INFO_iCCP) != 0)
- {
-# ifdef PNG_WRITE_sRGB_SUPPORTED
- if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
- png_app_warning(png_ptr,
- "profile matches sRGB but writing iCCP instead");
-# endif
+#ifdef PNG_WRITE_sBIT_SUPPORTED
+ /* PNG v3: a streaming app will need to see this before cICP because
+ * the information is helpful in handling HLG encoding (which is
+ * natively 10 bits but gets expanded to 16 in PNG.)
+ *
+ * The app shouldn't care about the order ideally, but it might have
+ * no choice. In PNG v3, apps are allowed to reject PNGs where the
+ * APNG chunks are out of order so it behooves libpng to be nice here.
+ */
+ if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
+ png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
+#endif
+ /* PNG v3: the July 2004 version of the TR introduced the concept of colour
+ * space priority. As above it therefore behooves libpng to write the colour
+ * space chunks in the priority order so that a streaming app need not buffer
+ * them.
+ *
+ * PNG v3: Chunks mDCV and cLLI provide ancillary information for the
+ * interpretation of the colourspace chunkgs but do not require support for
+ * those chunks so are outside the "COLORSPACE" check but before the write of
+ * the colourspace chunks themselves.
+ */
+#ifdef PNG_WRITE_cLLI_SUPPORTED
+ if ((info_ptr->valid & PNG_INFO_cLLI) != 0)
+ {
+ png_write_cLLI_fixed(png_ptr, info_ptr->maxCLL, info_ptr->maxFALL);
+ }
+#endif
+#ifdef PNG_WRITE_mDCV_SUPPORTED
+ if ((info_ptr->valid & PNG_INFO_mDCV) != 0)
+ {
+ png_write_mDCV_fixed(png_ptr,
+ info_ptr->mastering_red_x, info_ptr->mastering_red_y,
+ info_ptr->mastering_green_x, info_ptr->mastering_green_y,
+ info_ptr->mastering_blue_x, info_ptr->mastering_blue_y,
+ info_ptr->mastering_white_x, info_ptr->mastering_white_y,
+ info_ptr->mastering_maxDL, info_ptr->mastering_minDL);
+ }
+#endif
+
+# ifdef PNG_WRITE_cICP_SUPPORTED /* Priority 4 */
+ if ((info_ptr->valid & PNG_INFO_cICP) != 0)
+ {
+ png_write_cICP(png_ptr,
+ info_ptr->cicp_colour_primaries,
+ info_ptr->cicp_transfer_function,
+ info_ptr->cicp_matrix_coefficients,
+ info_ptr->cicp_video_full_range_flag);
+ }
+# endif
+
+# ifdef PNG_WRITE_iCCP_SUPPORTED /* Priority 3 */
+ if ((info_ptr->valid & PNG_INFO_iCCP) != 0)
+ {
png_write_iCCP(png_ptr, info_ptr->iccp_name,
- info_ptr->iccp_profile);
+ info_ptr->iccp_profile, info_ptr->iccp_proflen);
}
-# ifdef PNG_WRITE_sRGB_SUPPORTED
- else
-# endif
# endif
-# ifdef PNG_WRITE_sRGB_SUPPORTED
- if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
- (info_ptr->valid & PNG_INFO_sRGB) != 0)
- png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent);
+# ifdef PNG_WRITE_sRGB_SUPPORTED /* Priority 2 */
+ if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
+ png_write_sRGB(png_ptr, info_ptr->rendering_intent);
# endif /* WRITE_sRGB */
-#endif /* COLORSPACE */
-#ifdef PNG_WRITE_sBIT_SUPPORTED
- if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
- png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
-#endif
-
-#ifdef PNG_COLORSPACE_SUPPORTED
-# ifdef PNG_WRITE_cHRM_SUPPORTED
- if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
- (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 &&
- (info_ptr->valid & PNG_INFO_cHRM) != 0)
- png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy);
+# ifdef PNG_WRITE_gAMA_SUPPORTED /* Priority 1 */
+ if ((info_ptr->valid & PNG_INFO_gAMA) != 0)
+ png_write_gAMA_fixed(png_ptr, info_ptr->gamma);
# endif
-#endif
-#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
- write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR);
-#endif
+# ifdef PNG_WRITE_cHRM_SUPPORTED /* Also priority 1 */
+ if ((info_ptr->valid & PNG_INFO_cHRM) != 0)
+ png_write_cHRM_fixed(png_ptr, &info_ptr->cHRM);
+# endif
png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
}
@@ -2302,7 +2333,7 @@ int PNGAPI
png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
const void *buffer, png_int_32 row_stride, const void *colormap)
{
- /* Write the image to the given (FILE*). */
+ /* Write the image to the given FILE object. */
if (image != NULL && image->version == PNG_IMAGE_VERSION)
{
if (file != NULL && buffer != NULL)