From 3b1f4650b6b0756cc0afcf6aed7f60c77e762444 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Thu, 2 Nov 2023 12:19:47 +0100 Subject: [PATCH] check whether libpng supports iTXt chunks (#1020) --- examples/decoder_png.cc | 2 ++ examples/encoder_png.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/examples/decoder_png.cc b/examples/decoder_png.cc index 5f8feb3cc4..5742f02653 100644 --- a/examples/decoder_png.cc +++ b/examples/decoder_png.cc @@ -213,6 +213,7 @@ InputImage loadPNG(const char* filename, int output_bit_depth) // --- read XMP data +#ifdef PNG_iTXt_SUPPORTED png_textp textPtr = nullptr; const png_uint_32 nTextChunks = png_get_text(png_ptr, info_ptr, &textPtr, nullptr); for (png_uint_32 i = 0; i < nTextChunks; i++, textPtr++) { @@ -231,6 +232,7 @@ InputImage loadPNG(const char* filename, int output_bit_depth) } } } +#endif int band = png_get_channels(png_ptr, info_ptr); diff --git a/examples/encoder_png.cc b/examples/encoder_png.cc index e53660a1f1..a24b0593ea 100644 --- a/examples/encoder_png.cc +++ b/examples/encoder_png.cc @@ -134,6 +134,7 @@ bool PngEncoder::Encode(const struct heif_image_handle* handle, // --- write XMP metadata +#ifdef PNG_iTXt_SUPPORTED // spec: https://raw.githubusercontent.com/adobe/xmp-docs/master/XMPSpecifications/XMPSpecificationPart3.pdf std::vector xmp = get_xmp_metadata(handle); if (!xmp.empty()) { @@ -156,6 +157,7 @@ bool PngEncoder::Encode(const struct heif_image_handle* handle, xmp_text.itxt_length = text_length; png_set_text(png_ptr, info_ptr, &xmp_text, 1); } +#endif png_write_info(png_ptr, info_ptr);