home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / ColorModel.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  124 lines

  1. /*
  2.  * @(#)ColorModel.java    1.12 96/11/23
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.awt.image;
  24.  
  25. /**
  26.  * A class that encapsulates the methods for translating from pixel values
  27.  * to alpha, red, green, and blue color components for an image.  This
  28.  * class is abstract.
  29.  *
  30.  * @see IndexColorModel
  31.  * @see DirectColorModel
  32.  *
  33.  * @version    1.12 11/23/96
  34.  * @author     Jim Graham
  35.  */
  36. public abstract class ColorModel {
  37.     private int pData;        // Placeholder for data for native functions
  38.  
  39.     protected int pixel_bits;
  40.  
  41.     private static ColorModel RGBdefault;
  42.  
  43.     /**
  44.      * Return a ColorModel which describes the default format for
  45.      * integer RGB values used throughout the AWT image interfaces.
  46.      * The format for the RGB values is an integer with 8 bits
  47.      * each of alpha, red, green, and blue color components ordered
  48.      * correspondingly from the most significant byte to the least
  49.      * significant byte, as in:  0xAARRGGBB
  50.      */
  51.     public static ColorModel getRGBdefault() {
  52.     if (RGBdefault == null) {
  53.         RGBdefault = new DirectColorModel(32,
  54.                           0x00ff0000,    // Red
  55.                           0x0000ff00,    // Green
  56.                           0x000000ff,    // Blue
  57.                           0xff000000    // Alpha
  58.                           );
  59.     }
  60.     return RGBdefault;
  61.     }
  62.  
  63.     /**
  64.      * Constructs a ColorModel which describes a pixel of the specified
  65.      * number of bits.
  66.      */
  67.     public ColorModel(int bits) {
  68.     pixel_bits = bits;
  69.     }
  70.  
  71.     /**
  72.      * Returns the number of bits per pixel described by this ColorModel.
  73.      */
  74.     public int getPixelSize() {
  75.     return pixel_bits;
  76.     }
  77.  
  78.     /**
  79.      * The subclass must provide a function which provides the red
  80.      * color compoment for the specified pixel.
  81.      * @return        The red color component ranging from 0 to 255
  82.      */
  83.     public abstract int getRed(int pixel);
  84.  
  85.     /**
  86.      * The subclass must provide a function which provides the green
  87.      * color compoment for the specified pixel.
  88.      * @return        The green color component ranging from 0 to 255
  89.      */
  90.     public abstract int getGreen(int pixel);
  91.  
  92.     /**
  93.      * The subclass must provide a function which provides the blue
  94.      * color compoment for the specified pixel.
  95.      * @return        The blue color component ranging from 0 to 255
  96.      */
  97.     public abstract int getBlue(int pixel);
  98.  
  99.     /**
  100.      * The subclass must provide a function which provides the alpha
  101.      * color compoment for the specified pixel.
  102.      * @return        The alpha transparency value ranging from 0 to 255
  103.      */
  104.     public abstract int getAlpha(int pixel);
  105.  
  106.     /**
  107.      * Returns the color of the pixel in the default RGB color model.
  108.      * @see ColorModel#getRGBdefault
  109.      */
  110.     public int getRGB(int pixel) {
  111.     return (getAlpha(pixel) << 24)
  112.         | (getRed(pixel) << 16)
  113.         | (getGreen(pixel) << 8)
  114.         | (getBlue(pixel) << 0);
  115.     }
  116.  
  117.     /* Throw away the compiled data stored in pData */
  118.     private native void deletepData();
  119.  
  120.     public void finalize() {
  121.     deletepData();
  122.     }
  123. }
  124.