indexcolormodel.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 517 行 · 第 1/2 页
JAVA
517 行
/* IndexColorModel.java -- Java class for interpreting Pixel objects Copyright (C) 1999 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., 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.color.ColorSpace;import java.math.BigInteger;/** * Color model similar to pseudo visual in X11. * * 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. * * The IndexColorModel supports a map of valid pixels, allowing the * representation of holes in the the color map. The valid map is represented * as a BigInteger where each bit indicates the validity of the map entry with * the same index. * * 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. * * IndexColorModel supports anywhere from 1 to 16 bit index values. The * allowed transfer types are DataBuffer.TYPE_BYTE and DataBuffer.TYPE_USHORT. * * @author C. Brian Jones (cbj@gnu.org) */public class IndexColorModel extends ColorModel{ private int map_size; private boolean opaque; private int trans = -1; private int[] rgb; private BigInteger validBits = BigInteger.ZERO; /** * Each array much contain <code>size</code> elements. For each * array, the i-th color is described by reds[i], greens[i], * blues[i], alphas[i], unless alphas is not specified, 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 reds the red component of all colors * @param greens the green component of all colors * @param blues the blue component of all colors */ public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, byte[] blues) { this (bits, size, reds, greens, blues, (byte[]) null); } /** * Each array much contain <code>size</code> elements. For each * array, the i-th color is described by reds[i], greens[i], * blues[i], alphas[i], unless alphas is not specified, 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 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 */ public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, byte[] blues, int trans) { this (bits, size, reds, greens, blues, (byte[]) null); this.trans = trans; } /** * Each array much contain <code>size</code> elements. For each * array, the i-th color is described by reds[i], greens[i], * blues[i], alphas[i], unless alphas is not specified, 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 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 */ public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, byte[] blues, byte[] alphas) { // FIXME: This super() constructor should not be used since it can give // the wrong value for hasAlpha() which is final and cannot be overloaded super(bits); 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)); } } else { for (int i = 0; i < size; i++) { rgb[i] = ((alphas[i] & 0xff) << 24 | ((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); } /** * Each array much contain <code>size</code> elements. For each * array, the i-th color is described by reds[i], greens[i], * blues[i], alphas[i], unless alphas is not specified, 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 * @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. */ 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 < 1, bits > 16, or size < 1. */ public IndexColorModel (int bits, int size, byte[] cmap, int start, boolean hasAlpha, int trans) { super (bits); if (bits > 16) throw new IllegalArgumentException("bits > 16"); if (size < 1) throw new IllegalArgumentException("size < 1"); map_size = size; opaque = !hasAlpha; this.trans = trans; rgb = new int[size]; if (hasAlpha) { for (int i = 0; i < size; i++) rgb[i] = // alpha ((cmap[4 * i + 3 + start] & 0xff) << 24 // red | ((cmap[4 * i + start] & 0xff) << 16) // green | ((cmap[4 * i + 1 + start] & 0xff) << 8) // blue | (cmap[4 * i + 2 + start] & 0xff)); } 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)); } // 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 DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT * @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. * @throws IllegalArgumentException if transferType is something other than * TYPE_BYTE or TYPE_USHORT. */ public IndexColorModel (int bits, int size, int[] cmap, int start, boolean hasAlpha, int trans, int transferType) { super(bits * 4, // total bits, sRGB, four channels nArray(bits, 4), // bits for each channel ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB true, // has alpha false, // not premultiplied TRANSLUCENT, transferType); if (transferType != DataBuffer.TYPE_BYTE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?