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

📄 directcolormodel.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * The returned value is a non pre-multiplied value.  Thus, if the     * alpha is premultiplied, this method divides it out before returning     * the value.  If the alpha value is 0, for example, the blue value      * is 0.  If <code>inData</code> is not a primitive array of type     * <code>transferType</code>, 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>.  Since     * <code>DirectColorModel</code> can be subclassed, subclasses inherit     * the implementation of this method and if they don't override it     * then they throw an exception if they use an unsupported     * <code>transferType</code>.     * An <code>UnsupportedOperationException</code> is     * thrown if this <code>transferType</code> is not supported by this      * <code>ColorModel</code>.     * @param inData the array containing the pixel value     * @return the value of the blue component of the specified pixel.     * @throws ArrayIndexOutOfBoundsException if <code>inData</code> is not     *         large enough to hold a pixel value for this color model     * @throws ClassCastException if <code>inData</code> is not a      *         primitive array of type <code>transferType</code>     * @throws UnsupportedOperationException if this <code>transferType</code>     *         is not supported by this color model     */    public int getBlue(Object inData) {        int pixel=0;        switch (transferType) {            case DataBuffer.TYPE_BYTE:               byte bdata[] = (byte[])inData;               pixel = bdata[0] & 0xff;            break;            case DataBuffer.TYPE_USHORT:               short sdata[] = (short[])inData;               pixel = sdata[0] & 0xffff;            break;            case DataBuffer.TYPE_INT:               int idata[] = (int[])inData;               pixel = idata[0];            break;            default:               throw new UnsupportedOperationException("This method has not been "+                   "implemented for transferType " + transferType);        }        return getBlue(pixel);    }    /**     * Returns the alpha component for the specified pixel, scaled     * from 0 to 255.  The pixel value is specified by an array of data     * elements of type <code>transferType</code> passed in as an object     * reference.     * If <code>inData</code> is not a primitive array of type      * <code>transferType</code>, 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>.  Since     * <code>DirectColorModel</code> can be subclassed, subclasses inherit     * the implementation of this method and if they don't override it     * then they throw an exception if they use an unsupported     * <code>transferType</code>.     * If this <code>transferType</code> is not supported, an     * <code>UnsupportedOperationException</code> is thrown.     * @param inData the specified pixel     * @return the alpha component of the specified pixel, scaled from     *         0 to 255.     * @exception <code>ClassCastException</code> if <code>inData</code>     * 	is not a primitive array of type <code>transferType</code>     * @exception <code>ArrayIndexOutOfBoundsException</code> if     *	<code>inData</code> is not large enough to hold a pixel value     *	for this <code>ColorModel</code>     * @exception <code>UnsupportedOperationException</code> if this     *	<code>tranferType</code> is not supported by this     *	<code>ColorModel</code>     */    public int getAlpha(Object inData) {        int pixel=0;        switch (transferType) {            case DataBuffer.TYPE_BYTE:               byte bdata[] = (byte[])inData;               pixel = bdata[0] & 0xff;            break;            case DataBuffer.TYPE_USHORT:               short sdata[] = (short[])inData;               pixel = sdata[0] & 0xffff;            break;            case DataBuffer.TYPE_INT:               int idata[] = (int[])inData;               pixel = idata[0];            break;            default:               throw new UnsupportedOperationException("This method has not been "+                   "implemented for transferType " + transferType);        }        return getAlpha(pixel);    }    /**     * 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 <code>transferType</code> passed in as an object     * reference.  If <code>inData</code> is not a primitive array of type     * <code>transferType</code>, 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 is in a non pre-multiplied format.  Thus, if     * the alpha is premultiplied, this method divides it out of the     * color components.  If the alpha value is 0, for example, the color      * values is 0.  Since <code>DirectColorModel</code> can be     * subclassed, subclasses inherit the implementation of this method     * and if they don't override it then     * they throw an exception if they use an unsupported      * <code>transferType</code>.     *     * @param inData the specified pixel     * @return the color and alpha components of the specified pixel.     * @exception UnsupportedOperationException if this      *            <code>transferType</code> is not supported by this     *            <code>ColorModel</code>     * @see ColorModel#getRGBdefault     */    public int getRGB(Object inData) {        int pixel=0;        switch (transferType) {            case DataBuffer.TYPE_BYTE:               byte bdata[] = (byte[])inData;               pixel = bdata[0] & 0xff;            break;            case DataBuffer.TYPE_USHORT:               short sdata[] = (short[])inData;               pixel = sdata[0] & 0xffff;            break;            case DataBuffer.TYPE_INT:               int idata[] = (int[])inData;               pixel = idata[0];            break;            default:               throw new UnsupportedOperationException("This method has not been "+                   "implemented for transferType " + transferType);        }        return getRGB(pixel);    }    /**     * 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 <code>setDataElements</code>     * method of a <code>WritableRaster</code> object.  If the pixel variable     * is <code>null</code>, a new array is 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.     * Since <code>DirectColorModel</code> can be subclassed, subclasses     * inherit the implementation of this method and if they don't     * override it then they throw an exception if they use an unsupported     * <code>transferType</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>     * @exception ClassCastException if <code>pixel</code>      *  is not a primitive array of type <code>transferType</code>     * @exception ArrayIndexOutOfBoundsException if     *  <code>pixel</code> is not large enough to hold a pixel value     *  for this <code>ColorModel</code>     * @exception UnsupportedOperationException if this     *  <code>transferType</code> is not supported by this      *  <code>ColorModel</code>      * @see WritableRaster#setDataElements     * @see SampleModel#setDataElements     */    public Object getDataElements(int rgb, Object pixel) {        //REMIND: maybe more efficient not to use int array for        //DataBuffer.TYPE_USHORT and DataBuffer.TYPE_INT        int intpixel[] = null;        if (transferType == DataBuffer.TYPE_INT &&            pixel != null) {            intpixel = (int[])pixel;            intpixel[0] = 0;        } else {            intpixel = new int[1];        }        ColorModel defaultCM = ColorModel.getRGBdefault();        if (this == defaultCM || equals(defaultCM)) {            intpixel[0] = rgb;            return intpixel;        }        int red, grn, blu, alp;        red = (rgb>>16) & 0xff;        grn = (rgb>>8) & 0xff;        blu = rgb & 0xff;        if (is_sRGB || is_LinearRGB) {            int precision;            float factor;            if (is_LinearRGB) {                if (lRGBprecision == 8) {                    red = fromsRGB8LUT8[red] & 0xff;                    grn = fromsRGB8LUT8[grn] & 0xff;                    blu = fromsRGB8LUT8[blu] & 0xff;                    precision = 8;                    factor = 1.0f / 255.0f;                } else {                    red = fromsRGB8LUT16[red] & 0xffff;                    grn = fromsRGB8LUT16[grn] & 0xffff;                    blu = fromsRGB8LUT16[blu] & 0xffff;                    precision = 16;                    factor = 1.0f / 65535.0f;                }            } else {                precision = 8;                factor = 1.0f / 255.0f;            }            if (supportsAlpha) {                alp = (rgb>>24) & 0xff;                if (isAlphaPremultiplied) {                    factor *= (alp * (1.0f / 255.0f));                    precision = -1;  // force component calculations below                }                if (nBits[3] != 8) {                    alp = (int)                        ((alp * (1.0f / 255.0f) * ((1<<nBits[3]) - 1)) + 0.5f);                    if (alp > ((1<<nBits[3]) - 1)) {                        // fix 4412670 - see comment below                        alp = (1<<nBits[3]) - 1;                    }                }                intpixel[0] = alp << maskOffsets[3];            }            if (nBits[0] != precision) {                red = (int) ((red * factor * ((1<<nBits[0]) - 1)) + 0.5f);            }            if (nBits[1] != precision) {                grn = (int) ((grn * factor * ((1<<nBits[1]) - 1)) + 0.5f);            }            if (nBits[2] != precision) {                blu = (int) ((blu * factor * ((1<<nBits[2]) - 1)) + 0.5f);            }        } else {            // Need to convert the color            float[] norm = new float[3];            float factor = 1.0f / 255.0f;            norm[0] = red * factor;            norm[1] = grn * factor;            norm[2] = blu * factor;            norm = colorSpace.fromRGB(norm);            if (supportsAlpha) {                alp = (rgb>>24) & 0xff;                if (isAlphaPremultiplied) {                    factor *= alp;                    for (int i = 0; i < 3; i++) {                        norm[i] *= factor;                    }                }                if (nBits[3] != 8) {                    alp = (int)                        ((alp * (1.0f / 255.0f) * ((1<<nBits[3]) - 1)) + 0.5f);                    if (alp > ((1<<nBits[3]) - 1)) {                        // fix 4412670 - see comment below                        alp = (1<<nBits[3]) - 1;                    }                }                intpixel[0] = alp << maskOffsets[3];            }            red = (int) ((norm[0] * ((1<<nBits[0]) - 1)) + 0.5f);            grn = (int) ((norm[1] * ((1<<nBits[1]) - 1)) + 0.5f);            blu = (int) ((norm[2] * ((1<<nBits[2]) - 1)) + 0.5f);        }        if (maxBits > 23) {            // fix 4412670 - for components of 24 or more bits            // some calculations done above with float precision            // may lose enough precision that the integer result

⌨️ 快捷键说明

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