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

📄 indexcolormodel.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* IndexColorModel.java -- Java class for interpreting Pixel objects   Copyright (C) 1999, 2005 Free Software Foundation, Inc.This 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., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 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 gnu.java.awt.Buffers;import java.awt.color.ColorSpace;import java.math.BigInteger;/** * Color model similar to pseudo visual in X11. * <br><br> * This color model maps linear pixel values to actual RGB and alpha colors. * Thus, pixel values are indexes into the color map.  Each color component is * an 8-bit unsigned value. * <br><br> * The <code>IndexColorModel</code> supports a map of valid pixels, allowing  * the representation of holes in the the color map.  The valid map is  * represented as a {@link BigInteger} where each bit indicates the validity  * of the map entry with the same index. * <br><br> * Colors can have alpha components for transparency support.  If alpha * component values aren't given, color values are opaque.  The model also * supports a reserved pixel value to represent completely transparent colors, * no matter what the actual color component values are. * <br><br> * <code>IndexColorModel</code> supports anywhere from 1 to 16 bit index  * values.  The allowed transfer types are {@link DataBuffer#TYPE_BYTE} and  * {@link DataBuffer#TYPE_USHORT}. * * @author C. Brian Jones (cbj@gnu.org)  */public class IndexColorModel extends ColorModel{  private int map_size;  private boolean opaque;  // no alpha, but doesn't account for trans  private int trans = -1;  private int[] rgb;  private BigInteger validBits = BigInteger.ZERO;  /**   * Creates a new indexed color model for <code>size</code> color elements    * with no alpha component.  Each array must contain at least    * <code>size</code> elements.  For each array, the i-th color is described    * by reds[i], greens[i] and blues[i].    *   * @param bits the number of bits needed to represent <code>size</code>    *             colors.   * @param size the number of colors in the color map.   * @param reds the red component of all colors.   * @param greens the green component of all colors.   * @param blues the blue component of all colors.   *   * @throws IllegalArgumentException if <code>bits</code> &lt; 1 or    *         <code>bits</code> &gt; 16.   * @throws NullPointerException if any of the arrays is <code>null</code>.   * @throws ArrayIndexOutOfBoundsException if <code>size</code> is greater    *         than the length of the component arrays.   */  public IndexColorModel(int bits, int size, byte[] reds, byte[] greens,                         byte[] blues)  {    this(bits, size, reds, greens, blues, (byte[]) null);  }  /**   * Creates a new indexed color model for <code>size</code> color elements.   * Each array must contain at least <code>size</code> elements.  For each    * array, the i-th color is described by reds[i], greens[i] and blues[i].    * All the colors are opaque except for the transparent color.    *   * @param bits the number of bits needed to represent <code>size</code>    *             colors   * @param size the number of colors in the color map   * @param reds the red component of all colors   * @param greens the green component of all colors   * @param blues the blue component of all colors   * @param trans the index of the transparent color (use -1 for no    *              transparent color).   *    * @throws IllegalArgumentException if <code>bits</code> &lt; 1 or    *         <code>bits</code> &gt; 16.   * @throws NullPointerException if any of the arrays is <code>null</code>.   * @throws ArrayIndexOutOfBoundsException if <code>size</code> is greater    *         than the length of the component arrays.   */  public IndexColorModel(int bits, int size, byte[] reds, byte[] greens,                         byte[] blues, int trans)  {    super(bits, nArray(8, (0 <= trans && trans < size) ? 4 : 3),         ColorSpace.getInstance(ColorSpace.CS_sRGB),         (0 <= trans && trans < size),  // hasAlpha         false, OPAQUE,         Buffers.smallestAppropriateTransferType(bits));     if (bits < 1)       throw new IllegalArgumentException("bits < 1");    if (bits > 16)      throw new IllegalArgumentException("bits > 16");    if (size < 1)      throw new IllegalArgumentException("size < 1");    map_size = size;    if (0 <= trans && trans < size) {      this.trans = trans;      transparency = BITMASK;    }    rgb = new int[size];    for (int i = 0; i < size; i++)      {        rgb[i] = (0xff000000                  | ((reds[i] & 0xff) << 16)                  | ((greens[i] & 0xff) << 8)                  | (blues[i] & 0xff));      }    // Generate a bigint with 1's for every pixel    validBits = validBits.setBit(size).subtract(BigInteger.ONE);  }  /**   * Creates a new indexed color model for <code>size</code> color elements    * including alpha.  Each array must contain at least <code>size</code>    * elements.  For each array, the i-th color is described    * by reds[i], greens[i], blues[i] and alphas[i].    *   * @param bits the number of bits needed to represent <code>size</code>    *             colors.   * @param size the number of colors in the color map.   * @param reds the red component of all colors.   * @param greens the green component of all colors.   * @param blues the blue component of all colors.   * @param alphas the alpha component of all colors (<code>null</code>    *               permitted).   *   * @throws IllegalArgumentException if <code>bits</code> &lt; 1 or    *           <code>bits</code> &gt; 16.   * @throws NullPointerException if <code>reds</code>, <code>greens</code> or   *         <code>blues</code> is <code>null</code>.   * @throws ArrayIndexOutOfBoundsException if <code>size</code> is greater    *         than the length of the component arrays.   */  public IndexColorModel(int bits, int size, byte[] reds, byte[] greens,                         byte[] blues, byte[] alphas)  {    super(bits, nArray(8, (alphas == null ? 3 : 4)),         ColorSpace.getInstance(ColorSpace.CS_sRGB),         (alphas != null), false, TRANSLUCENT,         Buffers.smallestAppropriateTransferType(bits));     if (bits < 1)       throw new IllegalArgumentException("bits < 1");    if (bits > 16)      throw new IllegalArgumentException("bits > 16");    if (size < 1)      throw new IllegalArgumentException("size < 1");    map_size = size;    opaque = (alphas == null);    rgb = new int[size];    if (alphas == null)      {        for (int i = 0; i < size; i++)          {            rgb[i] = (0xff000000                      | ((reds[i] & 0xff) << 16)                      | ((greens[i] & 0xff) << 8)                      | (blues[i] & 0xff));          }        transparency = OPAQUE;      }    else      {	byte alphaZero = (byte) 0x00;        byte alphaOne = (byte) 0xFF;        for (int i = 0; i < size; i++)          {	    alphaZero = (byte) (alphaZero | alphas[i]);            alphaOne = (byte) (alphaOne & alphas[i]);            rgb[i] = ((alphas[i] & 0xff) << 24                      | ((reds[i] & 0xff) << 16)                      | ((greens[i] & 0xff) << 8)                      | (blues[i] & 0xff));          }        if ((alphaZero == (byte) 0x00) || (alphaOne == (byte) 0xFF))	  transparency = BITMASK;	else	  transparency = TRANSLUCENT;      }    // Generate a bigint with 1's for every pixel    validBits = validBits.setBit(size).subtract(BigInteger.ONE);  }  /**   * Creates a new indexed color model using the color components in    * <code>cmap</code>. If <code>hasAlpha</code> is <code>true</code> then   * <code>cmap</code> contains an alpha component after each of the red, green   * and blue components.   *   * @param bits the number of bits needed to represent <code>size</code>    *             colors   * @param size the number of colors in the color map   * @param cmap packed color components   * @param start the offset of the first color component in <code>cmap</code>   * @param hasAlpha <code>cmap</code> has alpha values   * @throws IllegalArgumentException if bits &lt; 1, bits &gt; 16, or size    *         &lt; 1.   * @throws NullPointerException if <code>cmap</code> is <code>null</code>.   */  public IndexColorModel(int bits, int size, byte[] cmap, int start,                          boolean hasAlpha)  {    this(bits, size, cmap, start, hasAlpha, -1);  }  /**   * Construct an IndexColorModel from an array of red, green, blue, and   * optional alpha components. The component values are interleaved as RGB(A).   *    * @param bits the number of bits needed to represent <code>size</code>    *             colors   * @param size the number of colors in the color map   * @param cmap interleaved color components   * @param start the offset of the first color component in <code>cmap</code>   * @param hasAlpha <code>cmap</code> has alpha values   * @param trans the index of the transparent color   * @throws IllegalArgumentException if bits &lt; 1, bits &gt; 16, or size   *         &lt; 1.   * @throws NullPointerException if <code>cmap</code> is <code>null</code>.   */  public IndexColorModel(int bits, int size, byte[] cmap, int start,                          boolean hasAlpha, int trans)  {    super(bits, nArray(8, hasAlpha || (0 <= trans && trans < size) ? 4 : 3),         ColorSpace.getInstance(ColorSpace.CS_sRGB),        hasAlpha || (0 <= trans && trans < size), false, OPAQUE,         Buffers.smallestAppropriateTransferType(bits));    if (bits < 1)      throw new IllegalArgumentException("bits < 1");    if (bits > 16)      throw new IllegalArgumentException("bits > 16");    if (size < 1)      throw new IllegalArgumentException("size < 1");    map_size = size;    opaque = !hasAlpha;    if (0 <= trans && trans < size)      this.trans = trans;    rgb = new int[size];    if (hasAlpha)    {      int alpha;      int alphaZero = 0x00;  // use to detect all zeros      int alphaOne = 0xff;   // use to detect all ones      for (int i = 0; i < size; i++) {	alpha = cmap[4 * i + 3 + start] & 0xff;          alphaZero = alphaZero | alpha;        alphaOne = alphaOne & alpha;        rgb[i] =	  ( alpha << 24	   // red	   | ((cmap[4 * i + start] & 0xff) << 16)	   // green	   | ((cmap[4 * i + 1 + start] & 0xff) << 8)	   // blue	   | (cmap[4 * i + 2 + start] & 0xff));      }      if (alphaZero == 0) 	transparency = BITMASK;      else if (alphaOne == 255)         transparency = (trans != -1 ? BITMASK : OPAQUE);      else	transparency = TRANSLUCENT;    }    else    {      for (int i = 0; i < size; i++)	rgb[i] = (0xff000000		  // red		  | ((cmap[3 * i + start] & 0xff) << 16)		  // green		  | ((cmap[3 * i + 1 + start] & 0xff) << 8)		  // blue		  | (cmap[3 * i + 2 + start] & 0xff));      if (trans != -1)	transparency = BITMASK;    }    // Generate a bigint with 1's for every pixel    validBits = validBits.setBit(size).subtract(BigInteger.ONE);  }  /**   * Construct an IndexColorModel from an array of <code>size</code> packed   * colors.  Each int element contains 8-bit red, green, blue, and optional   * alpha values packed in order.  If hasAlpha is false, then all the colors   * are opaque except for the transparent color.   *   * @param bits the number of bits needed to represent <code>size</code>    *             colors   * @param size the number of colors in the color map   * @param cmap packed color components   * @param start the offset of the first color component in <code>cmap</code>   * @param hasAlpha <code>cmap</code> has alpha values   * @param trans the index of the transparent color   * @param transferType {@link DataBuffer#TYPE_BYTE} or             {@link DataBuffer#TYPE_USHORT}.   * @throws IllegalArgumentException if bits &lt; 1, bits &gt; 16, or size   *         &lt; 1.   * @throws IllegalArgumentException if <code>transferType</code> is something   *         other than {@link DataBuffer#TYPE_BYTE} or    *         {@link DataBuffer#TYPE_USHORT}.   */  public IndexColorModel(int bits, int size, int[] cmap, int start,                          boolean hasAlpha, int trans, int transferType)  {    super(bits, 

⌨️ 快捷键说明

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