Java 8 ImageIO reads JPEG incorrectly in Linux

爷,独闯天下 提交于 2019-12-12 10:47:24

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/25187942/java-8-imageio-reads-jpeg-incorrectly-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!