Class ICCColorSpace

  • All Implemented Interfaces:
    java.io.Serializable

    public class ICCColorSpace
    extends java.awt.color.ColorSpace
    A pure Java version of ICC_ColorSpace and ICC_Profile, this class avoids the many issues with the use of those classes in a multi-threaded environment. It supports ICC v2 and v4 profiles, and provides support for "Named Color" profiles via the getNamedColors() method.
    Since:
    2.23
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CLASS_ABSTRACT
      Profile class is abstract ("abst").
      static int CLASS_COLORSPACECONVERSION
      Profile class is color-space conversion ("spac").
      static int CLASS_DEVICELINK
      Profile class is device-link ("link").
      static int CLASS_DISPLAY
      Profile class is display ("mntr").
      static int CLASS_INPUT
      Profile class is input ("scnr").
      static int CLASS_NAMEDCOLOR
      Profile class is named color ("name").
      static int CLASS_OUTPUT
      Profile class is output ("prtr").
      static int INTENT_ABSOLUTE
      Represents the "Absolute Colorimetric" rendering intent
      static int INTENT_PERCEPTUAL
      Represents the "Perceptual" rendering intent
      static int INTENT_RELATIVE
      Represents the "Relative Colorimetric" rendering intent
      static int INTENT_SATURATION
      Represents the "Saturation" rendering intent
      • Fields inherited from class java.awt.color.ColorSpace

        CS_CIEXYZ, CS_GRAY, CS_LINEAR_RGB, CS_PYCC, CS_sRGB, TYPE_2CLR, TYPE_3CLR, TYPE_4CLR, TYPE_5CLR, TYPE_6CLR, TYPE_7CLR, TYPE_8CLR, TYPE_9CLR, TYPE_ACLR, TYPE_BCLR, TYPE_CCLR, TYPE_CMY, TYPE_CMYK, TYPE_DCLR, TYPE_ECLR, TYPE_FCLR, TYPE_GRAY, TYPE_HLS, TYPE_HSV, TYPE_Lab, TYPE_Luv, TYPE_RGB, TYPE_XYZ, TYPE_YCbCr, TYPE_Yxy
    • Constructor Summary

      Constructors 
      Constructor Description
      ICCColorSpace​(java.awt.color.ICC_Profile profile)
      Create a new ICCColorSpace from the supplied ICC_Profile.
      ICCColorSpace​(java.io.File file)
      Create a new ICCColorSpace from the supplied File.
      ICCColorSpace​(java.io.InputStream input)
      Create a new ICCColorSpace from the supplied stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.color.ICC_Profile createICC_Profile()
      Create an ICC_Profile from this class
      boolean equals​(java.lang.Object o)
      Return true if this object is equal to the specified object.
      float[] fromCIEXYZ​(float[] xyz)  
      float[] fromCIEXYZ​(float[] xyz, int intent)
      Convert from XYZ to this ColorSpace.
      float[] fromRGB​(float[] rgb)
      Transforms a color value assumed to be in the default CS_sRGB color space into this ColorSpace.
      float[] fromRGB​(float[] rgb, int intent)
      Transforms a color value assumed to be in the default CS_sRGB color space into this ColorSpace.
      java.math.BigInteger getCalculatedProfileID()
      Return the calculated "Profile ID" as it should be stored in the profile header - this is the MD5 checksum of the ICC profile.
      java.lang.String getDescription()
      Return the text from the "desc" tag, or null if not available
      int getMajorVersion()
      Return the major version of the profile (2 or 4 at the time of writing)
      float getMaxValue​(int component)
      Return the maximum normalized value for the specified component, which is always 1
      java.io.Reader getMetaData()
      Return any XML metadata associated with this object.
      int getMinorVersion()
      Return the minor version of the profile
      float getMinValue​(int component)
      Return the maximum normalized value for the specified component, which is always 0
      java.lang.String getName​(int c)
      Return the name for the specified component, which is arbitrary and of the form "Comp-n"
      java.util.Map<java.lang.String,​SpotColorSpace> getNamedColors()
      If this profile is a CLASS_NAMEDCOLOR profile class, return a map of named colors to SpotColorSpaces defined by this profile.
      int getNumComponents()
      Returns the number of components of this ColorSpace.
      int getPatchVersion()
      Return the minor version of the profile
      int getPCSType()
      Return the PCS type, one of ColorSpace.TYPE_XYZ or ColorSpace.TYPE_Lab
      int getProfileClass()
      Returns the profile class, or -1 if it's unknown
      java.io.InputStream getProfileData()
      Return a stream containing the original bytes passed into the constructor
      java.math.BigInteger getStoredProfileID()
      Return the "Profile ID" from the profile header - bytes 84..99.
      int getType()
      Returns the color space type of this ColorSpace (for example ColorSpace.TYPE_RGB, ColorSpace.TYPE_XYZ, ...).
      XMP getXMP()
      Return an XMP Metadata object representing any XML metadata associated with this object
      int hashCode()  
      boolean isCS_sRGB()
      Return true if this profile is sRGB.
      void setMetaData​(java.lang.String metadata)
      Set the XML metadata associated with this object.
      float[] toCIEXYZ​(float[] components)
      Transforms a color value assumed to be in this ColorSpace into the CS_CIEXYZ conversion color space.
      float[] toCIEXYZ​(float[] c, int intent)
      Convert to from this colorspace to XYZ.
      float[] toRGB​(float[] components)
      Transforms a color value assumed to be in this ColorSpace into a value in the default CS_sRGB color space.
      float[] toRGB​(float[] components, int intent)
      Transforms a color value assumed to be in this ColorSpace into a value in the default CS_sRGB color space.
      int[] toRGB​(int[] in, int[] out, int intent)  
      java.lang.String toString()
      Return the String version of this object.
      • Methods inherited from class java.awt.color.ColorSpace

        getInstance
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • CLASS_INPUT

        public static final int CLASS_INPUT
        Profile class is input ("scnr"). Identical to ICC_Profile.CLASS_INPUT
        See Also:
        Constant Field Values
      • CLASS_DISPLAY

        public static final int CLASS_DISPLAY
        Profile class is display ("mntr"). Identical to ICC_Profile.CLASS_DISPLAY
        See Also:
        Constant Field Values
      • CLASS_OUTPUT

        public static final int CLASS_OUTPUT
        Profile class is output ("prtr"). Identical to ICC_Profile.CLASS_OUTPUT
        See Also:
        Constant Field Values
      • CLASS_DEVICELINK

        public static final int CLASS_DEVICELINK
        Profile class is device-link ("link"). Identical to ICC_Profile.CLASS_DEVICELINK
        See Also:
        Constant Field Values
      • CLASS_COLORSPACECONVERSION

        public static final int CLASS_COLORSPACECONVERSION
        Profile class is color-space conversion ("spac"). Identical to ICC_Profile.CLASS_COLORSPACECONVERSION
        See Also:
        Constant Field Values
      • CLASS_ABSTRACT

        public static final int CLASS_ABSTRACT
        Profile class is abstract ("abst"). Identical to ICC_Profile.CLASS_ABSTRACT
        See Also:
        Constant Field Values
      • CLASS_NAMEDCOLOR

        public static final int CLASS_NAMEDCOLOR
        Profile class is named color ("name"). Identical to ICC_Profile.CLASS_NAMEDCOLOR.
        See Also:
        getNamedColors(), Constant Field Values
      • INTENT_PERCEPTUAL

        public static final int INTENT_PERCEPTUAL
        Represents the "Perceptual" rendering intent
        See Also:
        Constant Field Values
      • INTENT_RELATIVE

        public static final int INTENT_RELATIVE
        Represents the "Relative Colorimetric" rendering intent
        See Also:
        Constant Field Values
      • INTENT_SATURATION

        public static final int INTENT_SATURATION
        Represents the "Saturation" rendering intent
        See Also:
        Constant Field Values
      • INTENT_ABSOLUTE

        public static final int INTENT_ABSOLUTE
        Represents the "Absolute Colorimetric" rendering intent
        See Also:
        Constant Field Values
    • Constructor Detail

      • ICCColorSpace

        public ICCColorSpace​(java.awt.color.ICC_Profile profile)
                      throws java.io.IOException
        Create a new ICCColorSpace from the supplied ICC_Profile. The bytes from the supplied profile are re-read so the two objects are completely independent.
        Parameters:
        profile - the ICC_Profile to load
        Throws:
        java.io.IOException - if the profile cannot be read
      • ICCColorSpace

        public ICCColorSpace​(java.io.File file)
                      throws java.io.IOException
        Create a new ICCColorSpace from the supplied File.
        Parameters:
        file - the file containing the ICC_Profile to load
        Throws:
        java.io.IOException - if the profile cannot be read
      • ICCColorSpace

        public ICCColorSpace​(java.io.InputStream input)
                      throws java.io.IOException
        Create a new ICCColorSpace from the supplied stream. The stream is not closed on completion.
        Parameters:
        input - the stream containing the ICC_Profile to load
        Throws:
        java.io.IOException - if the profile cannot be read
    • Method Detail

      • createICC_Profile

        public java.awt.color.ICC_Profile createICC_Profile()
        Create an ICC_Profile from this class
      • getProfileData

        public java.io.InputStream getProfileData()
        Return a stream containing the original bytes passed into the constructor
      • getStoredProfileID

        public java.math.BigInteger getStoredProfileID()
        Return the "Profile ID" from the profile header - bytes 84..99. This is supposed to be the MD5 checksum of the ICC profile. If the checksum has not been calculated this method returns null.
        Since:
        2.28.2
      • getCalculatedProfileID

        public java.math.BigInteger getCalculatedProfileID()
        Return the calculated "Profile ID" as it should be stored in the profile header - this is the MD5 checksum of the ICC profile.
        Since:
        2.28.2
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Return true if this object is equal to the specified object. Two ICC profiles are equal if a) they contain the same data, excluding the stored checksum, pcsintent and flags, and b) the stored checksum (or the calculated checksum if not set) is equal in both profiles.
        Overrides:
        equals in class java.lang.Object
      • getDescription

        public java.lang.String getDescription()
        Return the text from the "desc" tag, or null if not available
      • getMajorVersion

        public int getMajorVersion()
        Return the major version of the profile (2 or 4 at the time of writing)
        See Also:
        ICC_Profile.getMajorVersion()
      • getMinorVersion

        public int getMinorVersion()
        Return the minor version of the profile
        See Also:
        ICC_Profile.getMinorVersion()
      • getPatchVersion

        public int getPatchVersion()
        Return the minor version of the profile
        See Also:
        ICC_Profile.getMinorVersion()
      • getPCSType

        public int getPCSType()
        Return the PCS type, one of ColorSpace.TYPE_XYZ or ColorSpace.TYPE_Lab
        See Also:
        ICC_Profile.getPCSType()
      • getProfileClass

        public int getProfileClass()
        Returns the profile class, or -1 if it's unknown
        Returns:
        one of the predefined profile class constants.
        See Also:
        ICC_Profile.getProfileClass()
      • isCS_sRGB

        public boolean isCS_sRGB()
        Return true if this profile is sRGB. A "best effort" is made to determine this, by checking that the matrix is essentially identical. This is necessary as there are many variations of profile that claim to be sRGB.
        Overrides:
        isCS_sRGB in class java.awt.color.ColorSpace
      • fromCIEXYZ

        public float[] fromCIEXYZ​(float[] xyz)
        Specified by:
        fromCIEXYZ in class java.awt.color.ColorSpace
      • toCIEXYZ

        public float[] toCIEXYZ​(float[] components)
        Transforms a color value assumed to be in this ColorSpace into the CS_CIEXYZ conversion color space. This method transforms color values using relative colorimetry.
        Specified by:
        toCIEXYZ in class java.awt.color.ColorSpace
        Parameters:
        components - a float array with length of at least getNumComponents()
      • fromRGB

        public float[] fromRGB​(float[] rgb)
        Transforms a color value assumed to be in the default CS_sRGB color space into this ColorSpace. This method transforms color values using the Perceptual rendering intent.
        Specified by:
        fromRGB in class java.awt.color.ColorSpace
        Parameters:
        rgb - a float array with length of at least 3
      • fromRGB

        public float[] fromRGB​(float[] rgb,
                               int intent)
        Transforms a color value assumed to be in the default CS_sRGB color space into this ColorSpace.
        Parameters:
        rgb - a float array with length of at least 3
        intent - the Rendering Intent, one of INTENT_RELATIVE, INTENT_PERCEPTUAL, INTENT_SATURATION or INTENT_ABSOLUTE
        Since:
        2.24.1
      • toRGB

        public float[] toRGB​(float[] components)
        Transforms a color value assumed to be in this ColorSpace into a value in the default CS_sRGB color space. Note the java.awt.Color method says that the "Perceptual" rendering intent should be used - we have come to the conclusion that this is wrong. The method uses the Perceptual rendering intent, and maps out-of-gamut color by converting to LCH and reducing Chroma until the color is in gamut. See https://colorjs.io/docs/gamut-mapping.html for the reasoning behind this.
        Specified by:
        toRGB in class java.awt.color.ColorSpace
        Parameters:
        components - a float array with length of at least getNumComponents()
      • getType

        public int getType()
        Returns the color space type of this ColorSpace (for example ColorSpace.TYPE_RGB, ColorSpace.TYPE_XYZ, ...). The type defines the number of components of the color space and the interpretation, e.g. ColorSpace.TYPE_RGB identifies a color space with three components - red, green, and blue. It does not define the particular color characteristics of the space, e.g. the chromaticities of the primaries.
        Overrides:
        getType in class java.awt.color.ColorSpace
        Returns:
        the type constant that represents the type of this ColorSpace
      • getNumComponents

        public int getNumComponents()
        Returns the number of components of this ColorSpace.
        Overrides:
        getNumComponents in class java.awt.color.ColorSpace
      • getMaxValue

        public float getMaxValue​(int component)
        Return the maximum normalized value for the specified component, which is always 1
        Overrides:
        getMaxValue in class java.awt.color.ColorSpace
        Parameters:
        component - the component index, from 0 to getNumComponents()-1
        Returns:
        1
      • getMinValue

        public float getMinValue​(int component)
        Return the maximum normalized value for the specified component, which is always 0
        Overrides:
        getMinValue in class java.awt.color.ColorSpace
        Parameters:
        component - the component index, from 0 to getNumComponents()-1
        Returns:
        0
      • getNamedColors

        public java.util.Map<java.lang.String,​SpotColorSpace> getNamedColors()
        If this profile is a CLASS_NAMEDCOLOR profile class, return a map of named colors to SpotColorSpaces defined by this profile. Otherwise return null.
        Returns:
        a Map of Color Names to SpotColorSpace objects, or null if this is not a named cole
      • getName

        public java.lang.String getName​(int c)
        Return the name for the specified component, which is arbitrary and of the form "Comp-n"
        Overrides:
        getName in class java.awt.color.ColorSpace
        Parameters:
        c - the component index, from 0 to getNumComponents()-1
        Returns:
        the arbitrary color name
      • toRGB

        public int[] toRGB​(int[] in,
                           int[] out,
                           int intent)
      • toString

        public java.lang.String toString()
        Return the String version of this object. This method will always return a valid JSON string representing the complete object.
        Overrides:
        toString in class java.lang.Object
      • setMetaData

        public void setMetaData​(java.lang.String metadata)
        Set the XML metadata associated with this object. See PDF.setMetaData for more information.
        Parameters:
        metadata - the XML data to embed into the document, or null to clear any existing metadata. No validation is performed on this input.
        Since:
        2.24.3
      • getMetaData

        public java.io.Reader getMetaData()
                                   throws java.io.IOException

        Return any XML metadata associated with this object. See the PDF.getMetaData() for more information.

        Note that JPEG2000 images may have more than one MetaData stream embedded in them. If this is the case, in order to present only a single root node to the XML Parser, the XML objects are all wrapped in a single <JPEG2000> node

        Since 2.24.3, the returned type is guaranteed to hava a toString() method that will return the Metadata as a String.

        Returns:
        a Reader containing the source of the XML or null if no metadata is available.
        Throws:
        java.io.IOException - if the metadata can't be extracted
        Since:
        2.24.3
      • getXMP

        public XMP getXMP()
        Return an XMP Metadata object representing any XML metadata associated with this object
        Returns:
        the XMP, which may be empty or invalid but wil never be null
        Since:
        2.26