Added (Open)JDK 7 support (workaround for a bug, really)

This commit is contained in:
Harald Kuhr 2011-04-27 14:15:25 +02:00
parent a4d4111195
commit fbb51f0387

View File

@ -70,8 +70,12 @@ import java.util.Properties;
* @version $Id: ColorSpaces.java,v 1.0 24.01.11 17.51 haraldk Exp$ * @version $Id: ColorSpaces.java,v 1.0 24.01.11 17.51 haraldk Exp$
*/ */
public final class ColorSpaces { public final class ColorSpaces {
private final static boolean DEBUG = "true".equalsIgnoreCase(System.getProperty("com.twelvemonkeys.imageio.color.debug")); private final static boolean DEBUG = "true".equalsIgnoreCase(System.getProperty("com.twelvemonkeys.imageio.color.debug"));
// JDK 7 seems to handle non-perceptual rendering intents gracefully, so we don't need to fiddle with the profiles
private final static boolean JDK_HANDLES_RENDERING_INTENTS = SystemUtil.isClassAvailable("java.lang.invoke.CallSite");
// NOTE: java.awt.color.ColorSpace.CS_* uses 1000-1004, we'll use 5000+ to not interfere with future additions // NOTE: java.awt.color.ColorSpace.CS_* uses 1000-1004, we'll use 5000+ to not interfere with future additions
/** The Adobe RGB 1998 (or compatible) color space. Either read from disk or built-in. */ /** The Adobe RGB 1998 (or compatible) color space. Either read from disk or built-in. */
@ -120,9 +124,14 @@ public final class ColorSpaces {
return cs; return cs;
} }
// NOTE: The intent change breaks JDK7: Seems to be a bug in ICC_Profile.getData/setData,
// as calling it with unchanged header data, still breaks when creating new ICC_ColorSpace...
// However, we simply skip that, as JDK7 handles the rendering intents already.
if (!JDK_HANDLES_RENDERING_INTENTS) {
// Fix profile before lookup/create // Fix profile before lookup/create
profile.setData(ICC_Profile.icSigHead, profileHeader); profile.setData(ICC_Profile.icSigHead, profileHeader);
} }
}
return getCachedOrCreateCS(profile, profileHeader); return getCachedOrCreateCS(profile, profileHeader);
} }
@ -178,7 +187,7 @@ public final class ColorSpaces {
Validate.notNull(profile, "profile"); Validate.notNull(profile, "profile");
// NOTE: // NOTE:
// Several embedded ICC color profiles are non-compliant with Java and throws CMMException // Several embedded ICC color profiles are non-compliant with Java pre JDK7 and throws CMMException
// The problem with these embedded ICC profiles seems to be the rendering intent // The problem with these embedded ICC profiles seems to be the rendering intent
// being 1 (01000000) - "Media Relative Colormetric" in the offending profiles, // being 1 (01000000) - "Media Relative Colormetric" in the offending profiles,
// and 0 (00000000) - "Perceptual" in the good profiles // and 0 (00000000) - "Perceptual" in the good profiles
@ -208,14 +217,6 @@ public final class ColorSpaces {
ICC_Profile profile; ICC_Profile profile;
switch (colorSpace) { switch (colorSpace) {
// Default cases for convenience
case ColorSpace.CS_sRGB:
case ColorSpace.CS_GRAY:
case ColorSpace.CS_PYCC:
case ColorSpace.CS_CIEXYZ:
case ColorSpace.CS_LINEAR_RGB:
return ColorSpace.getInstance(colorSpace);
case CS_ADOBE_RGB_1998: case CS_ADOBE_RGB_1998:
profile = adobeRGB1998.get(); profile = adobeRGB1998.get();
@ -261,9 +262,9 @@ public final class ColorSpaces {
return createColorSpace(profile); return createColorSpace(profile);
default: default:
// Default cases for convenience
return ColorSpace.getInstance(colorSpace);
} }
throw new IllegalArgumentException(String.format("Unsupported color space: %s", colorSpace));
} }
private static ICC_Profile readProfileFromClasspathResource(final String profilePath) { private static ICC_Profile readProfileFromClasspathResource(final String profilePath) {
@ -351,7 +352,7 @@ public final class ColorSpaces {
private static Properties loadProfiles(final Platform.OperatingSystem os) { private static Properties loadProfiles(final Platform.OperatingSystem os) {
Properties systemDefaults; Properties systemDefaults;
try { try {
systemDefaults = SystemUtil.loadProperties(ColorSpaces.class, "com/twelvemonkeys/imageio/color/icc_profiles_" + os); systemDefaults = SystemUtil.loadProperties(ColorSpaces.class, "com/twelvemonkeys/imageio/color/icc_profiles_" + os.id());
} }
catch (IOException ignore) { catch (IOException ignore) {
ignore.printStackTrace(); ignore.printStackTrace();