< prev index next >

src/java.desktop/share/classes/java/awt/color/ColorSpace.java

Print this page




 251 
 252     /**
 253      * The CIEXYZ conversion color space defined above.
 254      */
 255     @Native public static final int CS_CIEXYZ = 1001;
 256 
 257     /**
 258      * The Photo YCC conversion color space.
 259      */
 260     @Native public static final int CS_PYCC = 1002;
 261 
 262     /**
 263      * The built-in linear gray scale color space.
 264      */
 265     @Native public static final int CS_GRAY = 1003;
 266 
 267 
 268     /**
 269      * Constructs a ColorSpace object given a color space type
 270      * and the number of components.
 271      * @param type one of the <CODE>ColorSpace</CODE> type constants
 272      * @param numcomponents the number of components in the color space
 273      */
 274     protected ColorSpace (int type, int numcomponents) {
 275         this.type = type;
 276         this.numComponents = numcomponents;
 277     }
 278 
 279 
 280     /**
 281      * Returns a ColorSpace representing one of the specific
 282      * predefined color spaces.
 283      * @param colorspace a specific color space identified by one of
 284      *        the predefined class constants (e.g. CS_sRGB, CS_LINEAR_RGB,
 285      *        CS_CIEXYZ, CS_GRAY, or CS_PYCC)
 286      * @return the requested <CODE>ColorSpace</CODE> object
 287      */
 288     // NOTE: This method may be called by privileged threads.
 289     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
 290     public static ColorSpace getInstance (int colorspace)
 291     {
 292     ColorSpace    theColorSpace;
 293 
 294         switch (colorspace) {
 295         case CS_sRGB:
 296             synchronized(ColorSpace.class) {
 297                 if (sRGBspace == null) {
 298                     ICC_Profile theProfile = ICC_Profile.getInstance (CS_sRGB);
 299                     sRGBspace = new ICC_ColorSpace (theProfile);
 300                 }
 301 
 302                 theColorSpace = sRGBspace;
 303             }
 304             break;
 305 
 306         case CS_CIEXYZ:


 349                     LINEAR_RGBspace = new ICC_ColorSpace (theProfile);
 350                     /* to allow access from java.awt.ColorModel */
 351                     CMSManager.LINEAR_RGBspace = LINEAR_RGBspace;
 352                 }
 353 
 354                 theColorSpace = LINEAR_RGBspace;
 355             }
 356             break;
 357 
 358 
 359         default:
 360             throw new IllegalArgumentException ("Unknown color space");
 361         }
 362 
 363         return theColorSpace;
 364     }
 365 
 366 
 367     /**
 368      * Returns true if the ColorSpace is CS_sRGB.
 369      * @return <CODE>true</CODE> if this is a <CODE>CS_sRGB</CODE> color
 370      *         space, <code>false</code> if it is not
 371      */
 372     public boolean isCS_sRGB () {
 373         /* REMIND - make sure we know sRGBspace exists already */
 374         return (this == sRGBspace);
 375     }
 376 
 377     /**
 378      * Transforms a color value assumed to be in this ColorSpace
 379      * into a value in the default CS_sRGB color space.
 380      * <p>
 381      * This method transforms color values using algorithms designed
 382      * to produce the best perceptual match between input and output
 383      * colors.  In order to do colorimetric conversion of color values,
 384      * you should use the <code>toCIEXYZ</code>
 385      * method of this color space to first convert from the input
 386      * color space to the CS_CIEXYZ color space, and then use the
 387      * <code>fromCIEXYZ</code> method of the CS_sRGB color space to
 388      * convert from CS_CIEXYZ to the output color space.
 389      * See {@link #toCIEXYZ(float[]) toCIEXYZ} and
 390      * {@link #fromCIEXYZ(float[]) fromCIEXYZ} for further information.
 391      *
 392      * @param colorvalue a float array with length of at least the number
 393      *        of components in this ColorSpace
 394      * @return a float array of length 3
 395      * @throws ArrayIndexOutOfBoundsException if array length is not
 396      *         at least the number of components in this ColorSpace
 397      */
 398     public abstract float[] toRGB(float[] colorvalue);
 399 
 400 
 401     /**
 402      * Transforms a color value assumed to be in the default CS_sRGB
 403      * color space into this ColorSpace.
 404      * <p>
 405      * This method transforms color values using algorithms designed
 406      * to produce the best perceptual match between input and output
 407      * colors.  In order to do colorimetric conversion of color values,
 408      * you should use the <code>toCIEXYZ</code>
 409      * method of the CS_sRGB color space to first convert from the input
 410      * color space to the CS_CIEXYZ color space, and then use the
 411      * <code>fromCIEXYZ</code> method of this color space to
 412      * convert from CS_CIEXYZ to the output color space.
 413      * See {@link #toCIEXYZ(float[]) toCIEXYZ} and
 414      * {@link #fromCIEXYZ(float[]) fromCIEXYZ} for further information.
 415      *
 416      * @param rgbvalue a float array with length of at least 3
 417      * @return a float array with length equal to the number of
 418      *         components in this ColorSpace
 419      * @throws ArrayIndexOutOfBoundsException if array length is not
 420      *         at least 3
 421      */
 422     public abstract float[] fromRGB(float[] rgbvalue);
 423 
 424 
 425     /**
 426      * Transforms a color value assumed to be in this ColorSpace
 427      * into the CS_CIEXYZ conversion color space.
 428      * <p>
 429      * This method transforms color values using relative colorimetry,
 430      * as defined by the International Color Consortium standard.  This
 431      * means that the XYZ values returned by this method are represented
 432      * relative to the D50 white point of the CS_CIEXYZ color space.
 433      * This representation is useful in a two-step color conversion
 434      * process in which colors are transformed from an input color
 435      * space to CS_CIEXYZ and then to an output color space.  This
 436      * representation is not the same as the XYZ values that would
 437      * be measured from the given color value by a colorimeter.
 438      * A further transformation is necessary to compute the XYZ values
 439      * that would be measured using current CIE recommended practices.
 440      * See the {@link ICC_ColorSpace#toCIEXYZ(float[]) toCIEXYZ} method of
 441      * <code>ICC_ColorSpace</code> for further information.
 442      *
 443      * @param colorvalue a float array with length of at least the number
 444      *        of components in this ColorSpace
 445      * @return a float array of length 3
 446      * @throws ArrayIndexOutOfBoundsException if array length is not
 447      *         at least the number of components in this ColorSpace.
 448      */
 449     public abstract float[] toCIEXYZ(float[] colorvalue);
 450 
 451 
 452     /**
 453      * Transforms a color value assumed to be in the CS_CIEXYZ conversion
 454      * color space into this ColorSpace.
 455      * <p>
 456      * This method transforms color values using relative colorimetry,
 457      * as defined by the International Color Consortium standard.  This
 458      * means that the XYZ argument values taken by this method are represented
 459      * relative to the D50 white point of the CS_CIEXYZ color space.
 460      * This representation is useful in a two-step color conversion
 461      * process in which colors are transformed from an input color
 462      * space to CS_CIEXYZ and then to an output color space.  The color
 463      * values returned by this method are not those that would produce
 464      * the XYZ value passed to the method when measured by a colorimeter.
 465      * If you have XYZ values corresponding to measurements made using
 466      * current CIE recommended practices, they must be converted to D50
 467      * relative values before being passed to this method.
 468      * See the {@link ICC_ColorSpace#fromCIEXYZ(float[]) fromCIEXYZ} method of
 469      * <code>ICC_ColorSpace</code> for further information.
 470      *
 471      * @param colorvalue a float array with length of at least 3
 472      * @return a float array with length equal to the number of
 473      *         components in this ColorSpace
 474      * @throws ArrayIndexOutOfBoundsException if array length is not
 475      *         at least 3
 476      */
 477     public abstract float[] fromCIEXYZ(float[] colorvalue);
 478 
 479     /**
 480      * Returns the color space type of this ColorSpace (for example
 481      * TYPE_RGB, TYPE_XYZ, ...).  The type defines the
 482      * number of components of the color space and the interpretation,
 483      * e.g. TYPE_RGB identifies a color space with three components - red,
 484      * green, and blue.  It does not define the particular color
 485      * characteristics of the space, e.g. the chromaticities of the
 486      * primaries.
 487      *
 488      * @return the type constant that represents the type of this
 489      *         <CODE>ColorSpace</CODE>
 490      */
 491     public int getType() {
 492         return type;
 493     }
 494 
 495     /**
 496      * Returns the number of components of this ColorSpace.
 497      * @return The number of components in this <CODE>ColorSpace</CODE>.
 498      */
 499     public int getNumComponents() {
 500         return numComponents;
 501     }
 502 
 503     /**
 504      * Returns the name of the component given the component index.
 505      *
 506      * @param idx the component index
 507      * @return the name of the component at the specified index
 508      * @throws IllegalArgumentException if <code>idx</code> is
 509      *         less than 0 or greater than numComponents - 1
 510      */
 511     public String getName (int idx) {
 512         /* REMIND - handle common cases here */
 513         if ((idx < 0) || (idx > numComponents - 1)) {
 514             throw new IllegalArgumentException(
 515                 "Component index out of range: " + idx);
 516         }
 517 
 518         if (compName == null) {
 519             switch (type) {
 520                 case ColorSpace.TYPE_XYZ:
 521                     compName = new String[] {"X", "Y", "Z"};
 522                     break;
 523                 case ColorSpace.TYPE_Lab:
 524                     compName = new String[] {"L", "a", "b"};
 525                     break;
 526                 case ColorSpace.TYPE_Luv:
 527                     compName = new String[] {"L", "u", "v"};
 528                     break;




 251 
 252     /**
 253      * The CIEXYZ conversion color space defined above.
 254      */
 255     @Native public static final int CS_CIEXYZ = 1001;
 256 
 257     /**
 258      * The Photo YCC conversion color space.
 259      */
 260     @Native public static final int CS_PYCC = 1002;
 261 
 262     /**
 263      * The built-in linear gray scale color space.
 264      */
 265     @Native public static final int CS_GRAY = 1003;
 266 
 267 
 268     /**
 269      * Constructs a ColorSpace object given a color space type
 270      * and the number of components.
 271      * @param type one of the {@code ColorSpace} type constants
 272      * @param numcomponents the number of components in the color space
 273      */
 274     protected ColorSpace (int type, int numcomponents) {
 275         this.type = type;
 276         this.numComponents = numcomponents;
 277     }
 278 
 279 
 280     /**
 281      * Returns a ColorSpace representing one of the specific
 282      * predefined color spaces.
 283      * @param colorspace a specific color space identified by one of
 284      *        the predefined class constants (e.g. CS_sRGB, CS_LINEAR_RGB,
 285      *        CS_CIEXYZ, CS_GRAY, or CS_PYCC)
 286      * @return the requested {@code ColorSpace} object
 287      */
 288     // NOTE: This method may be called by privileged threads.
 289     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
 290     public static ColorSpace getInstance (int colorspace)
 291     {
 292     ColorSpace    theColorSpace;
 293 
 294         switch (colorspace) {
 295         case CS_sRGB:
 296             synchronized(ColorSpace.class) {
 297                 if (sRGBspace == null) {
 298                     ICC_Profile theProfile = ICC_Profile.getInstance (CS_sRGB);
 299                     sRGBspace = new ICC_ColorSpace (theProfile);
 300                 }
 301 
 302                 theColorSpace = sRGBspace;
 303             }
 304             break;
 305 
 306         case CS_CIEXYZ:


 349                     LINEAR_RGBspace = new ICC_ColorSpace (theProfile);
 350                     /* to allow access from java.awt.ColorModel */
 351                     CMSManager.LINEAR_RGBspace = LINEAR_RGBspace;
 352                 }
 353 
 354                 theColorSpace = LINEAR_RGBspace;
 355             }
 356             break;
 357 
 358 
 359         default:
 360             throw new IllegalArgumentException ("Unknown color space");
 361         }
 362 
 363         return theColorSpace;
 364     }
 365 
 366 
 367     /**
 368      * Returns true if the ColorSpace is CS_sRGB.
 369      * @return {@code true} if this is a {@code CS_sRGB} color
 370      *         space, {@code false} if it is not
 371      */
 372     public boolean isCS_sRGB () {
 373         /* REMIND - make sure we know sRGBspace exists already */
 374         return (this == sRGBspace);
 375     }
 376 
 377     /**
 378      * Transforms a color value assumed to be in this ColorSpace
 379      * into a value in the default CS_sRGB color space.
 380      * <p>
 381      * This method transforms color values using algorithms designed
 382      * to produce the best perceptual match between input and output
 383      * colors.  In order to do colorimetric conversion of color values,
 384      * you should use the {@code toCIEXYZ}
 385      * method of this color space to first convert from the input
 386      * color space to the CS_CIEXYZ color space, and then use the
 387      * {@code fromCIEXYZ} method of the CS_sRGB color space to
 388      * convert from CS_CIEXYZ to the output color space.
 389      * See {@link #toCIEXYZ(float[]) toCIEXYZ} and
 390      * {@link #fromCIEXYZ(float[]) fromCIEXYZ} for further information.
 391      *
 392      * @param colorvalue a float array with length of at least the number
 393      *        of components in this ColorSpace
 394      * @return a float array of length 3
 395      * @throws ArrayIndexOutOfBoundsException if array length is not
 396      *         at least the number of components in this ColorSpace
 397      */
 398     public abstract float[] toRGB(float[] colorvalue);
 399 
 400 
 401     /**
 402      * Transforms a color value assumed to be in the default CS_sRGB
 403      * color space into this ColorSpace.
 404      * <p>
 405      * This method transforms color values using algorithms designed
 406      * to produce the best perceptual match between input and output
 407      * colors.  In order to do colorimetric conversion of color values,
 408      * you should use the {@code toCIEXYZ}
 409      * method of the CS_sRGB color space to first convert from the input
 410      * color space to the CS_CIEXYZ color space, and then use the
 411      * {@code fromCIEXYZ} method of this color space to
 412      * convert from CS_CIEXYZ to the output color space.
 413      * See {@link #toCIEXYZ(float[]) toCIEXYZ} and
 414      * {@link #fromCIEXYZ(float[]) fromCIEXYZ} for further information.
 415      *
 416      * @param rgbvalue a float array with length of at least 3
 417      * @return a float array with length equal to the number of
 418      *         components in this ColorSpace
 419      * @throws ArrayIndexOutOfBoundsException if array length is not
 420      *         at least 3
 421      */
 422     public abstract float[] fromRGB(float[] rgbvalue);
 423 
 424 
 425     /**
 426      * Transforms a color value assumed to be in this ColorSpace
 427      * into the CS_CIEXYZ conversion color space.
 428      * <p>
 429      * This method transforms color values using relative colorimetry,
 430      * as defined by the International Color Consortium standard.  This
 431      * means that the XYZ values returned by this method are represented
 432      * relative to the D50 white point of the CS_CIEXYZ color space.
 433      * This representation is useful in a two-step color conversion
 434      * process in which colors are transformed from an input color
 435      * space to CS_CIEXYZ and then to an output color space.  This
 436      * representation is not the same as the XYZ values that would
 437      * be measured from the given color value by a colorimeter.
 438      * A further transformation is necessary to compute the XYZ values
 439      * that would be measured using current CIE recommended practices.
 440      * See the {@link ICC_ColorSpace#toCIEXYZ(float[]) toCIEXYZ} method of
 441      * {@code ICC_ColorSpace} for further information.
 442      *
 443      * @param colorvalue a float array with length of at least the number
 444      *        of components in this ColorSpace
 445      * @return a float array of length 3
 446      * @throws ArrayIndexOutOfBoundsException if array length is not
 447      *         at least the number of components in this ColorSpace.
 448      */
 449     public abstract float[] toCIEXYZ(float[] colorvalue);
 450 
 451 
 452     /**
 453      * Transforms a color value assumed to be in the CS_CIEXYZ conversion
 454      * color space into this ColorSpace.
 455      * <p>
 456      * This method transforms color values using relative colorimetry,
 457      * as defined by the International Color Consortium standard.  This
 458      * means that the XYZ argument values taken by this method are represented
 459      * relative to the D50 white point of the CS_CIEXYZ color space.
 460      * This representation is useful in a two-step color conversion
 461      * process in which colors are transformed from an input color
 462      * space to CS_CIEXYZ and then to an output color space.  The color
 463      * values returned by this method are not those that would produce
 464      * the XYZ value passed to the method when measured by a colorimeter.
 465      * If you have XYZ values corresponding to measurements made using
 466      * current CIE recommended practices, they must be converted to D50
 467      * relative values before being passed to this method.
 468      * See the {@link ICC_ColorSpace#fromCIEXYZ(float[]) fromCIEXYZ} method of
 469      * {@code ICC_ColorSpace} for further information.
 470      *
 471      * @param colorvalue a float array with length of at least 3
 472      * @return a float array with length equal to the number of
 473      *         components in this ColorSpace
 474      * @throws ArrayIndexOutOfBoundsException if array length is not
 475      *         at least 3
 476      */
 477     public abstract float[] fromCIEXYZ(float[] colorvalue);
 478 
 479     /**
 480      * Returns the color space type of this ColorSpace (for example
 481      * TYPE_RGB, TYPE_XYZ, ...).  The type defines the
 482      * number of components of the color space and the interpretation,
 483      * e.g. TYPE_RGB identifies a color space with three components - red,
 484      * green, and blue.  It does not define the particular color
 485      * characteristics of the space, e.g. the chromaticities of the
 486      * primaries.
 487      *
 488      * @return the type constant that represents the type of this
 489      *         {@code ColorSpace}
 490      */
 491     public int getType() {
 492         return type;
 493     }
 494 
 495     /**
 496      * Returns the number of components of this ColorSpace.
 497      * @return The number of components in this {@code ColorSpace}.
 498      */
 499     public int getNumComponents() {
 500         return numComponents;
 501     }
 502 
 503     /**
 504      * Returns the name of the component given the component index.
 505      *
 506      * @param idx the component index
 507      * @return the name of the component at the specified index
 508      * @throws IllegalArgumentException if {@code idx} is
 509      *         less than 0 or greater than numComponents - 1
 510      */
 511     public String getName (int idx) {
 512         /* REMIND - handle common cases here */
 513         if ((idx < 0) || (idx > numComponents - 1)) {
 514             throw new IllegalArgumentException(
 515                 "Component index out of range: " + idx);
 516         }
 517 
 518         if (compName == null) {
 519             switch (type) {
 520                 case ColorSpace.TYPE_XYZ:
 521                     compName = new String[] {"X", "Y", "Z"};
 522                     break;
 523                 case ColorSpace.TYPE_Lab:
 524                     compName = new String[] {"L", "a", "b"};
 525                     break;
 526                 case ColorSpace.TYPE_Luv:
 527                     compName = new String[] {"L", "u", "v"};
 528                     break;


< prev index next >