Package org.faceless.pdf2
Class ICCColorSpace
- java.lang.Object
-
- java.awt.color.ColorSpace
-
- org.faceless.pdf2.ICCColorSpace
-
- All Implemented Interfaces:
Serializable
public class ICCColorSpace extends ColorSpace
A pure Java version ofICC_ColorSpace
andICC_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 thegetNamedColors()
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 intentstatic int
INTENT_PERCEPTUAL
Represents the "Perceptual" rendering intentstatic int
INTENT_RELATIVE
Represents the "Relative Colorimetric" rendering intentstatic 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(ICC_Profile profile)
Create a new ICCColorSpace from the suppliedICC_Profile
.ICCColorSpace(File file)
Create a new ICCColorSpace from the supplied File.ICCColorSpace(InputStream input)
Create a new ICCColorSpace from the supplied stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ICC_Profile
createICC_Profile()
Create anICC_Profile
from this classboolean
equals(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.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.String
getDescription()
Return the text from the "desc" tag, or null if not availableint
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 1Reader
getMetaData()
Return any XML metadata associated with this object.int
getMinorVersion()
Return the minor version of the profilefloat
getMinValue(int component)
Return the maximum normalized value for the specified component, which is always 0String
getName(int c)
Return the name for the specified component, which is arbitrary and of the form "Comp-n"Map<String,SpotColorSpace>
getNamedColors()
If this profile is aCLASS_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 profileint
getPCSType()
Return the PCS type, one ofColorSpace.TYPE_XYZ
orColorSpace.TYPE_Lab
int
getProfileClass()
Returns the profile class, or -1 if it's unknownInputStream
getProfileData()
Return a stream containing the original bytes passed into the constructorBigInteger
getStoredProfileID()
Return the "Profile ID" from the profile header - bytes 84..99.int
getType()
Returns the color space type of this ColorSpace (for exampleColorSpace.TYPE_RGB
,ColorSpace.TYPE_XYZ
, ...).XMP
getXMP()
Return an XMP Metadata object representing any XML metadata associated with this objectint
hashCode()
boolean
isCS_sRGB()
Return true if this profile is sRGB.void
setMetaData(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)
String
toString()
Return the String version of this object.-
Methods inherited from class java.awt.color.ColorSpace
getInstance
-
-
-
-
Field Detail
-
CLASS_INPUT
public static final int CLASS_INPUT
Profile class is input ("scnr"). Identical toICC_Profile.CLASS_INPUT
- See Also:
- Constant Field Values
-
CLASS_DISPLAY
public static final int CLASS_DISPLAY
Profile class is display ("mntr"). Identical toICC_Profile.CLASS_DISPLAY
- See Also:
- Constant Field Values
-
CLASS_OUTPUT
public static final int CLASS_OUTPUT
Profile class is output ("prtr"). Identical toICC_Profile.CLASS_OUTPUT
- See Also:
- Constant Field Values
-
CLASS_DEVICELINK
public static final int CLASS_DEVICELINK
Profile class is device-link ("link"). Identical toICC_Profile.CLASS_DEVICELINK
- See Also:
- Constant Field Values
-
CLASS_COLORSPACECONVERSION
public static final int CLASS_COLORSPACECONVERSION
Profile class is color-space conversion ("spac"). Identical toICC_Profile.CLASS_COLORSPACECONVERSION
- See Also:
- Constant Field Values
-
CLASS_ABSTRACT
public static final int CLASS_ABSTRACT
Profile class is abstract ("abst"). Identical toICC_Profile.CLASS_ABSTRACT
- See Also:
- Constant Field Values
-
CLASS_NAMEDCOLOR
public static final int CLASS_NAMEDCOLOR
Profile class is named color ("name"). Identical toICC_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(ICC_Profile profile) throws IOException
Create a new ICCColorSpace from the suppliedICC_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
-
createICC_Profile
public ICC_Profile createICC_Profile()
Create anICC_Profile
from this class
-
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
-
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.
-
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()
-
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 ofColorSpace.TYPE_XYZ
orColorSpace.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 classColorSpace
-
fromCIEXYZ
public float[] fromCIEXYZ(float[] xyz)
- Specified by:
fromCIEXYZ
in classColorSpace
-
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 classColorSpace
- Parameters:
components
- a float array with length of at leastgetNumComponents()
-
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 classColorSpace
- 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 3intent
- the Rendering Intent, one ofINTENT_RELATIVE
,INTENT_PERCEPTUAL
,INTENT_SATURATION
orINTENT_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 thejava.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 classColorSpace
- Parameters:
components
- a float array with length of at leastgetNumComponents()
-
toRGB
public 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.- Parameters:
components
- a float array with length of at leastgetNumComponents()
intent
- the Rendering Intent, one ofINTENT_RELATIVE
,INTENT_PERCEPTUAL
,INTENT_SATURATION
orINTENT_ABSOLUTE
- Since:
- 2.24.1
-
getType
public int getType()
Returns the color space type of this ColorSpace (for exampleColorSpace.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 classColorSpace
- 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 classColorSpace
-
getMaxValue
public float getMaxValue(int component)
Return the maximum normalized value for the specified component, which is always 1- Overrides:
getMaxValue
in classColorSpace
- Parameters:
component
- the component index, from 0 togetNumComponents()
-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 classColorSpace
- Parameters:
component
- the component index, from 0 togetNumComponents()
-1- Returns:
- 0
-
getNamedColors
public Map<String,SpotColorSpace> getNamedColors()
If this profile is aCLASS_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 classColorSpace
- Parameters:
c
- the component index, from 0 togetNumComponents()
-1- Returns:
- the arbitrary color name
-
toRGB
public int[] toRGB(int[] in, int[] out, int intent)
-
toCIEXYZ
public float[] toCIEXYZ(float[] c, int intent)
Convert to from this colorspace to XYZ. Identical totoCIEXYZ(float[])
except that you can also specify the rendering intent- Parameters:
c
- a float array with length of at leastgetNumComponents()
intent
- the Rendering Intent, one ofINTENT_RELATIVE
,INTENT_PERCEPTUAL
,INTENT_SATURATION
orINTENT_ABSOLUTE
- Since:
- 2.24.1
-
fromCIEXYZ
public float[] fromCIEXYZ(float[] xyz, int intent)
Convert from XYZ to this ColorSpace. Identical tofromCIEXYZ(float[])
except that you can also specify the rendering intent- Parameters:
xyz
- a float array with length of at least 3intent
- the Rendering Intent, one ofINTENT_RELATIVE
,INTENT_PERCEPTUAL
,INTENT_SATURATION
orINTENT_ABSOLUTE
- Since:
- 2.24.1
-
toString
public String toString()
Return the String version of this object. This method will always return a valid JSON string representing the complete object.
-
setMetaData
public void setMetaData(String metadata)
Set the XML metadata associated with this object. SeePDF.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>
nodeSince 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
-
-