TwelveMonkeys icon indicating copy to clipboard operation
TwelveMonkeys copied to clipboard

Java 9+ issue due to new Color Management (?)

Open haraldk opened this issue 5 years ago • 3 comments

The following no longer works:

param.setDestinationType(ImageTypeSpecifier.createBanded(ColorSpace.getInstance(ColorSpace.CS_sRGB), 
                                new int[]{0, 1, 2}, new int[] {0, 0, 0}, DataBuffer.TYPE_BYTE, false, false));

The above code works for me in Java 8 (1.8.0_x).

But I tested again, using a different Java version (OpenJDK 11.0.1+x). There seems to be a JDK issue, where something has changed in the comparison of ImageTypeSpecifiers, so that two equal (but not the same) specifiers are no longer considered equal... That's unfortunate.

For now, you can still get the same effect, by using the following code:

param.setDestinationType(reader.getRawImageType(imgNo);

This works for me, both Java 8 and 11.

The problem seems to be that embedded color profiles that are equal to sRGB no longer compares correctly in ColorSpaces class, thus multiple sRGB profiles are created.

Originally posted by @haraldk in https://github.com/haraldk/TwelveMonkeys/issues/398#issuecomment-485865888

haraldk avatar Apr 23 '19 16:04 haraldk

JDK seems to have a lot of nasty issues with color profiles.

@haraldk Are you aware of any use case where this can cause a problem? Like reading an image?

sghpjuikit avatar Jun 20 '19 14:06 sghpjuikit

@sghpjuikit I’m not sure if I understand what you are asking here...

Yes, the issue I described causes problems whenever comparing two ColorSpace or ICC_Profile instances is needed.

The linked issue, #398, shows one such case.

It shouldn’t cause much problems for reading images in general, but it may waste some memory by keeping multiple ICC profiles in memory unnecessary.

Best regards,

— Harald K

haraldk avatar Jun 20 '19 16:06 haraldk

I haven't noticed the linked issue, I see. You answered my question sufficiently.

sghpjuikit avatar Jun 21 '19 06:06 sghpjuikit