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

📄 colormodel.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
               pixel = sdata[0] & 0xffff;               length = sdata.length;            break;            case DataBuffer.TYPE_INT:               int idata[] = (int[])inData;               pixel = idata[0];               length = idata.length;            break;            default:               throw new UnsupportedOperationException("This method has not been "+                   "implemented for transferType " + transferType);        }        if (length == 1) {            return getAlpha(pixel);        }        else {            throw new UnsupportedOperationException                ("This method is not supported by this color model");        }    }    /**     * Returns the color/alpha components for the specified pixel in the     * default RGB color model format.  A color conversion is done if     * necessary.  The pixel value is specified by an array of data     * elements of type transferType passed in as an object reference.     * If inData is not a primitive array of type transferType, a     * <code>ClassCastException</code> is thrown.  An     * <code>ArrayIndexOutOfBoundsException</code> is     * thrown if <code>inData</code> is not large enough to hold a pixel     * value for this <code>ColorModel</code>.     * The returned value will be in a non pre-multiplied format, i.e. if     * the alpha is premultiplied, this method will divide it out of the     * color components (if the alpha value is 0, the color values will be 0).     * @param inData the specified pixel     * @return the color and alpha components of the specified pixel.     * @see ColorModel#getRGBdefault     */    public int getRGB(Object inData) {        return (getAlpha(inData) << 24)            | (getRed(inData) << 16)            | (getGreen(inData) << 8)            | (getBlue(inData) << 0);    }    /**     * Returns a data element array representation of a pixel in this     * <code>ColorModel</code>, given an integer pixel representation in     * the default RGB color model.     * This array can then be passed to the      * {@link WritableRaster#setDataElements} method of     * a {@link WritableRaster} object.  If the pixel variable is      * <code>null</code>, a new array will be allocated.  If      * <code>pixel</code> is not     * <code>null</code>, it must be a primitive array of type     * <code>transferType</code>; otherwise, a     * <code>ClassCastException</code> is thrown.  An     * <code>ArrayIndexOutOfBoundsException</code> is thrown if      * <code>pixel</code> is     * not large enough to hold a pixel value for this     * <code>ColorModel</code>. The pixel array is returned.     * If this <code>transferType</code> is not supported, a     * <code>UnsupportedOperationException</code> will be      * thrown.  Since <code>ColorModel</code> is an abstract class,     * any instance is an instance of a subclass.  Subclasses must     * override this method since the implementation in this abstract     * class throws an <code>UnsupportedOperationException</code>.     * @param rgb the integer pixel representation in the default RGB     * color model     * @param pixel the specified pixel     * @return an array representation of the specified pixel in this     *	<code>ColorModel</code>.     * @throws ClassCastException if <code>pixel</code>     *  is not a primitive array of type <code>transferType</code>     * @throws ArrayIndexOutOfBoundsException if     *  <code>pixel</code> is not large enough to hold a pixel value     *  for this <code>ColorModel</code>     * @throws UnsupportedOperationException if this     *  method is not supported by this <code>ColorModel</code>      * @see WritableRaster#setDataElements     * @see SampleModel#setDataElements     */    public Object getDataElements(int rgb, Object pixel) {        throw new UnsupportedOperationException            ("This method is not supported by this color model.");    }        /**     * Returns an array of unnormalized color/alpha components given a pixel      * in this <code>ColorModel</code>.  The pixel value is specified as     * an <code>int</code>.  An <code>IllegalArgumentException</code>     * will be thrown if pixel values for this <code>ColorModel</code> are     * not conveniently representable as a single <code>int</code> or if     * color component values for this <code>ColorModel</code> are not     * conveniently representable in the unnormalized form.     * For example, this method can be used to retrieve the     * components for a specific pixel value in a      * <code>DirectColorModel</code>.  If the components array is      * <code>null</code>, a new array will be allocated.  The     * components array will be returned.  Color/alpha components are     * stored in the components array starting at <code>offset</code>      * (even if the array is allocated by this method).  An     * <code>ArrayIndexOutOfBoundsException</code> is thrown if  the     * components array is not <code>null</code> and is not large     * enough to hold all the color and alpha components (starting at offset).     * Since <code>ColorModel</code> is an abstract class,     * any instance is an instance of a subclass.  Subclasses must        * override this method since the implementation in this abstract     * class throws an <code>UnsupportedOperationException</code>.     * @param pixel the specified pixel     * @param components the array to receive the color and alpha     * components of the specified pixel     * @param offset the offset into the <code>components</code> array at     * which to start storing the color and alpha components     * @return an array containing the color and alpha components of the     * specified pixel starting at the specified offset.     * @throws UnsupportedOperationException if this     *		method is not supported by this <code>ColorModel</code>     */    public int[] getComponents(int pixel, int[] components, int offset) {        throw new UnsupportedOperationException            ("This method is not supported by this color model.");    }        /**     * Returns an array of unnormalized color/alpha components given a pixel     * in this <code>ColorModel</code>.  The pixel value is specified by     * an array of data elements of type transferType passed in as an     * object reference.  If <code>pixel</code> is not a primitive array     * of type transferType, a <code>ClassCastException</code> is thrown.     * An <code>IllegalArgumentException</code> will be thrown if color     * component values for this <code>ColorModel</code> are not     * conveniently representable in the unnormalized form.     * An <code>ArrayIndexOutOfBoundsException</code> is     * thrown if <code>pixel</code> is not large enough to hold a pixel     * value for this <code>ColorModel</code>.     * This method can be used to retrieve the components for a specific     * pixel value in any <code>ColorModel</code>.  If the components     * array is <code>null</code>, a new array will be allocated.  The     * components array will be returned.  Color/alpha components are     * stored in the <code>components</code> array starting at      * <code>offset</code> (even if the array is allocated by this     * method).  An <code>ArrayIndexOutOfBoundsException</code>     * is thrown if  the components array is not <code>null</code> and is     * not large enough to hold all the color and alpha components     * (starting at <code>offset</code>).     * Since <code>ColorModel</code> is an abstract class,     * any instance is an instance of a subclass.  Subclasses must        * override this method since the implementation in this abstract     * class throws an <code>UnsupportedOperationException</code>.     * @param pixel the specified pixel     * @param components an array that receives the color and alpha     * components of the specified pixel     * @param offset the index into the <code>components</code> array at     * which to begin storing the color and alpha components of the      * specified pixel     * @return an array containing the color and alpha components of the     * specified pixel starting at the specified offset.     * @throws UnsupportedOperationException if this     *		method is not supported by this <code>ColorModel</code>     */    public int[] getComponents(Object pixel, int[] components, int offset) {        throw new UnsupportedOperationException            ("This method is not supported by this color model.");    }    /**     * Returns an array of all of the color/alpha components in unnormalized     * form, given a normalized component array.  Unnormalized components     * are unsigned integral values between 0 and 2<sup>n</sup> - 1, where     * n is the number of bits for a particular component.  Normalized     * components are float values between a per component minimum and     * maximum specified by the <code>ColorSpace</code> object for this     * <code>ColorModel</code>.  An <code>IllegalArgumentException</code>     * will be thrown if color component values for this     * <code>ColorModel</code> are not conveniently representable in the     * unnormalized form.  If the      * <code>components</code> array is <code>null</code>, a new array     * will be allocated.  The <code>components</code> array will     * be returned.  Color/alpha components are stored in the      * <code>components</code> array starting at <code>offset</code> (even     * if the array is allocated by this method). An     * <code>ArrayIndexOutOfBoundsException</code> is thrown if the     * <code>components</code> array is not <code>null</code> and is not     * large enough to hold all the color and alpha     * components (starting at <code>offset</code>).  An     * <code>IllegalArgumentException</code> is thrown if the     * <code>normComponents</code> array is not large enough to hold     * all the color and alpha components starting at     * <code>normOffset</code>.     * @param normComponents an array containing normalized components     * @param normOffset the offset into the <code>normComponents</code>      * array at which to start retrieving normalized components     * @param components an array that receives the components from     * <code>normComponents</code>     * @param offset the index into <code>components</code> at which to     * begin storing normalized components from      * <code>normComponents</code>     * @return an array containing unnormalized color and alpha      * components.     * @throws IllegalArgumentException If the component values for this     * <CODE>ColorModel</CODE> are not conveniently representable in the     * unnormalized form.     * @throws IllegalArgumentException if the length of      *          <code>normComponents</code> minus <code>normOffset</code>     *          is less than <code>numComponents</code>     * @throws UnsupportedOperationException if the     *          constructor of this <code>ColorModel</code> called the     *          <code>super(bits)</code> constructor, but did not      *          override this method.  See the constructor,      *          {@link #ColorModel(int)}.     */    public int[] getUnnormalizedComponents(float[] normComponents,                                           int normOffset,                                           int[] components, int offset) {        // Make sure that someone isn't using a custom color model        // that called the super(bits) constructor.        if (colorSpace == null) {            throw new UnsupportedOperationException("This method is not supported "+                                        "by this color model.");        }        if (nBits == null) {            throw new UnsupportedOperationException ("This method is not supported.  "+                                         "Unable to determine #bits per "+                                         "component.");        }        if ((normComponents.length - normOffset) < numComponents) {            throw new                IllegalArgumentException(                        "Incorrect number of components.  Expecting "+                        numComponents);        }                if (components == null) {            components = new int[offset+numComponents];        }        if (supportsAlpha && isAlphaPremultiplied) {            float normAlpha = normComponents[normOffset+numColorComponents];            for (int i=0; i < numColorComponents; i++) {                components[offset+i] = (int) (normComponents[normOffset+i]                                              * ((1<<nBits[i]) - 1)                                              * normAlpha + 0.5f);            }            components[offset+numColorComponents] = (int)                (normAlpha * ((1<<nBits[numColorComponents]) - 1) + 0.5f);        }        else {            for (int i=0; i < numComponents; i++) {                components[offset+i] = (int) (normComponents[normOffset+i]                                              * ((1<<nBits[i]) - 1) + 0.5f);            }        }                return components;    }    /**     * Returns an array of all of the color/alpha components in normalized     * form, given an unnormalized component array.  Unnormalized components     * are unsigned integral values between 0 and 2<sup>n</sup> - 1, where     * n is the number of bits for a particular component.  Normalized     * components are float values between a per component minimum and     * maximum specified by the <code>ColorSpace</code> object for this     * <code>ColorModel</code>.  An <code>IllegalArgumentException</code>     * will be thrown if color component values for this     * <code>ColorModel</code> are not conveniently representable in the     * unnormalized form.  If the     * <code>normComponents</code> array is <code>null</code>, a new array     * will be allocated.  The <code>normComponents</code> array     * will be returned.  Color/alpha components are stored in the     * <code>normComponents</code> array starting at

⌨️ 快捷键说明

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