blob: cc15a17e653f970a277928633aa2500231841d70 [file] [log] [blame]
freeimage assumes libpng-1.4.x api in a few places
--- a/Source/FreeImage/PluginPNG.cpp
+++ b/Source/FreeImage/PluginPNG.cpp
@@ -106,7 +106,11 @@ ReadMetadata(png_structp png_ptr, png_infop info_ptr, FIBITMAP *dib) {
tag = FreeImage_CreateTag();
if(!tag) return FALSE;
+#ifdef PNG_iTXt_SUPPORTED
DWORD tag_length = (DWORD) MAX(text_ptr[i].text_length, text_ptr[i].itxt_length);
+#else
+ DWORD tag_length = (DWORD) text_ptr[i].text_length;
+#endif
FreeImage_SetTagLength(tag, tag_length);
FreeImage_SetTagCount(tag, tag_length);
@@ -153,9 +157,11 @@ WriteMetadata(png_structp png_ptr, png_infop info_ptr, FIBITMAP *dib) {
text_metadata.key = (char*)FreeImage_GetTagKey(tag); // keyword, 1-79 character description of "text"
text_metadata.text = (char*)FreeImage_GetTagValue(tag); // comment, may be an empty string (ie "")
text_metadata.text_length = FreeImage_GetTagLength(tag);// length of the text string
+#ifdef PNG_iTXt_SUPPORTED
text_metadata.itxt_length = FreeImage_GetTagLength(tag);// length of the itxt string
text_metadata.lang = 0; // language code, 0-79 characters or a NULL pointer
text_metadata.lang_key = 0; // keyword translated UTF-8 string, 0 or more chars or a NULL pointer
+#endif
// set the tag
png_set_text(png_ptr, info_ptr, &text_metadata, 1);
@@ -175,9 +181,11 @@ WriteMetadata(png_structp png_ptr, png_infop info_ptr, FIBITMAP *dib) {
text_metadata.key = (char*)g_png_xmp_keyword; // keyword, 1-79 character description of "text"
text_metadata.text = (char*)FreeImage_GetTagValue(tag); // comment, may be an empty string (ie "")
text_metadata.text_length = FreeImage_GetTagLength(tag);// length of the text string
+#ifdef PNG_iTXt_SUPPORTED
text_metadata.itxt_length = FreeImage_GetTagLength(tag);// length of the itxt string
text_metadata.lang = 0; // language code, 0-79 characters or a NULL pointer
text_metadata.lang_key = 0; // keyword translated UTF-8 string, 0 or more chars or a NULL pointer
+#endif
// set the tag
png_set_text(png_ptr, info_ptr, &text_metadata, 1);
@@ -559,7 +559,11 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_iCCP)) {
png_charp profile_name = NULL;
+#if PNG_LIBPNG_VER_MINOR < 4
+ png_charp profile_data = NULL;
+#else
png_bytep profile_data = NULL;
+#endif
png_uint_32 profile_length = 0;
int compression_type;
@@ -599,7 +599,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
row_pointers[height - 1 - k] = FreeImage_GetScanLine(dib, k);
}
+#ifdef PNG_BENIGN_ERRORS_SUPPORTED
png_set_benign_errors(png_ptr, 1);
+#endif
png_read_image(png_ptr, row_pointers);
// check if the bitmap contains transparency, if so enable it in the header
@@ -833,7 +835,11 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
FIICCPROFILE *iccProfile = FreeImage_GetICCProfile(dib);
if (iccProfile->size && iccProfile->data) {
+#if PNG_LIBPNG_VER_MINOR < 4
+ png_set_iCCP(png_ptr, info_ptr, "Embedded Profile", 0, (png_charp)iccProfile->data, iccProfile->size);
+#else
png_set_iCCP(png_ptr, info_ptr, "Embedded Profile", 0, (png_const_bytep)iccProfile->data, iccProfile->size);
+#endif
}
// write metadata