Skip to content

Commit

Permalink
check whether libpng supports iTXt chunks (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Nov 2, 2023
1 parent 2289041 commit 3b1f465
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/decoder_png.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -231,6 +232,7 @@ InputImage loadPNG(const char* filename, int output_bit_depth)
}
}
}
#endif

int band = png_get_channels(png_ptr, info_ptr);

Expand Down
2 changes: 2 additions & 0 deletions examples/encoder_png.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> xmp = get_xmp_metadata(handle);
if (!xmp.empty()) {
Expand All @@ -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);

Expand Down

0 comments on commit 3b1f465

Please sign in to comment.