Class ICCColorSpace

  • All Implemented Interfaces:
    Serializable

    public class ICCColorSpace
    extends 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
    • Constructor Detail

      • ICCColorSpace

        public ICCColorSpace​(ICC_Profile profile)
                      throws 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:
        IOException - if the profile cannot be read
      • ICCColorSpace

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

        public ICCColorSpace​(InputStream input)
                      throws 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:
        IOException - if the profile cannot be read
    • Method Detail

      • getProfileData

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

        public 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 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 Object
      • equals

        public boolean equals​(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 Object
      • getDescription

        public 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()
      • 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 ColorSpace
      • fromCIEXYZ

        public float[] fromCIEXYZ​(float[] xyz)
        Specified by:
        fromCIEXYZ in class 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 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 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 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 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 ColorSpace
      • getMaxValue

        public float getMaxValue​(int component)
        Return the maximum normalized value for the specified component, which is always 1
        Overrides:
        getMaxValue in class 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 ColorSpace
        Parameters:
        component - the component index, from 0 to getNumComponents()-1
        Returns:
        0
      • getNamedColors

        public Map<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 String getName​(int c)
        Return the name for the specified component, which is arbitrary and of the form "Comp-n"
        Overrides:
        getName in class 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 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 Object
      • setMetaData

        public void setMetaData​(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 Reader getMetaData()
                           throws 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:
        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