mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-30 00:00:01 -04:00
#386 Fixed ColorSpaces ICC profile caching bug
This commit is contained in:
+16
-1
@@ -33,6 +33,7 @@ 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 static org.junit.Assert.*;
|
||||
|
||||
@@ -82,7 +83,7 @@ public class ColorSpacesTest {
|
||||
|
||||
private ICC_Profile createBrokenProfile(ICC_Profile internal) {
|
||||
byte[] data = internal.getData();
|
||||
data[ICC_Profile.icHdrRenderingIntent] = 1; // Intent: 1 == Relative Colormetric
|
||||
data[ICC_Profile.icHdrRenderingIntent + 3] = 1; // Intent: 1 == Relative Colormetric
|
||||
return ICC_Profile.getInstance(data);
|
||||
}
|
||||
|
||||
@@ -185,4 +186,18 @@ public class ColorSpacesTest {
|
||||
public void testIsCS_sRGBNull() {
|
||||
ColorSpaces.isCS_sRGB(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualHeadersDifferentProfile() throws IOException {
|
||||
// These profiles are extracted from various JPEGs, and have the exact same profile header...
|
||||
ICC_Profile profile1 = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc"));
|
||||
ICC_Profile profile2 = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/color_match_rgb.icc"));
|
||||
|
||||
assertNotSame(profile1, profile2); // Sanity
|
||||
|
||||
ICC_ColorSpace cs1 = ColorSpaces.createColorSpace(profile1);
|
||||
ICC_ColorSpace cs2 = ColorSpaces.createColorSpace(profile2);
|
||||
|
||||
assertNotSame(cs1, cs2);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-9
@@ -9,33 +9,36 @@ 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;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
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);
|
||||
new KCMSSanitizerStrategy().fixProfile(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFixProfileNullHeader() throws Exception {
|
||||
new KCMSSanitizerStrategy().fixProfile(((ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB)).getProfile(), null);
|
||||
public void testFixProfile() throws Exception {
|
||||
new KCMSSanitizerStrategy().fixProfile(((ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB)).getProfile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFixProfileUpdateHeader() throws Exception {
|
||||
byte[] header = new byte[128];
|
||||
header[ICC_Profile.icHdrRenderingIntent + 3] = 1;
|
||||
ICC_Profile profile = mock(ICC_Profile.class);
|
||||
byte[] header = new byte[0];
|
||||
when(profile.getData(ICC_Profile.icSigHead)).thenReturn(header);
|
||||
|
||||
// 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);
|
||||
new KCMSSanitizerStrategy().fixProfile(profile);
|
||||
|
||||
// Verify that the method was invoked
|
||||
verify(profile).setData(ICC_Profile.icSigHead, header);
|
||||
verify(profile).setData(eq(ICC_Profile.icSigHead), any(byte[].class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +46,7 @@ public class KCMSSanitizerStrategyTest {
|
||||
// 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);
|
||||
new KCMSSanitizerStrategy().fixProfile(corbisRGB);
|
||||
|
||||
// Make sure all known affected tags have type 'XYZ '
|
||||
assertArrayEquals(XYZ, Arrays.copyOfRange(corbisRGB.getData(ICC_Profile.icSigMediaWhitePointTag), 0, 4));
|
||||
|
||||
+2
-10
@@ -11,21 +11,13 @@ 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);
|
||||
new LCMSSanitizerStrategy().fixProfile(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFixProfile() throws Exception {
|
||||
ICC_Profile profile = mock(ICC_Profile.class);
|
||||
new LCMSSanitizerStrategy().fixProfile(profile, new byte[0]);
|
||||
new LCMSSanitizerStrategy().fixProfile(profile);
|
||||
|
||||
verifyNoMoreInteractions(profile);
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user