I'm trying to load a PNG file using SDL but the program doesn't work and this error appears in the console
"libpng warning: iCCP: known incorrect sRGB profile"
Why this warning appears? what should I do to solve this problem?
I'm trying to load a PNG file using SDL but the program doesn't work and this error appears in the console
"libpng warning: iCCP: known incorrect sRGB profile"
Why this warning appears? what should I do to solve this problem?
some background info on this:
(source: https://wiki.archlinux.org/index.php/Libpng_errors)
(source: https://forum.qt.io/topic/58638/solved-libpng-warning-iccp-known-incorrect-srgb-profile-drive-me-nuts/16)
Libpng-1.6 is more stringent about checking ICC profiles than previous versions. You can ignore the warning. To get rid of it, remove the iCCP chunk from the PNG image.
Some applications treat warnings as errors; if you are using such an application you do have to remove the chunk. You can do that with any of a variety of PNG editors such as ImageMagick's
convert in.png out.png
.To remove the invalid iCCP chunk from all of the PNG files in a folder (directory), you can use ImageMagick's
mogrify *.png
, provided that your ImageMagick was built with libpng16 (runconvert -list format | grep PNG
to be sure of that).If you'd like to find out which files need to be fixed instead of blindly processing all of them, you can run my
pngcrush -n -q *.png
where the "-n
" means don't rewrite the files and "-q
" means suppress most of the output except for warnings. Sorry, there's no option yet in pngcrush to suppress everything but the warnings.Binary Releases of ImageMagick are here
For Android Projects (Android Studio) navigate into res folder.
For example:
C:\AndroidProjects\{your_project_folder}\app\src\main\res\drawable-hdpi\mogrify *.png
After trying a couple of the suggestions on this page I ended up using the pngcrush solution. You can use the bash script below to recursively detect and fix bad png profiles. Just pass it the full path to the directory you want to search for png files.
The script:
To add to Glenn's great answer, here's what I did to find which files were faulty:
I used the find and xargs because pngcrush could not handle lots of arguments (which were returned by
**/*.png
). The-print0
and-0
is required to handle file names containing spaces.Then search in the output for these lines:
iCCP: Not recognizing known sRGB profile that has been edited
.And for each of those, run mogrify on it to fix them.
Doing this prevents having a commit changing every single png file in the repository when only a few have actually been modified. Plus it has the advantage to show exactly which files were faulty.
I tested this on Windows with a Cygwin console and a zsh shell. Thanks again to Glenn who put most of the above, I'm just adding an answer as it's usually easier to find than comments :)
Solution
The incorrect profile could be fixed by:
Note: This solution uses the Qt Library.
Example
Here is a minimal example I have written in C++ in order to demonstrate how to implement the proposed solution:
The complete source code of a GUI application based on this example is available on GitHub.