When processing images with embedded color profiles (ICC) in Java, there is a bug that causes colors to be interpreted incorrectly when running with Java 8 (and some versions of OpenJDK7) . This issue is occurring because the color management module (CMM) was switched from Sun/Kodak’s legacy CMM to the more up-to-date and open-source LittleCMS in Java 8. While an improvement, version 2.5 of LittleCMS (packaged in Java 8u31 and lower) had some concurrency issues and you may see the following errors in your log:

java.awt.color.CMMException: Cannot get color transform
        at sun.java2d.cmm.lcms.LCMS.createNativeTransform(Native Method)
        at sun.java2d.cmm.lcms.LCMSTransform.doTransform(LCMSTransform.java:149)
        at sun.java2d.cmm.lcms.LCMSTransform.colorConvert(LCMSTransform.java:608)
        at java.awt.color.ICC_ColorSpace.toRGB(ICC_ColorSpace.java:182)
        at com.qoppa.o.e.e.b(Unknown Source)
        at com.qoppa.o.e.q.b(Unknown Source)
        at com.qoppa.pdfWeb.b.b.b(Unknown Source)
        at com.qoppa.pdfWeb.b.i.b(Unknown Source)
        at com.qoppa.pdfWeb.b.i.b(Unknown Source)
        at com.qoppa.pdf.n.d.b.c.b(Unknown Source)
        at com.qoppa.pdfWeb.b.i.d(Unknown Source)
        at com.qoppa.pdfWeb.b.i.b(Unknown Source)
        at com.qoppa.pdfWeb.b.i.b(Unknown Source)
        at com.qoppa.pdfWeb.PDFWeb.saveDocumentAsSVG(Unknown Source)
        at nl.fd.importer.converter.PdfToSvgService.doConvert(PdfToSvgService.java:53)

Try one of the below solutions in your application to resolve the issue.

Use the Java 7 color management library

Since this issue does not occur when running in Java 7 (which used the old color management library) you could continue using Java 8 and set the CMM providor property to use the Java 7 color manager.

Add this to your code before the first call to the library to revert to the previous Java 7 color model.

// This line solves the "Wrong colors" problem:
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");

Update to Java 8u40 (or higher)

In Java 8 update 31, version 2.5 of LittleCMS is included. Version 2.5 of LittleCMS has issues generating correct colors when running concurrently. In Java 8 update 40 LittleCMS was updated to version 2.6, which according to the Release Notes fixes some issues with concurrency.

Version 2.6 is a featured release that introduces contexts, greatly improves concurrency and minimizes thread contention.

Tagged: