haraldk / TwelveMonkeys

TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO
https://haraldk.github.io/TwelveMonkeys/
BSD 3-Clause "New" or "Revised" License
1.88k stars 312 forks source link

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

Open haraldk opened 5 years ago

haraldk commented 5 years ago

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

sghpjuikit commented 5 years ago

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?

haraldk commented 5 years ago

@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

sghpjuikit commented 5 years ago

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