src/java.desktop/share/classes/java/awt/image/ColorModel.java

Print this page




 386             throw new IllegalArgumentException("There must be at least "+
 387                                                "one component with > 0 "+
 388                                               "pixel bits.");
 389         }
 390 
 391         // Save this since we always need to check if it is the default CS
 392         if (cspace != ColorSpace.getInstance(ColorSpace.CS_sRGB)) {
 393             is_sRGB = false;
 394         }
 395 
 396         // Save the transfer type
 397         this.transferType = transferType;
 398     }
 399 
 400     /**
 401      * Returns whether or not alpha is supported in this
 402      * <code>ColorModel</code>.
 403      * @return <code>true</code> if alpha is supported in this
 404      * <code>ColorModel</code>; <code>false</code> otherwise.
 405      */
 406     final public boolean hasAlpha() {
 407         return supportsAlpha;
 408     }
 409 
 410     /**
 411      * Returns whether or not the alpha has been premultiplied in the
 412      * pixel values to be translated by this <code>ColorModel</code>.
 413      * If the boolean is <code>true</code>, this <code>ColorModel</code>
 414      * is to be used to interpret pixel values in which color and alpha
 415      * information are represented as separate spatial bands, and color
 416      * samples are assumed to have been multiplied by the
 417      * alpha sample.
 418      * @return <code>true</code> if the alpha values are premultiplied
 419      *          in the pixel values to be translated by this
 420      *          <code>ColorModel</code>; <code>false</code> otherwise.
 421      */
 422     final public boolean isAlphaPremultiplied() {
 423         return isAlphaPremultiplied;
 424     }
 425 
 426     /**
 427      * Returns the transfer type of this <code>ColorModel</code>.
 428      * The transfer type is the type of primitive array used to represent
 429      * pixel values as arrays.
 430      * @return the transfer type.
 431      * @since 1.3
 432      */
 433     final public int getTransferType() {
 434         return transferType;
 435     }
 436 
 437     /**
 438      * Returns the number of bits per pixel described by this
 439      * <code>ColorModel</code>.
 440      * @return the number of bits per pixel.
 441      */
 442     public int getPixelSize() {
 443         return pixel_bits;
 444     }
 445 
 446     /**
 447      * Returns the number of bits for the specified color/alpha component.
 448      * Color components are indexed in the order specified by the
 449      * <code>ColorSpace</code>.  Typically, this order reflects the name
 450      * of the color space type. For example, for TYPE_RGB, index 0
 451      * corresponds to red, index 1 to green, and index 2
 452      * to blue.  If this <code>ColorModel</code> supports alpha, the alpha
 453      * component corresponds to the index following the last color


1495                  (isAlphaPremultiplied ? 4 : 5) +
1496                  pixel_bits * 6 +
1497                  transparency * 7 +
1498                  numComponents * 8;
1499 
1500         if (nBits != null) {
1501             for (int i = 0; i < numComponents; i++) {
1502                 result = result + nBits[i] * (i + 9);
1503             }
1504         }
1505 
1506         return result;
1507     }
1508 
1509     /**
1510      * Returns the <code>ColorSpace</code> associated with this
1511      * <code>ColorModel</code>.
1512      * @return the <code>ColorSpace</code> of this
1513      * <code>ColorModel</code>.
1514      */
1515     final public ColorSpace getColorSpace() {
1516         return colorSpace;
1517     }
1518 
1519     /**
1520      * Forces the raster data to match the state specified in the
1521      * <code>isAlphaPremultiplied</code> variable, assuming the data is
1522      * currently correctly described by this <code>ColorModel</code>.  It
1523      * may multiply or divide the color raster data by alpha, or do
1524      * nothing if the data is in the correct state.  If the data needs to
1525      * be coerced, this method will also return an instance of this
1526      * <code>ColorModel</code> with the <code>isAlphaPremultiplied</code>
1527      * flag set appropriately.  This method will throw a
1528      * <code>UnsupportedOperationException</code> if it is not supported
1529      * by this <code>ColorModel</code>.
1530      * Since <code>ColorModel</code> is an abstract class,
1531      * any instance is an instance of a subclass.  Subclasses must
1532      * override this method since the implementation in this abstract
1533      * class throws an <code>UnsupportedOperationException</code>.
1534      * @param raster the <code>WritableRaster</code> data
1535      * @param isAlphaPremultiplied <code>true</code> if the alpha is




 386             throw new IllegalArgumentException("There must be at least "+
 387                                                "one component with > 0 "+
 388                                               "pixel bits.");
 389         }
 390 
 391         // Save this since we always need to check if it is the default CS
 392         if (cspace != ColorSpace.getInstance(ColorSpace.CS_sRGB)) {
 393             is_sRGB = false;
 394         }
 395 
 396         // Save the transfer type
 397         this.transferType = transferType;
 398     }
 399 
 400     /**
 401      * Returns whether or not alpha is supported in this
 402      * <code>ColorModel</code>.
 403      * @return <code>true</code> if alpha is supported in this
 404      * <code>ColorModel</code>; <code>false</code> otherwise.
 405      */
 406     public final boolean hasAlpha() {
 407         return supportsAlpha;
 408     }
 409 
 410     /**
 411      * Returns whether or not the alpha has been premultiplied in the
 412      * pixel values to be translated by this <code>ColorModel</code>.
 413      * If the boolean is <code>true</code>, this <code>ColorModel</code>
 414      * is to be used to interpret pixel values in which color and alpha
 415      * information are represented as separate spatial bands, and color
 416      * samples are assumed to have been multiplied by the
 417      * alpha sample.
 418      * @return <code>true</code> if the alpha values are premultiplied
 419      *          in the pixel values to be translated by this
 420      *          <code>ColorModel</code>; <code>false</code> otherwise.
 421      */
 422     public final boolean isAlphaPremultiplied() {
 423         return isAlphaPremultiplied;
 424     }
 425 
 426     /**
 427      * Returns the transfer type of this <code>ColorModel</code>.
 428      * The transfer type is the type of primitive array used to represent
 429      * pixel values as arrays.
 430      * @return the transfer type.
 431      * @since 1.3
 432      */
 433     public final int getTransferType() {
 434         return transferType;
 435     }
 436 
 437     /**
 438      * Returns the number of bits per pixel described by this
 439      * <code>ColorModel</code>.
 440      * @return the number of bits per pixel.
 441      */
 442     public int getPixelSize() {
 443         return pixel_bits;
 444     }
 445 
 446     /**
 447      * Returns the number of bits for the specified color/alpha component.
 448      * Color components are indexed in the order specified by the
 449      * <code>ColorSpace</code>.  Typically, this order reflects the name
 450      * of the color space type. For example, for TYPE_RGB, index 0
 451      * corresponds to red, index 1 to green, and index 2
 452      * to blue.  If this <code>ColorModel</code> supports alpha, the alpha
 453      * component corresponds to the index following the last color


1495                  (isAlphaPremultiplied ? 4 : 5) +
1496                  pixel_bits * 6 +
1497                  transparency * 7 +
1498                  numComponents * 8;
1499 
1500         if (nBits != null) {
1501             for (int i = 0; i < numComponents; i++) {
1502                 result = result + nBits[i] * (i + 9);
1503             }
1504         }
1505 
1506         return result;
1507     }
1508 
1509     /**
1510      * Returns the <code>ColorSpace</code> associated with this
1511      * <code>ColorModel</code>.
1512      * @return the <code>ColorSpace</code> of this
1513      * <code>ColorModel</code>.
1514      */
1515     public final ColorSpace getColorSpace() {
1516         return colorSpace;
1517     }
1518 
1519     /**
1520      * Forces the raster data to match the state specified in the
1521      * <code>isAlphaPremultiplied</code> variable, assuming the data is
1522      * currently correctly described by this <code>ColorModel</code>.  It
1523      * may multiply or divide the color raster data by alpha, or do
1524      * nothing if the data is in the correct state.  If the data needs to
1525      * be coerced, this method will also return an instance of this
1526      * <code>ColorModel</code> with the <code>isAlphaPremultiplied</code>
1527      * flag set appropriately.  This method will throw a
1528      * <code>UnsupportedOperationException</code> if it is not supported
1529      * by this <code>ColorModel</code>.
1530      * Since <code>ColorModel</code> is an abstract class,
1531      * any instance is an instance of a subclass.  Subclasses must
1532      * override this method since the implementation in this abstract
1533      * class throws an <code>UnsupportedOperationException</code>.
1534      * @param raster the <code>WritableRaster</code> data
1535      * @param isAlphaPremultiplied <code>true</code> if the alpha is