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 702a7cc3..767e6b8e 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 @@ -173,6 +173,21 @@ public final class ColorSpaces { } } + /** + * Tests whether an ICC color profile is equal to the default sRGB profile. + * + * @param profile the ICC profile to test. May not be {@code null}. + * @return {@code true} if {@code profile} is equal to the default sRGB profile. + * @throws IllegalArgumentException if {@code profile} is {@code null} + * + * @see java.awt.color.ColorSpace#isCS_sRGB() + */ + public static boolean isCS_sRGB(final ICC_Profile profile) { + Validate.notNull(profile, "profile"); + + return profile.getColorSpaceType() == ColorSpace.TYPE_RGB && Arrays.equals(profile.getData(ICC_Profile.icSigHead), sRGB.header); + } + /** * Tests whether an ICC color profile is known to cause problems for {@link java.awt.image.ColorConvertOp}. *
@@ -229,7 +244,7 @@ public final class ColorSpaces { if (profile == null) { // Fall back to the bundled ClayRGB1998 public domain Adobe RGB 1998 compatible profile, - // identical for all practical purposes + // which is identical for all practical purposes profile = readProfileFromClasspathResource("/profiles/ClayRGB1998.icc"); if (profile == null) { @@ -339,15 +354,19 @@ public final class ColorSpaces { private static class sRGB { private static final byte[] header = ICC_Profile.getInstance(ColorSpace.CS_sRGB).getData(ICC_Profile.icSigHead); } + private static class CIEXYZ { private static final byte[] header = ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ).getData(ICC_Profile.icSigHead); } + private static class PYCC { private static final byte[] header = ICC_Profile.getInstance(ColorSpace.CS_PYCC).getData(ICC_Profile.icSigHead); } + private static class GRAY { private static final byte[] header = ICC_Profile.getInstance(ColorSpace.CS_GRAY).getData(ICC_Profile.icSigHead); } + private static class LINEAR_RGB { private static final byte[] header = ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB).getData(ICC_Profile.icSigHead); } @@ -361,7 +380,14 @@ public final class ColorSpaces { systemDefaults = SystemUtil.loadProperties(ColorSpaces.class, "com/twelvemonkeys/imageio/color/icc_profiles_" + os.id()); } catch (IOException ignore) { - ignore.printStackTrace(); + System.err.printf( + "Warning: Could not load system default ICC profile locations from %s, will use bundled fallback profiles.\n", + ignore.getMessage() + ); + if (DEBUG) { + ignore.printStackTrace(); + } + systemDefaults = null; } diff --git a/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_lnx.properties b/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_lnx.properties new file mode 100644 index 00000000..706fe6d6 --- /dev/null +++ b/imageio/imageio-core/src/main/resources/com/twelvemonkeys/imageio/color/icc_profiles_lnx.properties @@ -0,0 +1,29 @@ +# +# Copyright (c) 2013, 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=unknown, use built in for now +#ADOBE_RGB_1998=unknown, use built in for now \ No newline at end of file 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 index bab2bf93..21fef9f9 100644 --- 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 @@ -26,4 +26,4 @@ # 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 +#ADOBE_RGB_1998=unknown, use built in for now \ No newline at end of file diff --git a/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/color/ColorSpacesTest.java b/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/color/ColorSpacesTest.java index 9dddc7aa..ac154765 100644 --- a/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/color/ColorSpacesTest.java +++ b/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/color/ColorSpacesTest.java @@ -139,7 +139,7 @@ public class ColorSpacesTest { assertSame(cs, ColorSpaces.createColorSpace(iccCs.getProfile())); } else { - System.err.println("Not an ICC_ColorSpace: " + cs); + System.err.println("WARNING: Not an ICC_ColorSpace: " + cs); } } @@ -163,7 +163,25 @@ public class ColorSpacesTest { assertSame(cs, ColorSpaces.createColorSpace(iccCs.getProfile())); } else { - System.err.println("Not an ICC_ColorSpace: " + cs); + System.err.println("Warning: Not an ICC_ColorSpace: " + cs); } } + + @Test + public void testIsCS_sRGBTrue() { + assertTrue(ColorSpaces.isCS_sRGB(ICC_Profile.getInstance(ColorSpace.CS_sRGB))); + } + + @Test + public void testIsCS_sRGBFalse() { + assertFalse(ColorSpaces.isCS_sRGB(ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB))); + assertFalse(ColorSpaces.isCS_sRGB(ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ))); + assertFalse(ColorSpaces.isCS_sRGB(ICC_Profile.getInstance(ColorSpace.CS_GRAY))); + assertFalse(ColorSpaces.isCS_sRGB(ICC_Profile.getInstance(ColorSpace.CS_PYCC))); + } + + @Test(expected = IllegalArgumentException.class) + public void testIsCS_sRGBNull() { + ColorSpaces.isCS_sRGB(null); + } }