New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom ICC not read from PNG #4260
Comments
I'll take a look, thanks for the analysis! |
http://www.libpng.org/pub/png/libpng-manual.txt
|
so what's the bottom line? even if the profile is not strictly valid, I'd say we should try and use it anyway. do you agree? |
I agree, RT should still try to load it. By the way, this sort of problem, that the embedded ICC profile was found but not used, or that it was used but is known to be broken, is something that the user should be informed about, see #4261. |
I couldn't find where PNG files get their profile from, maybe they don't?
if (hasprofile) {
embProfile = cmsOpenProfileFromMem (loadedProfileData, loadedProfileLength);
} else {
embProfile = nullptr;
}
if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &loadedProfileLength, &profdata)) {
embProfile = cmsOpenProfileFromMem (profdata, loadedProfileLength);
loadedProfileData = new char [loadedProfileLength];
memcpy (loadedProfileData, profdata, loadedProfileLength);
} else {
embProfile = nullptr;
}
embProfile = nullptr; |
This works for me, but I'm on libpng v1.2.57. @Beep6581 can you please test? diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc
--- a/rtengine/imageio.cc
+++ b/rtengine/imageio.cc
@@ -356,6 +356,18 @@
png_set_strip_alpha(png);
}
+ // reading the embedded ICC profile if any
+ if (png_get_valid(png, info, PNG_INFO_iCCP)) {
+ png_charp name;
+ int compression_type;
+ png_charp profdata;
+ png_uint_32 proflen;
+ png_get_iCCP(png, info, &name, &compression_type, &profdata, &proflen);
+ embProfile = cmsOpenProfileFromMem(profdata, proflen);
+ loadedProfileData = new char[proflen];
+ memcpy(loadedProfileData, profdata, proflen);
+ }
+
//setting gamma
double gamma;
|
@agriggio compilation fails using GCC-5.4.0 with:
|
@Beep6581 libpng version? |
Still libpng-1.6.34 ;] |
@Beep6581 try this please: diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc
--- a/rtengine/imageio.cc
+++ b/rtengine/imageio.cc
@@ -308,6 +308,11 @@
return IMIO_HEADERERROR;
}
+ // silence the warning about "invalid" sRGB profiles -- see #4260
+#if defined(PNG_SKIP_sRGB_CHECK_PROFILE) && defined(PNG_SET_OPTION_SUPPORTED)
+ png_set_option(png, PNG_SKIP_sRGB_CHECK_PROFILE, PNG_OPTION_ON);
+#endif
+
png_infop info = png_create_info_struct (png);
png_infop end_info = png_create_info_struct (png);
@@ -360,7 +365,11 @@
if (png_get_valid(png, info, PNG_INFO_iCCP)) {
png_charp name;
int compression_type;
+#if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR > 4)
+ png_bytep profdata;
+#else
png_charp profdata;
+#endif
png_uint_32 proflen;
png_get_iCCP(png, info, &name, &compression_type, &profdata, &proflen);
embProfile = cmsOpenProfileFromMem(profdata, proflen); |
@agriggio do I apply this on top of the previous patch?
|
One applied on top of the other, and RT compiled! |
great! If no objections, I'll push later today then |
5.3-357-g
a31f522libpng 1.6.34
cairo-1.14.10
cairomm-1.12.0
http://rawtherapee.com/shared/test_images/redblue.png
http://rawtherapee.com/shared/test_images/redblue.icc
RawTherapee does not display the colors in
redblue.png
correctly.A warning is thrown in the console:
If you open the PNG and set the ICC manually, the colors are fine.
I found that libpng-1.6.* is more stringent in ICC checks than previous versions. The warning is probably being treated as a fatal error by RT and so the profile is not used.
Ref: https://discuss.pixls.us/t/favorite-test-images/6199/7?u=morgan_hardwood
The text was updated successfully, but these errors were encountered: