Please see the attached JPEG image. While displaying fine in most of viewers/browsers etc, we get wrong colors in FreeImage.
The problem is that it is missing some headers and heuristic is needed to process it properly. See here for more details: https://bugs.openjdk.java.net/browse/JDK-4845461
There is a sample implementation of the heuristic (note it is GPL so may not fit here): https://github.com/frohoff/jdk8u-jdk/blob/master/src/share/native/sun/awt/image/jpeg/imageioJPEG.c - look for saw_Adobe_marker keyword to see it.
I personally got it fixed with something like:
if (!cinfo.saw_JFIF_marker && cinfo.num_components == 3)
cinfo.out_color_space = cinfo.jpeg_color_space;
right after jpeg_read_header() call in PluginJPEG.cpp and it works fine for both this file and my test set, but my set is relatively small and may not cover all the possible combinations of headers and data types.
A proper fix is highly appreciated.
Hi,
I think your attached image was modified by SourceForge as nothing is wrong.
Can you upload a new image inside a ZIP file (so that the upload process do not modify the file) ?
Hervé
Sure, here you are. It seems that jpeglib 6 and 9 process this file differently and jpeg 6 works better. As we use 9 here, a workaround is needed.