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

📄 componentcolormodel.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)ComponentColorModel.java	1.66 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.awt.image;import java.awt.color.ColorSpace;import java.awt.color.ICC_ColorSpace;/** * A <CODE>ColorModel</CODE> class that works with pixel values that  * represent color and alpha information as separate samples and that  * store each sample in a separate data element.  This class can be  * used with an arbitrary <CODE>ColorSpace</CODE>.  The number of  * color samples in the pixel values must be same as the number of  * color components in the <CODE>ColorSpace</CODE>. There may be a  * single alpha sample.   * <p> * For those methods that use * a primitive array pixel representation of type <CODE>transferType</CODE>, * the array length is the same as the number of color and alpha samples. * Color samples are stored first in the array followed by the alpha * sample, if present.  The order of the color samples is specified * by the <CODE>ColorSpace</CODE>.  Typically, this order reflects the  * name of the color space type. For example, for <CODE>TYPE_RGB</CODE>,  * index 0 corresponds to red, index 1 to green, and index 2 to blue.   * <p> * The translation from pixel sample values to color/alpha components for * display or processing purposes is based on a one-to-one correspondence of * samples to components. * Depending on the transfer type used to create an instance of * <code>ComponentColorModel</code>, the pixel sample values * represented by that instance may be signed or unsigned and may * be of integral type or float or double (see below for details). * The translation from sample values to normalized color/alpha components * must follow certain rules.  For float and double samples, the translation * is an identity, i.e. normalized component values are equal to the * corresponding sample values.  For integral samples, the translation * should be only a simple scale and offset, where the scale and offset * constants may be different for each component.  The result of * applying the scale and offset constants is a set of color/alpha * component values, which are guaranteed to fall within a certain * range.  Typically, the range for a color component will be the range * defined by the <code>getMinValue</code> and <code>getMaxValue</code> * methods of the <code>ColorSpace</code> class.  The range for an * alpha component should be 0.0 to 1.0. * <p> * Instances of <code>ComponentColorModel</code> created with transfer types * <CODE>DataBuffer.TYPE_BYTE</CODE>, <CODE>DataBuffer.TYPE_USHORT</CODE>, * and <CODE>DataBuffer.TYPE_INT</CODE> have pixel sample values which * are treated as unsigned integral values. * The number of bits in a color or alpha sample of a pixel value might not * be the same as the number of bits for the corresponding color or alpha * sample passed to the * <code>ComponentColorModel(ColorSpace, int[], boolean, boolean, int, int)</code> * constructor.  In * that case, this class assumes that the least significant n bits of a sample * value hold the component value, where n is the number of significant bits  * for the component passed to the constructor.  It also assumes that  * any higher-order bits in a sample value are zero.  Thus, sample values * range from 0 to 2<sup>n</sup> - 1.  This class maps these sample values * to normalized color component values such that 0 maps to the value * obtained from the <code>ColorSpace's</code> <code>getMinValue</code> * method for each component and 2<sup>n</sup> - 1 maps to the value * obtained from <code>getMaxValue</code>.  To create a * <code>ComponentColorModel</code> with a different color sample mapping * requires subclassing this class and overriding the * <code>getNormalizedComponents(Object, float[], int)</code> method. * The mapping for an alpha sample always maps 0 to 0.0 and * 2<sup>n</sup> - 1 to 1.0. * <p> * For instances with unsigned sample values, * the unnormalized color/alpha component representation is only * supported if two conditions hold.  First, sample value value 0 must * map to normalized component value 0.0 and sample value 2<sup>n</sup> - 1 * to 1.0.  Second the min/max range of all color components of the * <code>ColorSpace</code> must be 0.0 to 1.0.  In this case, the * component representation is the n least * significant bits of the corresponding sample.  Thus each component is * an unsigned integral value between 0 and 2<sup>n</sup> - 1, where * n is the number of significant bits for a particular component. * If these conditions are not met, any method taking an unnormalized * component argument will throw an <code>IllegalArgumentException</code>. * <p> * Instances of <code>ComponentColorModel</code> created with transfer types * <CODE>DataBuffer.TYPE_SHORT</CODE>, <CODE>DataBuffer.TYPE_FLOAT</CODE>, and * <CODE>DataBuffer.TYPE_DOUBLE</CODE> have pixel sample values which * are treated as signed short, float, or double values. * Such instances do not support the unnormalized color/alpha component * representation, so any methods taking such a representation as an argument * will throw an <code>IllegalArgumentException</code> when called on one * of these instances.  The normalized component values of instances * of this class have a range which depends on the transfer * type as follows: for float samples, the full range of the float data * type; for double samples, the full range of the float data type * (resulting from casting double to float); for short samples, * from approximately -maxVal to +maxVal, where maxVal is the per * component maximum value for the <code>ColorSpace</code> * (-32767 maps to -maxVal, 0 maps to 0.0, and 32767 maps * to +maxVal).  A subclass may override the scaling for short sample * values to normalized component values by overriding the * <code>getNormalizedComponents(Object, float[], int)</code> method. * For float and double samples, the normalized component values are * taken to be equal to the corresponding sample values, and subclasses * should not attempt to add any non-identity scaling for these transfer * types. * <p> * Instances of <code>ComponentColorModel</code> created with transfer types * <CODE>DataBuffer.TYPE_SHORT</CODE>, <CODE>DataBuffer.TYPE_FLOAT</CODE>, and * <CODE>DataBuffer.TYPE_DOUBLE</CODE> * use all the bits of all sample values.  Thus all color/alpha components * have 16 bits when using <CODE>DataBuffer.TYPE_SHORT</CODE>, 32 bits when * using <CODE>DataBuffer.TYPE_FLOAT</CODE>, and 64 bits when using * <CODE>DataBuffer.TYPE_DOUBLE</CODE>.  When the * <code>ComponentColorModel(ColorSpace, int[], boolean, boolean, int, int)</code> * form of constructor is used with one of these transfer types, the * bits array argument is ignored. * <p> * It is possible to have color/alpha sample values * which cannot be reasonably interpreted as component values for rendering. * This can happen when <code>ComponentColorModel</code> is subclassed to * override the mapping of unsigned sample values to normalized color * component values or when signed sample values outside a certain range * are used.  (As an example, specifying an alpha component as a signed * short value outside the range 0 to 32767, normalized range 0.0 to 1.0, can * lead to unexpected results.) It is the * responsibility of applications to appropriately scale pixel data before * rendering such that color components fall within the normalized range * of the <code>ColorSpace</code> (obtained using the <code>getMinValue</code> * and <code>getMaxValue</code> methods of the <code>ColorSpace</code> class) * and the alpha component is between 0.0 and 1.0.  If color or alpha * component values fall outside these ranges, rendering results are * indeterminate. * <p> * Methods that use a single int pixel representation throw * an <CODE>IllegalArgumentException</CODE>, unless the number of components  * for the <CODE>ComponentColorModel</CODE> is one and the component * value is unsigned -- in other words,  a single color component using * a transfer type of <CODE>DataBuffer.TYPE_BYTE</CODE>, * <CODE>DataBuffer.TYPE_USHORT</CODE>, or <CODE>DataBuffer.TYPE_INT</CODE>  * and no alpha. * <p> * A <CODE>ComponentColorModel</CODE> can be used in conjunction with a  * <CODE>ComponentSampleModel</CODE>, a <CODE>BandedSampleModel</CODE>,  * or a <CODE>PixelInterleavedSampleModel</CODE> to construct a * <CODE>BufferedImage</CODE>. * * @see ColorModel * @see ColorSpace * @see ComponentSampleModel * @see BandedSampleModel * @see PixelInterleavedSampleModel * @see BufferedImage * * @version 10 Feb 1997 */public class ComponentColorModel extends ColorModel {        /**     * <code>signed</code>  is <code>true</code> for <code>short</code>,     * <code>float</code>, and <code>double</code> transfer types; it     * is <code>false</code> for <code>byte</code>, <code>ushort</code>,     * and <code>int</code> transfer types.     */    private boolean signed; // true for transfer types short, float, double                            // false for byte, ushort, int    private boolean is_sRGB_stdScale;    private boolean is_LinearRGB_stdScale;    private boolean is_LinearGray_stdScale;    private boolean is_ICCGray_stdScale;    private byte[] tosRGB8LUT;    private byte[] fromsRGB8LUT8;    private short[] fromsRGB8LUT16;    private byte[] fromLinearGray16ToOtherGray8LUT;    private short[] fromLinearGray16ToOtherGray16LUT;    private boolean needScaleInit;    private boolean noUnnorm;    private boolean nonStdScale;    private float[] min;    private float[] diffMinMax;    private float[] compOffset;    private float[] compScale;    /**     * Constructs a <CODE>ComponentColorModel</CODE> from the specified     * parameters. Color components will be in the specified     * <CODE>ColorSpace</CODE>.  The supported transfer types are     * <CODE>DataBuffer.TYPE_BYTE</CODE>, <CODE>DataBuffer.TYPE_USHORT</CODE>,     * <CODE>DataBuffer.TYPE_INT</CODE>,     * <CODE>DataBuffer.TYPE_SHORT</CODE>, <CODE>DataBuffer.TYPE_FLOAT</CODE>,     * and <CODE>DataBuffer.TYPE_DOUBLE</CODE>.     * If not null, the <CODE>bits</CODE> array specifies the     * number of significant bits per color and alpha component and its     * length should be at least the number of components in the     * <CODE>ColorSpace</CODE> if there is no alpha     * information in the pixel values, or one more than this number if     * there is alpha information.  When the <CODE>transferType</CODE> is     * <CODE>DataBuffer.TYPE_SHORT</CODE>, <CODE>DataBuffer.TYPE_FLOAT</CODE>,     * or <CODE>DataBuffer.TYPE_DOUBLE</CODE> the <CODE>bits</CODE> array     * argument is ignored.  <CODE>hasAlpha</CODE> indicates whether alpha     * information is present.  If <CODE>hasAlpha</CODE> is true, then     * the boolean <CODE>isAlphaPremultiplied</CODE>     * specifies how to interpret color and alpha samples in pixel values.     * If the boolean is true, color samples are assumed to have been     * multiplied by the alpha sample. The <CODE>transparency</CODE>     * specifies what alpha values can be represented by this color model.     * The acceptable <code>transparency</code> values are     * <CODE>OPAQUE</CODE>, <CODE>BITMASK</CODE> or <CODE>TRANSLUCENT</CODE>.     * The <CODE>transferType</CODE> is the type of primitive array used     * to represent pixel values.     *     * @param colorSpace       The <CODE>ColorSpace</CODE> associated      *                         with this color model.     * @param bits             The number of significant bits per component.     *                         May be null, in which case all bits of all     *                         component samples will be significant.     *                         Ignored if transferType is one of     *                         <CODE>DataBuffer.TYPE_SHORT</CODE>,     *                         <CODE>DataBuffer.TYPE_FLOAT</CODE>, or     *                         <CODE>DataBuffer.TYPE_DOUBLE</CODE>,     *                         in which case all bits of all component     *                         samples will be significant.     * @param hasAlpha         If true, this color model supports alpha.     * @param isAlphaPremultiplied If true, alpha is premultiplied.     * @param transparency     Specifies what alpha values can be represented     *                         by this color model.     * @param transferType     Specifies the type of primitive array used to     *                         represent pixel values.     *     * @throws IllegalArgumentException If the <CODE>bits</CODE> array     *         argument is not null, its length is less than the number of     *         color and alpha components, and transferType is one of     *         <CODE>DataBuffer.TYPE_BYTE</CODE>,     *         <CODE>DataBuffer.TYPE_USHORT</CODE>, or     *         <CODE>DataBuffer.TYPE_INT</CODE>.     * @throws IllegalArgumentException If transferType is not one of     *         <CODE>DataBuffer.TYPE_BYTE</CODE>,     *         <CODE>DataBuffer.TYPE_USHORT</CODE>,     *         <CODE>DataBuffer.TYPE_INT</CODE>,     *         <CODE>DataBuffer.TYPE_SHORT</CODE>,     *         <CODE>DataBuffer.TYPE_FLOAT</CODE>, or     *         <CODE>DataBuffer.TYPE_DOUBLE</CODE>.     *     * @see ColorSpace     * @see java.awt.Transparency     */    public ComponentColorModel (ColorSpace colorSpace,                                int[] bits,                                boolean hasAlpha,                                boolean isAlphaPremultiplied,                                int transparency,                                int transferType) {        super (bitsHelper(transferType, colorSpace, hasAlpha),               bitsArrayHelper(bits, transferType, colorSpace, hasAlpha),               colorSpace, hasAlpha, isAlphaPremultiplied, transparency,               transferType);        switch(transferType) {            case DataBuffer.TYPE_BYTE:            case DataBuffer.TYPE_USHORT:            case DataBuffer.TYPE_INT:                signed = false;                needScaleInit = true;                break;            case DataBuffer.TYPE_SHORT:                signed = true;                needScaleInit = true;                break;            case DataBuffer.TYPE_FLOAT:            case DataBuffer.TYPE_DOUBLE:                signed = true;                needScaleInit = false;                noUnnorm = true;                nonStdScale = false;                break;            default:                throw new IllegalArgumentException("This constructor is not "+

⌨️ 快捷键说明

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