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

📄 colormodel.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * <code>normOffset</code> (even if the array is allocated by this     * method).  An <code>ArrayIndexOutOfBoundsException</code> is thrown     * if the <code>normComponents</code> array is not <code>null</code>      * and is not large enough to hold all the color and alpha components     * (starting at <code>normOffset</code>).  An     * <code>IllegalArgumentException</code> is thrown if the      * <code>components</code> array is not large enough to hold all the     * color and alpha components starting at <code>offset</code>.     * <p>     * Since <code>ColorModel</code> is an abstract class,     * any instance is an instance of a subclass.  The default implementation     * of this method in this abstract class assumes that component values     * for this class are conveniently representable in the unnormalized     * form.  Therefore, subclasses which may     * have instances which do not support the unnormalized form must     * override this method.     * @param components an array containing unnormalized components     * @param offset the offset into the <code>components</code> array at     * which to start retrieving unnormalized components     * @param normComponents an array that receives the normalized components     * @param normOffset the index into <code>normComponents</code> at     * which to begin storing normalized components     * @return an array containing normalized color and alpha      * components.      * @throws IllegalArgumentException If the component values for this     * <CODE>ColorModel</CODE> are not conveniently representable in the     * unnormalized form.     * @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)}.     * @throws UnsupportedOperationException if this method is unable     *          to determine the number of bits per component     */    public float[] getNormalizedComponents(int[] components, int offset,                                           float[] normComponents,                                           int normOffset) {        // 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 ((components.length - offset) < numComponents) {            throw new                IllegalArgumentException(                        "Incorrect number of components.  Expecting "+                        numComponents);        }                if (normComponents == null) {            normComponents = new float[numComponents+normOffset];        }        if (supportsAlpha && isAlphaPremultiplied) {            // Normalized coordinates are non premultiplied            float normAlpha = (float)components[offset+numColorComponents];            normAlpha /= (float) ((1<<nBits[numColorComponents]) - 1);            if (normAlpha != 0.0f) {                for (int i=0; i < numColorComponents; i++) {                    normComponents[normOffset+i] =                        ((float) components[offset+i]) /                        (normAlpha * ((float) ((1<<nBits[i]) - 1)));                }            } else {                for (int i=0; i < numColorComponents; i++) {                    normComponents[normOffset+i] = 0.0f;                }            }            normComponents[normOffset+numColorComponents] = normAlpha;        }        else {            for (int i=0; i < numComponents; i++) {                normComponents[normOffset+i] = ((float) components[offset+i]) /                                               ((float) ((1<<nBits[i]) - 1));            }        }        return normComponents;    }    /**     * Returns a pixel value represented as an <code>int</code> in this     * <code>ColorModel</code>, given an array of unnormalized color/alpha     * components.  This method will throw an      * <code>IllegalArgumentException</code> if component 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.  An      * <code>ArrayIndexOutOfBoundsException</code> is thrown if  the     * <code>components</code> array 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 components an array of unnormalized color and alpha     * components     * @param offset the index into <code>components</code> at which to     * begin retrieving the color and alpha components     * @return an <code>int</code> pixel value in this     * <code>ColorModel</code> corresponding to the specified components.       * @throws IllegalArgumentException if     * 	pixel values for this <code>ColorModel</code> are not      * 	conveniently representable as a single <code>int</code>     * @throws IllegalArgumentException if     * 	component values for this <code>ColorModel</code> are not      * 	conveniently representable in the unnormalized form     * @throws ArrayIndexOutOfBoundsException if     *  the <code>components</code> array is not large enough to      *	hold all of the color and alpha components starting at     *	<code>offset</code>      * @throws UnsupportedOperationException if this     * 	method is not supported by this <code>ColorModel</code>     */    public int getDataElement(int[] components, int offset) {        throw new UnsupportedOperationException("This method is not supported "+                                    "by this color model.");    }        /**     * Returns a data element array representation of a pixel in this     * <code>ColorModel</code>, given an array of unnormalized color/alpha     * components.  This array can then be passed to the     * <code>setDataElements</code> method of a <code>WritableRaster</code>      * object.  This method will throw an <code>IllegalArgumentException</code>     * if color component values for this <code>ColorModel</code> are not     * conveniently representable in the unnormalized form.     * An <code>ArrayIndexOutOfBoundsException</code> is thrown     * if the <code>components</code> array is not large enough to hold     * all the color and alpha components (starting at     * <code>offset</code>).  If the <code>obj</code> variable is     * <code>null</code>, a new array will be allocated.  If     * <code>obj</code> is not <code>null</code>, it must be a primitive     * array of type transferType; otherwise, a      * <code>ClassCastException</code> is thrown.  An     * <code>ArrayIndexOutOfBoundsException</code> is thrown if      * <code>obj</code> is not large enough to hold a pixel value for this     * <code>ColorModel</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 components an array of unnormalized color and alpha     * components     * @param offset the index into <code>components</code> at which to     * begin retrieving color and alpha components     * @param obj the <code>Object</code> representing an array of color     * and alpha components     * @return an <code>Object</code> representing an array of color and     * alpha components.     * @throws ClassCastException if <code>obj</code>     *  is not a primitive array of type <code>transferType</code>     * @throws ArrayIndexOutOfBoundsException if     *  <code>obj</code> is not large enough to hold a pixel value     *  for this <code>ColorModel</code> or the <code>components</code>     *	array is not large enough to hold all of the color and alpha     *	components starting at <code>offset</code>      * @throws IllegalArgumentException if     * 	component values for this <code>ColorModel</code> are not      * 	conveniently representable in the unnormalized form     * @throws UnsupportedOperationException if this      *  method is not supported by this <code>ColorModel</code>      * @see WritableRaster#setDataElements     * @see SampleModel#setDataElements     */    public Object getDataElements(int[] components, int offset, Object obj) {        throw new UnsupportedOperationException("This method has not been implemented "+                                    "for this color model.");    }    /**     * Returns a pixel value represented as an <code>int</code> in this     * <code>ColorModel</code>, given an array of normalized color/alpha     * components.  This method will throw an      * <code>IllegalArgumentException</code> if pixel values for this     * <code>ColorModel</code> are not conveniently representable as a     * single <code>int</code>.  An      * <code>ArrayIndexOutOfBoundsException</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>).     * Since <code>ColorModel</code> is an abstract class,     * any instance is an instance of a subclass.  The default implementation     * of this method in this abstract class first converts from the     * normalized form to the unnormalized form and then calls     * <code>getDataElement(int[], int)</code>.  Subclasses which may     * have instances which do not support the unnormalized form must     * override this method.     * @param normComponents an array of normalized color and alpha     * components     * @param normOffset the index into <code>normComponents</code> at which to     * begin retrieving the color and alpha components     * @return an <code>int</code> pixel value in this     * <code>ColorModel</code> corresponding to the specified components.       * @throws IllegalArgumentException if     * 	pixel values for this <code>ColorModel</code> are not      * 	conveniently representable as a single <code>int</code>     * @throws ArrayIndexOutOfBoundsException if     *  the <code>normComponents</code> array is not large enough to      *	hold all of the color and alpha components starting at     *	<code>normOffset</code>      * @since 1.4     */    public int getDataElement(float[] normComponents, int normOffset) {        int components[] = getUnnormalizedComponents(normComponents,                                                     normOffset, null, 0);        return getDataElement(components, 0);    }        /**     * Returns a data element array representation of a pixel in this     * <code>ColorModel</code>, given an array of normalized color/alpha     * components.  This array can then be passed to the     * <code>setDataElements</code> method of a <code>WritableRaster</code>      * object.  An <code>ArrayIndexOutOfBoundsException</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>).  If the <code>obj</code> variable is     * <code>null</code>, a new array will be allocated.  If     * <code>obj</code> is not <code>null</code>, it must be a primitive     * array of type transferType; otherwise, a      * <code>ClassCastException</code> is thrown.  An     * <code>ArrayIndexOutOfBoundsException</code> is thrown if      * <code>obj</code> is not large enough to hold a pixel value for this     * <code>ColorModel</code>.     * Since <code>ColorModel</code> is an abstract class,     * any instance is an instance of a subclass.  The default implementation     * of this method in this abstract class first converts from the     * normalized form to the unnormalized form and then calls     * <code>getDataElement(int[], int, Object)</code>.  Subclasses which may     * have instances which do not support the unnormalized form must     * override this method.     * @param normComponents an array of normalized color and alpha     * components     * @param normOffset the index into <code>normComponents</code> at which to     * begin retrieving color and alpha components     * @param obj a primitive data array to hold the returned pixel     * @return an <code>Object</code> which is a primitive data array     * representation of a pixel     * @throws ClassCastException if <code>obj</code>     *  is not a primitive array of type <code>transferType</code>     * @throws ArrayIndexOutOfBoundsException if     *  <code>obj</code> is not large enough to hold a pixel value     *  for this <code>ColorModel</code> or the <code>normComponents</code>     *	array is not large enough to hold all of the color and alpha     *	components starting at <code>normOffset</code>      * @see WritableRaster#setDataElements     * @see SampleModel#setDataElements     * @since 1.4     */    public Object getDataElements(float[] normComponents, int normOffset,                                  Object obj) {        int components[] = getUnnormalizedComponents(normComponents,                                                     normOffset, null, 0);        return getDataElements(components, 0, obj);    }    /**     * Returns an array of all of the color/alpha components in normalized     * form, 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 referenc

⌨️ 快捷键说明

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