TMI-41: Better handling of ICC Color Profiles. Now using different strategies to "sanitize" profiles, depending on the Color Management System in use.

This commit is contained in:
Harald Kuhr
2015-01-07 15:25:45 +01:00
parent f588d65565
commit 94ed531fb2
7 changed files with 227 additions and 68 deletions
@@ -33,8 +33,6 @@ import org.junit.Test;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.*;
@@ -47,8 +45,6 @@ import static org.junit.Assert.*;
*/
public class ColorSpacesTest {
private static final byte[] XYZ = new byte[] {'X', 'Y', 'Z', ' '};
@Test
public void testCreateColorSpaceFromKnownProfileReturnsInternalCS_sRGB() {
ICC_Profile profile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
@@ -189,19 +185,4 @@ public class ColorSpacesTest {
public void testIsCS_sRGBNull() {
ColorSpaces.isCS_sRGB(null);
}
@Test
public void testCorbisRGBSpecialHandling() throws IOException {
ICC_Profile corbisRGB = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/Corbis RGB.icc"));
ICC_ColorSpace colorSpace = ColorSpaces.createColorSpace(corbisRGB);
assertNotNull(colorSpace);
// Make sure all known affected tags have type 'XYZ '
ICC_Profile profile = colorSpace.getProfile();
assertArrayEquals(XYZ, Arrays.copyOfRange(profile.getData(ICC_Profile.icSigMediaWhitePointTag), 0, 4));
assertArrayEquals(XYZ, Arrays.copyOfRange(profile.getData(ICC_Profile.icSigRedColorantTag), 0, 4));
assertArrayEquals(XYZ, Arrays.copyOfRange(profile.getData(ICC_Profile.icSigGreenColorantTag), 0, 4));
assertArrayEquals(XYZ, Arrays.copyOfRange(profile.getData(ICC_Profile.icSigBlueColorantTag), 0, 4));
}
}
@@ -0,0 +1,54 @@
package com.twelvemonkeys.imageio.color;
import org.junit.Test;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
public class KCMSSanitizerStrategyTest {
private static final byte[] XYZ = new byte[] {'X', 'Y', 'Z', ' '};
@Test(expected = IllegalArgumentException.class)
public void testFixProfileNullProfile() throws Exception {
new KCMSSanitizerStrategy().fixProfile(null, null);
}
@Test
public void testFixProfileNullHeader() throws Exception {
new KCMSSanitizerStrategy().fixProfile(((ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB)).getProfile(), null);
}
@Test
public void testFixProfileUpdateHeader() throws Exception {
ICC_Profile profile = mock(ICC_Profile.class);
byte[] header = new byte[0];
// Can't test that the values are actually changed, as the LCMS-backed implementation
// of ICC_Profile does not change based on this invocation.
new KCMSSanitizerStrategy().fixProfile(profile, header);
// Verify that the method was invoked
verify(profile).setData(ICC_Profile.icSigHead, header);
}
@Test
public void testFixProfileCorbisRGB() throws IOException {
// TODO: Consider re-writing this using mocks, to avoid dependencies on the CMS implementation
ICC_Profile corbisRGB = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/Corbis RGB.icc"));
new KCMSSanitizerStrategy().fixProfile(corbisRGB, null);
// Make sure all known affected tags have type 'XYZ '
assertArrayEquals(XYZ, Arrays.copyOfRange(corbisRGB.getData(ICC_Profile.icSigMediaWhitePointTag), 0, 4));
assertArrayEquals(XYZ, Arrays.copyOfRange(corbisRGB.getData(ICC_Profile.icSigRedColorantTag), 0, 4));
assertArrayEquals(XYZ, Arrays.copyOfRange(corbisRGB.getData(ICC_Profile.icSigGreenColorantTag), 0, 4));
assertArrayEquals(XYZ, Arrays.copyOfRange(corbisRGB.getData(ICC_Profile.icSigBlueColorantTag), 0, 4));
}
}
@@ -0,0 +1,32 @@
package com.twelvemonkeys.imageio.color;
import org.junit.Test;
import java.awt.color.ICC_Profile;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
public class LCMSSanitizerStrategyTest {
@Test(expected = IllegalArgumentException.class)
public void testFixProfileNullProfile() throws Exception {
new LCMSSanitizerStrategy().fixProfile(null, null);
}
@Test
public void testFixProfileNoHeader() throws Exception {
ICC_Profile profile = mock(ICC_Profile.class);
new LCMSSanitizerStrategy().fixProfile(profile, null);
verifyNoMoreInteractions(profile);
}
@Test
public void testFixProfile() throws Exception {
ICC_Profile profile = mock(ICC_Profile.class);
new LCMSSanitizerStrategy().fixProfile(profile, new byte[0]);
verifyNoMoreInteractions(profile);
}
}