6

I'm trying to read user-uploaded JPEG image (arbitrary) to create thumbnail in server app. System works just fine in Windows7 / Oracle Java 8u11 but I have problem with color model under CentOS on server:

original image is:

http://studio-st.ru/media/portfolio/image/45

resulting thumbnail on development workstation under Windows is absolutely correct

result under Linux is color-shifted (reddish on Java 8u05, color-shifted on Java 8u11). Not presented here because original example was on site, which is fixed now.

Deeper investigation shown that problem is in reading image - ImageIO.read(inputStream) on Windows and Linux return image objects with exactly the same parameters, however color probe getRGB(x,y) for the same image (just read) returns different values.

Colors treating in Linux differ on Java 8u05 & 8u11, 8u05 was "reddish", 8u11 is as shown above.

This has nothing to do with alpha channels - this particular source image is JPEG Type 5 (TYPE_3BYTE_BGR), exported from Adobe Lightroom with conversion to sRGB, without any other tricks.

This also affects all images exported that time (all images on this site, in fact).

Can anyone provide some advice on how to make it work (except for waiting for fix for JDK)? Maybe recommend alternate library, which can be used here (EJB, data stored in MongoDB, so data is fetched using InputStreams - no filesystem access).

Thanks!

UPD: issue appears to be with Java8's new Color Management Module - it doesn't understand this image format. Switching to legacy CMM fixed the issue. Please see details in correct comment below.

  • This Q&A might perhaps be useful to you: [Is there a 100% Java alternative to ImageIO for reading JPEG files?](https://stackoverflow.com/questions/2999528/is-there-a-100-java-alternative-to-imageio-for-reading-jpeg-files) – Boann Aug 07 '14 at 17:35
  • Thanks, gotta do some experimentation JAI... – Alexander Terekhov Aug 07 '14 at 18:04

1 Answers1

4

You could try using my JPEGImageReader plugin for ImageIO, it handles color conversions a little bit differently than the default JPEGImageReader, so it might help (sorry, don't have my work computer near, so I can't test myself just now). If it doesn't help, I'd like to fix it. Can I use your image for a test case? :-)

Another thing that might help, is specifying:

-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider

on the command line (or set the sun.java2d.cmm system property accordingly using other means). The color management module (CMM) was switched from Sun/Kodak's legacy CMM to the more up-to-date and open-source Little CMS in Java 8. Setting this system property will re-enable the legacy color management from Java pre 8.

As you mention no disk access, it pretty much rules out JMagick or im4j as these works best with files. It would probably be possible to use temp files though.

Harald K
  • 26,314
  • 7
  • 65
  • 111
  • 1
    Thanks! I'll do some experimentation here as well. And of course, feel free to use the image for testing :-) – Alexander Terekhov Aug 07 '14 at 20:44
  • Switching to Sun/Kodak CMM fixed the situation - now everything works as expected. Thanks again! :-) – Alexander Terekhov Aug 07 '14 at 20:56
  • All good then! :-) You should probably file a platform specific bug report for Java 8 as well, to have this fixed. – Harald K Aug 08 '14 at 06:46
  • 1
    Yes, I have already filed the bug there and waiting for them to answer with confirmation )) – Alexander Terekhov Aug 08 '14 at 08:50
  • 1
    @AlexanderTerekhov The Oracle bug process is quite terrible. They won't "answer with confirmation". They won't say anything, even if it's fixed. The only way to ever find out what happens to reports is to know that the bug reports actually turn up on a different site to which they are submitted, and to go manually searching there. I found your bug report, but apparently they have already closed it as "cannot reproduce". You might need to submit again with a specific test picture: https://bugs.openjdk.java.net/browse/JDK-8054568 – Boann Aug 09 '14 at 13:33
  • Is it possible to re-open it? In any case, I think it would be a good idea to link to this SO question in the bug report, to show that this is a real problem, and what is needed to fix it. – Harald K Aug 09 '14 at 13:44