Class ColorSpace
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ICC_ColorSpace
Color object or, via a ColorModel
object, of an Image, a BufferedImage, or a
GraphicsDevice. It contains methods that transform colors in a
specific color space to/from sRGB and to/from a well-defined CIEXYZ color
space.
For purposes of the methods in this class, colors are represented as arrays
of color components represented as floats in a normalized range defined by
each ColorSpace. For many ColorSpaces (e.g. sRGB), this range
is 0.0 to 1.0. However, some ColorSpaces have components whose values
have a different range. Methods are provided to inquire per component minimum
and maximum normalized values.
Several variables are defined for purposes of referring to color space types
(e.g. TYPE_RGB, TYPE_XYZ, etc.) and to refer to specific
color spaces (e.g. CS_sRGB and CS_CIEXYZ). sRGB is a proposed
standard RGB color space. For more information, see
http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html.
The purpose of the methods to transform to/from the well-defined CIEXYZ color
space is to support conversions between any two color spaces at a reasonably
high degree of accuracy. It is expected that particular implementations of
subclasses of ColorSpace (e.g. ICC_ColorSpace) will support
high performance conversion based on underlying platform color management
systems.
The CS_CIEXYZ space used by the toCIEXYZ/fromCIEXYZ methods
can be described as follows:
CIEXYZ viewing illuminance: 200 lux viewing white point: CIE D50 media white point: "that of a perfectly reflecting diffuser" -- D50 media black point: 0 lux or 0 Reflectance flare: 1 percent surround: 20percent of the media white point media description: reflection print (i.e., RLAB, Hunt viewing media) note: For developers creating an ICC profile for this conversion space, the following is applicable. Use a simple Von Kries white point adaptation folded into the 3X3 matrix parameters and fold the flare and surround effects into the three one-dimensional lookup tables (assuming one uses the minimal model for monitors).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe built-in CIEXYZ conversion color space defined above.static final intThe built-in linear gray scale color space.static final intThe built-in linear RGB color space.static final intThe built-in Photo YCC conversion color space.static final intThe built-in sRGB color space defined at http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html.static final intGeneric 2 component color spaces.static final intGeneric 3 component color spaces.static final intGeneric 4 component color spaces.static final intGeneric 5 component color spaces.static final intGeneric 6 component color spaces.static final intGeneric 7 component color spaces.static final intGeneric 8 component color spaces.static final intGeneric 9 component color spaces.static final intGeneric 10 component color spaces.static final intGeneric 11 component color spaces.static final intGeneric 12 component color spaces.static final intAny of the family of CMY color spaces.static final intAny of the family of CMYK color spaces.static final intGeneric 13 component color spaces.static final intGeneric 14 component color spaces.static final intGeneric 15 component color spaces.static final intAny of the family of GRAY color spaces.static final intAny of the family of HLS color spaces.static final intAny of the family of HSV color spaces.static final intAny of the family of Lab color spaces.static final intAny of the family of Luv color spaces.static final intAny of the family of RGB color spaces.static final intAny of the family of XYZ color spaces.static final intAny of the family of YCbCr color spaces.static final intAny of the family of Yxy color spaces. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedColorSpace(int type, int numComponents) Constructs aColorSpaceobject given a color space type and the number of components. -
Method Summary
Modifier and TypeMethodDescriptionabstract float[]fromCIEXYZ(float[] colorvalue) Transforms a color value assumed to be in theCS_CIEXYZconversion color space into thisColorSpace.abstract float[]fromRGB(float[] rgbvalue) Transforms a color value assumed to be in the defaultCS_sRGBcolor space into thisColorSpace.static ColorSpacegetInstance(int cspace) Returns aColorSpacerepresenting one of the specific predefined color spaces.floatgetMaxValue(int component) Returns the maximum normalized color component value for the specified component.floatgetMinValue(int component) Returns the minimum normalized color component value for the specified component.getName(int component) Returns the name of the component given the component index.intReturns the number of components of this ColorSpace.intgetType()Returns the color space type of thisColorSpace(for exampleTYPE_RGB,TYPE_XYZ, ...).booleanReturns true if theColorSpaceisCS_sRGB.abstract float[]toCIEXYZ(float[] colorvalue) Transforms a color value assumed to be in thisColorSpaceinto theCS_CIEXYZconversion color space.abstract float[]toRGB(float[] colorvalue) Transforms a color value assumed to be in thisColorSpaceinto a value in the defaultCS_sRGBcolor space.
-
Field Details
-
TYPE_XYZ
-
TYPE_Lab
-
TYPE_Luv
-
TYPE_YCbCr
-
TYPE_Yxy
-
TYPE_RGB
-
TYPE_GRAY
-
TYPE_HSV
-
TYPE_HLS
-
TYPE_CMYK
-
TYPE_CMY
-
TYPE_2CLR
-
TYPE_3CLR
-
TYPE_4CLR
-
TYPE_5CLR
-
TYPE_6CLR
-
TYPE_7CLR
-
TYPE_8CLR
-
TYPE_9CLR
-
TYPE_ACLR
-
TYPE_BCLR
-
TYPE_CCLR
-
TYPE_DCLR
-
TYPE_ECLR
-
TYPE_FCLR
-
CS_sRGB
The built-in sRGB color space defined at http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html.- See Also:
-
CS_LINEAR_RGB
The built-in linear RGB color space. This space is based on the same RGB primaries asCS_sRGB, but has a linear tone reproduction curve.- See Also:
-
CS_CIEXYZ
The built-in CIEXYZ conversion color space defined above.- See Also:
-
CS_PYCC
-
CS_GRAY
-
-
Constructor Details
-
ColorSpace
protected ColorSpace(int type, int numComponents) Constructs aColorSpaceobject given a color space type and the number of components.- Parameters:
type- one of theColorSpacetype constantsnumComponents- the number of components in the color space
-
-
Method Details
-
getInstance
Returns aColorSpacerepresenting one of the specific predefined color spaces.- Parameters:
cspace- a specific color space identified by one of the predefined class constants (e.g.CS_sRGB,CS_LINEAR_RGB,CS_CIEXYZ,CS_GRAY, orCS_PYCC)- Returns:
- the requested
ColorSpaceobject - Throws:
IllegalArgumentException- ifcspaceis not one of the predefined color space types
-
isCS_sRGB
public boolean isCS_sRGB()Returns true if theColorSpaceisCS_sRGB.- Returns:
trueif this is aCS_sRGBcolor space,falseif it is not
-
toRGB
public abstract float[] toRGB(float[] colorvalue) Transforms a color value assumed to be in thisColorSpaceinto a value in the defaultCS_sRGBcolor space.This method transforms color values using algorithms designed to produce the best perceptual match between input and output colors. In order to do colorimetric conversion of color values, you should use the
toCIEXYZmethod of this color space to first convert from the input color space to the CS_CIEXYZ color space, and then use thefromCIEXYZmethod of theCS_sRGBcolor space to convert fromCS_CIEXYZto the output color space. SeetoCIEXYZandfromCIEXYZfor further information.- Parameters:
colorvalue- a float array with length of at least the number of components in thisColorSpace- Returns:
- a float array of length 3
- Throws:
ArrayIndexOutOfBoundsException- if array length is not at least the number of components in thisColorSpaceNullPointerException- ifcolorvalueisnull
-
fromRGB
public abstract float[] fromRGB(float[] rgbvalue) Transforms a color value assumed to be in the defaultCS_sRGBcolor space into thisColorSpace.This method transforms color values using algorithms designed to produce the best perceptual match between input and output colors. In order to do colorimetric conversion of color values, you should use the
toCIEXYZmethod of theCS_sRGBcolor space to first convert from the input color space to theCS_CIEXYZcolor space, and then use thefromCIEXYZmethod of this color space to convert fromCS_CIEXYZto the output color space. SeetoCIEXYZandfromCIEXYZfor further information.- Parameters:
rgbvalue- a float array with length of at least 3- Returns:
- a float array with length equal to the number of components in
this
ColorSpace - Throws:
ArrayIndexOutOfBoundsException- if array length is not at least 3NullPointerException- ifrgbvalueisnull
-
toCIEXYZ
public abstract float[] toCIEXYZ(float[] colorvalue) Transforms a color value assumed to be in thisColorSpaceinto theCS_CIEXYZconversion color space.This method transforms color values using relative colorimetry, as defined by the International Color Consortium standard. This means that the XYZ values returned by this method are represented relative to the D50 white point of the
CS_CIEXYZcolor space. This representation is useful in a two-step color conversion process in which colors are transformed from an input color space toCS_CIEXYZand then to an output color space. This representation is not the same as the XYZ values that would be measured from the given color value by a colorimeter. A further transformation is necessary to compute the XYZ values that would be measured using current CIE recommended practices. See thetoCIEXYZmethod ofICC_ColorSpacefor further information.- Parameters:
colorvalue- a float array with length of at least the number of components in thisColorSpace- Returns:
- a float array of length 3
- Throws:
ArrayIndexOutOfBoundsException- if array length is not at least the number of components in thisColorSpaceNullPointerException- ifcolorvalueisnull
-
fromCIEXYZ
public abstract float[] fromCIEXYZ(float[] colorvalue) Transforms a color value assumed to be in theCS_CIEXYZconversion color space into thisColorSpace.This method transforms color values using relative colorimetry, as defined by the International Color Consortium standard. This means that the XYZ argument values taken by this method are represented relative to the D50 white point of the
CS_CIEXYZcolor space. This representation is useful in a two-step color conversion process in which colors are transformed from an input color space toCS_CIEXYZand then to an output color space. The color values returned by this method are not those that would produce the XYZ value passed to the method when measured by a colorimeter. If you have XYZ values corresponding to measurements made using current CIE recommended practices, they must be converted to D50 relative values before being passed to this method. See thefromCIEXYZmethod ofICC_ColorSpacefor further information.- Parameters:
colorvalue- a float array with length of at least 3- Returns:
- a float array with length equal to the number of components in
this
ColorSpace - Throws:
ArrayIndexOutOfBoundsException- if array length is not at least 3NullPointerException- ifcolorvalueisnull
-
getType
public int getType()Returns the color space type of thisColorSpace(for exampleTYPE_RGB,TYPE_XYZ, ...). The type defines the number of components of the color space and the interpretation, e.g.TYPE_RGBidentifies 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.- Returns:
- the type constant that represents the type of this
ColorSpace
-
getNumComponents
public int getNumComponents()Returns the number of components of this ColorSpace.- Returns:
- the number of components in this
ColorSpace
-
getName
Returns the name of the component given the component index.- Parameters:
component- the component index- Returns:
- the name of the component at the specified index
- Throws:
IllegalArgumentException- ifcomponentis less than 0 or greater thannumComponents - 1
-
getMinValue
public float getMinValue(int component) Returns the minimum normalized color component value for the specified component. The default implementation in this abstract class returns 0.0 for all components. Subclasses should override this method if necessary.- Parameters:
component- the component index- Returns:
- the minimum normalized component value
- Throws:
IllegalArgumentException- if component is less than 0 or greater thannumComponents - 1- Since:
- 1.4
-
getMaxValue
public float getMaxValue(int component) Returns the maximum normalized color component value for the specified component. The default implementation in this abstract class returns 1.0 for all components. Subclasses should override this method if necessary.- Parameters:
component- the component index- Returns:
- the maximum normalized component value
- Throws:
IllegalArgumentException- if component is less than 0 or greater thannumComponents - 1- Since:
- 1.4
-