📄 colorspace.java
字号:
* @param colorspace a specific color space identified by one of * the predefined class constants (e.g. CS_sRGB, CS_LINEAR_RGB, * CS_CIEXYZ, CS_GRAY, or CS_PYCC) * @return The requested <CODE>ColorSpace</CODE> object. */ // NOTE: This method may be called by privileged threads. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! public static ColorSpace getInstance (int colorspace) { ColorSpace theColorSpace; switch (colorspace) { case CS_sRGB: if (sRGBspace == null) { ICC_Profile theProfile = ICC_Profile.getInstance (CS_sRGB); sRGBspace = new ICC_ColorSpace (theProfile); } theColorSpace = sRGBspace; break; case CS_CIEXYZ: if (XYZspace == null) { ICC_Profile theProfile = ICC_Profile.getInstance (CS_CIEXYZ); XYZspace = new ICC_ColorSpace (theProfile); } theColorSpace = XYZspace; break; case CS_PYCC: if (PYCCspace == null) { ICC_Profile theProfile = ICC_Profile.getInstance (CS_PYCC); PYCCspace = new ICC_ColorSpace (theProfile); } theColorSpace = PYCCspace; break; case CS_GRAY: if (GRAYspace == null) { ICC_Profile theProfile = ICC_Profile.getInstance (CS_GRAY); GRAYspace = new ICC_ColorSpace (theProfile); CMM.GRAYspace = GRAYspace; // to allow access from // java.awt.ColorModel } theColorSpace = GRAYspace; break; case CS_LINEAR_RGB: if (LINEAR_RGBspace == null) { ICC_Profile theProfile = ICC_Profile.getInstance(CS_LINEAR_RGB); LINEAR_RGBspace = new ICC_ColorSpace (theProfile); CMM.LINEAR_RGBspace = LINEAR_RGBspace; // to allow access from // java.awt.ColorModel } theColorSpace = LINEAR_RGBspace; break; default: throw new IllegalArgumentException ("Unknown color space"); } return theColorSpace; } /** * Returns true if the ColorSpace is CS_sRGB. * @return <CODE>true</CODE> if this is a <CODE>CS_sRGB</CODE> color * space, <code>false</code> if it is not. */ public boolean isCS_sRGB () { /* REMIND - make sure we know sRGBspace exists already */ return (this == sRGBspace); } /** * Transforms a color value assumed to be in this ColorSpace * into a value in the default CS_sRGB color space. * <p> * 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 <code>toCIEXYZ</code> * method of this color space to first convert from the input * color space to the CS_CIEXYZ color space, and then use the * <code>fromCIEXYZ</code> method of the CS_sRGB color space to * convert from CS_CIEXYZ to the output color space. * See {@link #toCIEXYZ(float[]) toCIEXYZ} and * {@link #fromCIEXYZ(float[]) fromCIEXYZ} for further information. * <p> * @param colorvalue a float array with length of at least the number * of components in this ColorSpace * @return a float array of length 3 * @throws ArrayIndexOutOfBoundsException if array length is not * at least the number of components in this ColorSpace. */ public abstract float[] toRGB(float[] colorvalue); /** * Transforms a color value assumed to be in the default CS_sRGB * color space into this ColorSpace. * <p> * 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 <code>toCIEXYZ</code> * method of the CS_sRGB color space to first convert from the input * color space to the CS_CIEXYZ color space, and then use the * <code>fromCIEXYZ</code> method of this color space to * convert from CS_CIEXYZ to the output color space. * See {@link #toCIEXYZ(float[]) toCIEXYZ} and * {@link #fromCIEXYZ(float[]) fromCIEXYZ} for further information. * <p> * @param rgbvalue a float array with length of at least 3 * @return a float array with length equal to the number of * components in this ColorSpace * @throws ArrayIndexOutOfBoundsException if array length is not * at least 3. */ public abstract float[] fromRGB(float[] rgbvalue); /** * Transforms a color value assumed to be in this ColorSpace * into the CS_CIEXYZ conversion color space. * <p> * 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_CIEXYZ color space. * This representation is useful in a two-step color conversion * process in which colors are transformed from an input color * space to CS_CIEXYZ and 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 the {@link ICC_ColorSpace#toCIEXYZ(float[]) toCIEXYZ} method of * <code>ICC_ColorSpace</code> for further information. * <p> * @param colorvalue a float array with length of at least the number * of components in this ColorSpace * @return a float array of length 3 * @throws ArrayIndexOutOfBoundsException if array length is not * at least the number of components in this ColorSpace. */ public abstract float[] toCIEXYZ(float[] colorvalue); /** * Transforms a color value assumed to be in the CS_CIEXYZ conversion * color space into this ColorSpace. * <p> * 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_CIEXYZ color space. * This representation is useful in a two-step color conversion * process in which colors are transformed from an input color * space to CS_CIEXYZ and 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 the {@link ICC_ColorSpace#fromCIEXYZ(float[]) fromCIEXYZ} method of * <code>ICC_ColorSpace</code> for further information. * <p> * @param colorvalue a float array with length of at least 3 * @return a float array with length equal to the number of * components in this ColorSpace * @throws ArrayIndexOutOfBoundsException if array length is not * at least 3. */ public abstract float[] fromCIEXYZ(float[] colorvalue); /** * Returns the color space type of this ColorSpace (for example * TYPE_RGB, TYPE_XYZ, ...). The type defines the * number of components of the color space and the interpretation, * e.g. 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. * @return The type constant that represents the type of this * <CODE>ColorSpace</CODE>. */ public int getType() { return type; } /** * Returns the number of components of this ColorSpace. * @return The number of components in this <CODE>ColorSpace</CODE>. */ public int getNumComponents() { return numComponents; } /** * Returns the name of the component given the component index. * @param idx The component index. * @return The name of the component at the specified index. */ public String getName (int idx) { /* REMIND - handle common cases here */ return new String("Unnamed color component("+idx+")"); } /** * 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. * @param component The component index. * @return The minimum normalized component value. * @throws IllegalArgumentException if component is less than 0 or * greater than numComponents - 1. * @since 1.4 */ public float getMinValue(int component) { if ((component < 0) || (component > numComponents - 1)) { throw new IllegalArgumentException( "Component index out of range: + component"); } return 0.0f; } /** * 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. * @param component The component index. * @return The maximum normalized component value. * @throws IllegalArgumentException if component is less than 0 or * greater than numComponents - 1. * @since 1.4 */ public float getMaxValue(int component) { if ((component < 0) || (component > numComponents - 1)) { throw new IllegalArgumentException( "Component index out of range: + component"); } return 1.0f; } /* Returns true if cspace is the XYZspace. */ static boolean isCS_CIEXYZ(ColorSpace cspace) { return (cspace == XYZspace); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -