Class ColorProfiles
- java.lang.Object
-
- com.twelvemonkeys.imageio.color.ColorProfiles
-
public final class ColorProfiles extends java.lang.ObjectA helper class for working with ICC color profiles.Standard ICC color profiles are read from system-specific locations for known operating systems.
Color profiles may be configured by placing a property-file
com/twelvemonkeys/imageio/color/icc_profiles.propertieson the classpath, specifying the full path to the profiles. ICC color profiles are probably already present on your system, or can be downloaded from ICC, Adobe or other places. *Example property file:
# icc_profiles.properties ADOBE_RGB_1998=/path/to/Adobe RGB 1998.icc GENERIC_CMYK=/path/to/Generic CMYK.icc
- Version:
- $Id: ColorSpaces.java,v 1.0 24.01.11 17.51 haraldk Exp$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classColorProfiles.CIEXYZ(package private) static classColorProfiles.GRAY(package private) static classColorProfiles.LINEAR_RGB(package private) static classColorProfiles.Profiles(package private) static classColorProfiles.PYCC(package private) static classColorProfiles.sRGB
-
Field Summary
Fields Modifier and Type Field Description (package private) static intICC_PROFILE_HEADER_SIZE(package private) static intICC_PROFILE_MAGICprivate static ICCProfileSanitizerprofileCleanerWe need special ICC profile handling for KCMS vs LCMS.
-
Constructor Summary
Constructors Modifier Constructor Description privateColorProfiles()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static byte[]computeMD5(byte[] header, byte[] data)static java.awt.color.ICC_ProfilecreateProfile(byte[] input)Reads an ICC Profile from the given byte array, with extra validation.static java.awt.color.ICC_ProfilecreateProfileRaw(byte[] input)Creates an ICC Profile from the given byte array, as-is, with no validation.(package private) static voidfixProfile(java.awt.color.ICC_Profile profile)private static intgetCsType(byte[] profileHeader)private static java.awt.color.ICC_ProfilegetInternalProfile(byte[] profileHeader)(package private) static byte[]getProfileHeaderWithProfileId(byte[] data)(package private) static byte[]getProfileHeaderWithProfileId(java.awt.color.ICC_Profile profile)private static intintBigEndian(byte[] data, int index)static booleanisCS_GRAY(java.awt.color.ICC_Profile profile)Tests whether an ICC color profile is equal to the default GRAY profile.static booleanisCS_sRGB(java.awt.color.ICC_Profile profile)Tests whether an ICC color profile is equal to the default sRGB profile.(package private) static booleanisOffendingColorProfile(java.awt.color.ICC_Profile profile)Tests whether an ICC color profile is known to cause problems forColorConvertOp.private static byte[]limit(byte[] input, int size)static java.awt.color.ICC_ProfilereadProfile(java.io.InputStream input)Reads an ICC Profile from the given input stream, with extra validation.(package private) static java.awt.color.ICC_ProfilereadProfileFromClasspathResource(java.lang.String profilePath)(package private) static java.awt.color.ICC_ProfilereadProfileFromPath(java.lang.String profilePath)static java.awt.color.ICC_ProfilereadProfileRaw(java.io.InputStream input)Reads an ICC Profile from the given input stream, as-is, with no validation.private static intvalidateAndGetSize(byte[] input)private static intvalidateHeaderAndGetSize(byte[] input)static java.awt.color.ICC_ProfilevalidateProfile(java.awt.color.ICC_Profile profile)Tests whether an ICC color profile is valid.(package private) static booleanvalidationAltersProfileHeader()
-
-
-
Field Detail
-
profileCleaner
private static final ICCProfileSanitizer profileCleaner
We need special ICC profile handling for KCMS vs LCMS. Delegate to specific strategy.
-
ICC_PROFILE_MAGIC
static final int ICC_PROFILE_MAGIC
- See Also:
- Constant Field Values
-
ICC_PROFILE_HEADER_SIZE
static final int ICC_PROFILE_HEADER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getProfileHeaderWithProfileId
static byte[] getProfileHeaderWithProfileId(java.awt.color.ICC_Profile profile)
-
getProfileHeaderWithProfileId
static byte[] getProfileHeaderWithProfileId(byte[] data)
-
computeMD5
private static byte[] computeMD5(byte[] header, byte[] data)
-
isCS_sRGB
public static boolean isCS_sRGB(java.awt.color.ICC_Profile profile)
Tests whether an ICC color profile is equal to the default sRGB profile.- Parameters:
profile- the ICC profile to test. May not benull.- Returns:
trueifprofileis equal to the default sRGB profile.- Throws:
java.lang.IllegalArgumentException- ifprofileisnull- See Also:
ColorSpace.CS_sRGB,ColorSpace.isCS_sRGB()
-
isCS_GRAY
public static boolean isCS_GRAY(java.awt.color.ICC_Profile profile)
Tests whether an ICC color profile is equal to the default GRAY profile.- Parameters:
profile- the ICC profile to test. May not benull.- Returns:
trueifprofileis equal to the default GRAY profile.- Throws:
java.lang.IllegalArgumentException- ifprofileisnull- See Also:
ColorSpace.CS_GRAY
-
isOffendingColorProfile
static boolean isOffendingColorProfile(java.awt.color.ICC_Profile profile)
Tests whether an ICC color profile is known to cause problems forColorConvertOp.Note that this method only tests if a color conversion using this profile is known to fail. There's no guarantee that the color conversion will succeed even if this method returns
false.- Parameters:
profile- the ICC color profile. May not benull.- Returns:
trueif known to be offending,falseotherwise- Throws:
java.lang.IllegalArgumentException- ifprofileisnull
-
validateProfile
public static java.awt.color.ICC_Profile validateProfile(java.awt.color.ICC_Profile profile)
Tests whether an ICC color profile is valid. Invalid profiles are known to cause problems forColorConvertOp.Note that this method only tests if a color conversion using this profile is known to fail. There's no guarantee that the color conversion will succeed even if this method returns
false.- Parameters:
profile- the ICC color profile. May not benull.- Returns:
profileif valid.- Throws:
java.lang.IllegalArgumentException- ifprofileisnulljava.awt.color.CMMException- ifprofileis invalid.
-
readProfileRaw
public static java.awt.color.ICC_Profile readProfileRaw(java.io.InputStream input) throws java.io.IOExceptionReads an ICC Profile from the given input stream, as-is, with no validation. This method behaves exactly likeICC_Profile.getInstance(input).- Parameters:
input- the input stream to read from, may not benull- Returns:
- an
ICC_Profileobject as read from the input stream. - Throws:
java.io.IOException- If an I/O error occurs while reading the stream.java.lang.IllegalArgumentException- Ifinputisnullor the stream does not contain valid ICC Profile data.- See Also:
ICC_Profile.getInstance(InputStream),readProfile(InputStream)
-
readProfile
public static java.awt.color.ICC_Profile readProfile(java.io.InputStream input) throws java.io.IOExceptionReads an ICC Profile from the given input stream, with extra validation. If a matching profile already exists in cache, the cached instance is returned.- Parameters:
input- the input stream to read from, may not benull- Returns:
- an
ICC_Profileobject as read from the input stream. - Throws:
java.io.IOException- If an I/O error occurs while reading the stream.java.lang.IllegalArgumentException- Ifinputisnullor the stream does not contain valid ICC Profile data.- See Also:
ICC_Profile.getInstance(InputStream)
-
createProfileRaw
public static java.awt.color.ICC_Profile createProfileRaw(byte[] input)
Creates an ICC Profile from the given byte array, as-is, with no validation. This method behaves exactly likeICC_Profile.getInstance(input), except that extraneous bytes at the end of the array is ignored.- Parameters:
input- the byte array to create a profile from, may not benull- Returns:
- an
ICC_Profileobject created from the byte array - Throws:
java.lang.IllegalArgumentException- Ifinputisnullor the byte array does not contain valid ICC Profile data.- See Also:
ICC_Profile.getInstance(byte[]),createProfile(byte[])
-
createProfile
public static java.awt.color.ICC_Profile createProfile(byte[] input)
Reads an ICC Profile from the given byte array, with extra validation. Extraneous bytes at the end of the array are ignored. If a matching profile already exists in cache, the cached instance is returned.- Parameters:
input- the byte array to create a profile from, may not benull- Returns:
- an
ICC_Profileobject created from the byte array - Throws:
java.lang.IllegalArgumentException- Ifinputisnullor the byte array does not contain valid ICC Profile data.- See Also:
ICC_Profile.getInstance(byte[])
-
limit
private static byte[] limit(byte[] input, int size)
-
validateAndGetSize
private static int validateAndGetSize(byte[] input)
-
validateHeaderAndGetSize
private static int validateHeaderAndGetSize(byte[] input)
-
getInternalProfile
private static java.awt.color.ICC_Profile getInternalProfile(byte[] profileHeader)
-
intBigEndian
private static int intBigEndian(byte[] data, int index)
-
getCsType
private static int getCsType(byte[] profileHeader)
-
readProfileFromClasspathResource
static java.awt.color.ICC_Profile readProfileFromClasspathResource(java.lang.String profilePath)
-
readProfileFromPath
static java.awt.color.ICC_Profile readProfileFromPath(java.lang.String profilePath)
-
fixProfile
static void fixProfile(java.awt.color.ICC_Profile profile)
-
validationAltersProfileHeader
static boolean validationAltersProfileHeader()
-
-