diff --git a/imageio/imageio-core/src/main/java/com/twelvemonkeys/imageio/color/ColorSpaces.java b/imageio/imageio-core/src/main/java/com/twelvemonkeys/imageio/color/ColorSpaces.java index f30c095f..50e17916 100644 --- a/imageio/imageio-core/src/main/java/com/twelvemonkeys/imageio/color/ColorSpaces.java +++ b/imageio/imageio-core/src/main/java/com/twelvemonkeys/imageio/color/ColorSpaces.java @@ -29,6 +29,8 @@ package com.twelvemonkeys.imageio.color; import com.twelvemonkeys.io.FileUtil; +import com.twelvemonkeys.lang.Platform; +import com.twelvemonkeys.lang.SystemUtil; import com.twelvemonkeys.lang.Validate; import com.twelvemonkeys.util.LRUHashMap; @@ -39,9 +41,27 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Map; +import java.util.Properties; /** * A helper class for working with ICC color profiles and color spaces. + *
+ * Standard ICC color profiles are read from system-specific locations + * for known operating systems. + * + * Color profiles may be configured by placing a property-file + * {@code com/twelvemonkeys/imageio/color/icc_profiles.properties} + * on the classpath, specifying the full path to the profile. + * ICC color profiles are probably already present on your system, or + * can be downloaded from + * ICC, + * Adobe or other places. + * + * Example property file: + *probably + * ADOBE_RGB_1998=/path/to/Adobe RGB 1998.icc + * GENERIC_CMYK=/path/to/Generic CMYK.icc + ** * @author Harald Kuhr * @author last modified by $Author: haraldk$ @@ -161,10 +181,6 @@ public final class ColorSpaces { return data[ICC_Profile.icHdrRenderingIntent] != 0; } - // TODO: Use internal cache (needs mapping between ID and Key...) - // TODO: Allow system-property/config file on class path to configure location of color profiles - // TODO: Document how to download, install and configure Adobe color profiles or other profiles - /** * Returns the color space specified by the given color space constant. * @@ -179,6 +195,8 @@ public final class ColorSpaces { * @see ColorSpaces#CS_GENERIC_CMYK */ public static ColorSpace getColorSpace(int colorSpace) { + // TODO: Use internal cache for AdobeRGB and CMYK! (needs mapping between ID and Key...) + switch (colorSpace) { // Default cases for convenience case ColorSpace.CS_sRGB: @@ -189,10 +207,9 @@ public final class ColorSpaces { return ColorSpace.getInstance(colorSpace); case CS_ADOBE_RGB_1998: - // TODO: Read profile specified by config file instead of hard coded try { - // This works for OS X only - return createColorSpace(ICC_Profile.getInstance("/System/Library/ColorSync/Profiles/AdobeRGB1998.icc")); + String profile = Profiles.MAP.getProperty("ADOBE_RGB_1998"); + return createColorSpace(ICC_Profile.getInstance(profile)); } catch (IOException ignore) { } @@ -213,19 +230,13 @@ public final class ColorSpaces { throw new RuntimeException("Could not read AdobeRGB1998 profile"); case CS_GENERIC_CMYK: - // TODO: Read profile specified by config file instead of hard coded - // TODO: C:\Windows\System32\spool\drivers\color\RSWOP.icm for Windows Vista? try { - // This works for OS X only -// return createColorSpace(ICC_Profile.getInstance("/C:/Windows/System32/spool/drivers/color/RSWOP.icm")); - return createColorSpace(ICC_Profile.getInstance("/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc")); -// return createColorSpace(ICC_Profile.getInstance("/Downloads/coated_FOGRA39L_argl.icc")); -// return createColorSpace(ICC_Profile.getInstance("/Downloads/RSWOP.icm")); -// return createColorSpace(ICC_Profile.getInstance("/Downloads/USWebCoatedSWOP.icc")); + String profile = Profiles.MAP.getProperty("GENERIC_CMYK"); + return createColorSpace(ICC_Profile.getInstance(profile)); } catch (IOException ignore) { } - + // Fall back to generic CMYK ColorSpace, which is *insanely slow* using ColorConvertOp... :-P return CMYKColorSpace.getInstance(); default: @@ -270,4 +281,31 @@ public final class ColorSpaces { private static class LINEAR_RGB { private static final byte[] header = ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB).getData(ICC_Profile.icSigHead); } + + private static class Profiles { + static final Properties MAP = loadProfiles(Platform.os()); + + private static Properties loadProfiles(Platform.OperatingSystem os) { + Properties systemDefaults; + try { + systemDefaults = SystemUtil.loadProperties(ColorSpaces.class, "com/twelvemonkeys/imageio/color/icc_profiles_" + os); + } + catch (IOException ignore) { + ignore.printStackTrace(); + systemDefaults = null; + } + + // Create map with defaults and add user overrides if any + Properties profiles = new Properties(systemDefaults); + + try { + Properties userOverrides = SystemUtil.loadProperties(ColorSpaces.class, "com/twelvemonkeys/imageio/color/icc_profiles"); + profiles.putAll(userOverrides); + } + catch (IOException ignore) { + } + + return profiles; + } + } } diff --git a/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_osx.properties b/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_osx.properties new file mode 100644 index 00000000..a516ec1c --- /dev/null +++ b/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_osx.properties @@ -0,0 +1,29 @@ +# +# Copyright (c) 2011, Harald Kuhr +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name "TwelveMonkeys" nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +GENERIC_CMYK=/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc +ADOBE_RGB_1998=/System/Library/ColorSync/Profiles/AdobeRGB1998.icc diff --git a/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_win.properties b/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_win.properties new file mode 100644 index 00000000..bab2bf93 --- /dev/null +++ b/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_win.properties @@ -0,0 +1,29 @@ +# +# Copyright (c) 2011, Harald Kuhr +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name "TwelveMonkeys" nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +GENERIC_CMYK=/C:/Windows/System32/spool/drivers/color/RSWOP.icm +#ADOBE_RGB_1998=use built in for now \ No newline at end of file