⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colormodel.java

📁 this gcc-g++-3.3.1.tar.gz is a source file of gcc, you can learn more about gcc through this codes f
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 1999, 2000, 2002  Free Software FoundationThis file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.awt.image;import java.awt.Point;import java.awt.Transparency;import java.awt.color.ColorSpace;import gnu.java.awt.Buffers;/** * A color model operates with colors in several formats: * * <ul> * <li>normalized: component samples are in range [0.0, 1.0].</li> * * <li>color model pixel value: all the color component samples for a * sigle pixel packed/encoded in a way natural for the color * model.</li> * * <li>color model pixel int value: only makes sense if the natural * encoding of a single pixel can fit in a single int value.</li> * * <li>array of transferType containing a single pixel: the pixel is * encoded in the natural way of the color model, taking up as many * array elements as needed.</li> * * <li>sRGB pixel int value: a pixel in sRGB color space, encoded in * default 0xAARRGGBB format, assumed not alpha premultiplied.</li> *  * <li>single [0, 255] scaled int samples from default sRGB color * space. These are always assumed to be alpha non-premultiplied.</li> * * <li>arrays of unnormalized component samples of single pixel: these * samples are scaled and multiplied according to the color model, but * is otherwise not packed or encoded. Each element of the array is one * separate component sample. The color model only operate on the * components from one pixel at a time, but using offsets, allows * manipulation of arrays that contain the components of more than one * pixel.</li> * * </ul> * * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> * @author C. Brian Jones (cbj@gnu.org)  */public abstract class ColorModel implements Transparency{  protected int pixel_bits;  protected int transferType;  int[] bits;  ColorSpace cspace;  int transparency;  boolean hasAlpha;  boolean isAlphaPremultiplied;      static int[] nArray(int value, int times)  {    int[] array = new int[times];    java.util.Arrays.fill(array, value);    return array;  }  static byte[] nArray(byte value, int times)  {    byte[] array = new byte[times];    java.util.Arrays.fill(array, value);    return array;  }   /**   * Constructs the default color model.  The default color model    * can be obtained by calling <code>getRGBdefault</code> of this   * class.   * @param b the number of bits wide used for bit size of pixel values   */  public ColorModel(int bits)  {    this(bits * 4, // total bits, sRGB, four channels	 nArray(bits, 4), // bits for each channel	 null, // FIXME: should be sRGB	 true, // has alpha	 false, // not premultiplied	 TRANSLUCENT,	 Buffers.smallestAppropriateTransferType(bits * 4));  }  /**   * Constructs a ColorModel that translates pixel values to   * color/alpha components.   *   * @exception IllegalArgumentException If the length of the bit array is less   * than the number of color or alpha components in this ColorModel, or if the   * transparency is not a valid value, or if the sum of the number of bits in   * bits is less than 1 or if any of the elements in bits is less than 0.   */  protected ColorModel(int pixel_bits, int[] bits, ColorSpace cspace,		       boolean hasAlpha, boolean isAlphaPremultiplied,		       int transparency, int transferType)  {    int bits_sum = 0;    for (int i = 0; i < bits.length; i++)      {        if (bits [i] < 0)          throw new IllegalArgumentException ();        bits_sum |= bits [i];      }        if ((bits.length < cspace.numComponents)        || (bits_sum < 1))      throw new IllegalArgumentException ();    this.pixel_bits = pixel_bits;    this.bits = bits;    this.cspace = cspace;    this.hasAlpha = hasAlpha;    this.isAlphaPremultiplied = isAlphaPremultiplied;    this.transparency = transparency;    this.transferType = transferType;  }  /**   * Returns the default color model which in Sun's case is an instance   * of <code>DirectColorModel</code>.   */  public static ColorModel getRGBdefault()  {    return new DirectColorModel(8, 0xff0000, 0xff00, 0xff, 0xff000000);  }  public final boolean hasAlpha()  {    return hasAlpha;  }  public final boolean isAlphaPremultiplied()  {    return isAlphaPremultiplied;  }  /**   * Get get number of bits wide used for the bit size of pixel values   */  public int getPixelSize()  {    return pixel_bits;  }      public int getComponentSize(int componentIdx)  {    return bits[componentIdx];  }      public int[] getComponentSize()  {    return bits;  }  public int getTransparency()  {    return transparency;  }  public int getNumComponents()  {    return getNumColorComponents() + (hasAlpha ? 1 : 0);  }  public int getNumColorComponents()  {    return cspace.getNumComponents();  }  /**   * Converts pixel value to sRGB and extract red int sample scaled   * to range [0, 255].   *   * @param pixel pixel value that will be interpreted according to   * the color model, (assumed alpha premultiplied if color model says   * so.)   *   * @return red sample scaled to range [0, 255], from default color   * space sRGB, alpha non-premultiplied.   */  public abstract int getRed(int pixel);  /**   * Converts pixel value to sRGB and extract green int sample   * scaled to range [0, 255].   *   * @see #getRed(int)   */    public abstract int getGreen(int pixel);      /**   * Converts pixel value to sRGB and extract blue int sample   * scaled to range [0, 255].   *   * @see #getRed(int)   */  public abstract int getBlue(int pixel);  /**   * Extract alpha int sample from pixel value, scaled to [0, 255].   *   * @param pixel pixel value that will be interpreted according to   * the color model.   *   * @return alpha sample, scaled to range [0, 255].   */  public abstract int getAlpha(int pixel);  /**   * Converts a pixel int value of the color space of the color   * model to a sRGB pixel int value.   *   * This method is typically overriden in subclasses to provide a   * more efficient implementation.   *    * @param pixel pixel value that will be interpreted according to   * the color model.   *   * @return a pixel in sRGB color space, encoded in default   * 0xAARRGGBB format.  */  public int getRGB(int pixel)  {    return       ((getAlpha(pixel) & 0xff) << 24) |      ((  getRed(pixel) & 0xff) << 16) |      ((getGreen(pixel) & 0xff) <<  8) |      (( getBlue(pixel) & 0xff) <<  0);  }    /**   * In this color model we know that the whole pixel value will   * always be contained within the first element of the pixel   * array.   */  final int getPixelFromArray(Object inData) {    DataBuffer data =      Buffers.createBufferFromData(transferType, inData, 1);    Object da = Buffers.getData(data);    return data.getElem(0);  }  /**    * Converts pixel in the given array to sRGB and extract blue int   * sample scaled to range [0-255].   *   * This method is typically overriden in subclasses to provide a   * more efficient implementation.   *    * @param array of transferType containing a single pixel.  The   * pixel should be encoded in the natural way of the color model.   */  public int getRed(Object inData)  {    return getRed(getPixelFromArray(inData));  }  /**   * @see #getRed(Object)   */  public int getGreen(Object inData)  {    return getGreen(getPixelFromArray(inData));  }  /**   * @see #getRed(Object)   */  public int getBlue(Object inData) {    return getBlue(getPixelFromArray(inData));  }  /**   * @see #getRed(Object)   */  public int getAlpha(Object inData) {    return getAlpha(getPixelFromArray(inData));  }  /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -