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

📄 directcolormodel.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    final public int getAlphaMask() {        if (supportsAlpha) {            return maskArray[3];        } else {            return 0;        }    }    /*     * Given an int pixel in this ColorModel's ColorSpace, converts     * it to the default sRGB ColorSpace and returns the R, G, and B     * components as float values between 0.0 and 1.0.     */    private float[] getDefaultRGBComponents(int pixel) {        int components[] = getComponents(pixel, null, 0);        float norm[] = getNormalizedComponents(components, 0, null, 0);        // Note that getNormalizedComponents returns non-premultiplied values        return colorSpace.toRGB(norm);    }    private int getsRGBComponentFromsRGB(int pixel, int idx) {	int c = ((pixel & maskArray[idx]) >>> maskOffsets[idx]);        if (isAlphaPremultiplied) {            int a = ((pixel & maskArray[3]) >>> maskOffsets[3]);            c = (a == 0) ? 0 :                         (int) (((c * scaleFactors[idx]) * 255.0f /                                 (a * scaleFactors[3])) + 0.5f);        } else if (scaleFactors[idx] != 1.0f) {	    c = (int) ((c * scaleFactors[idx]) + 0.5f);        }	return c;    }    private int getsRGBComponentFromLinearRGB(int pixel, int idx) {	int c = ((pixel & maskArray[idx]) >>> maskOffsets[idx]);        if (isAlphaPremultiplied) {            float factor = (float) ((1 << lRGBprecision) - 1);            int a = ((pixel & maskArray[3]) >>> maskOffsets[3]);            c = (a == 0) ? 0 :                         (int) (((c * scaleFactors[idx]) * factor /                                 (a * scaleFactors[3])) + 0.5f);        } else if (nBits[idx] != lRGBprecision) {            if (lRGBprecision == 16) {                c = (int) ((c * scaleFactors[idx] * 257.0f) + 0.5f);            } else {	        c = (int) ((c * scaleFactors[idx]) + 0.5f);            }        }        // now range of c is 0-255 or 0-65535, depending on lRGBprecision	return tosRGB8LUT[c] & 0xff;    }    /**     * Returns the red color component for the specified pixel, scaled     * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB.  A      * color conversion is done if necessary.  The pixel value is specified      * as an <code>int</code>.     * 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 red value      * is 0.     * @param pixel the specified pixel     * @return the red color component for the specified pixel, from      *         0 to 255 in the sRGB <code>ColorSpace</code>.     */    final public int getRed(int pixel) {        if (is_sRGB) {            return getsRGBComponentFromsRGB(pixel, 0);        } else if (is_LinearRGB) {            return getsRGBComponentFromLinearRGB(pixel, 0);        }        float rgb[] = getDefaultRGBComponents(pixel);        return (int) (rgb[0] * 255.0f + 0.5f);    }    /**     * Returns the green color component for the specified pixel, scaled     * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB.  A      * color conversion is done if necessary.  The pixel value is specified     * as an <code>int</code>.     * 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 green value     * is 0.     * @param pixel the specified pixel     * @return the green color component for the specified pixel, from      *         0 to 255 in the sRGB <code>ColorSpace</code>.     */    final public int getGreen(int pixel) {        if (is_sRGB) {            return getsRGBComponentFromsRGB(pixel, 1);        } else if (is_LinearRGB) {            return getsRGBComponentFromLinearRGB(pixel, 1);        }        float rgb[] = getDefaultRGBComponents(pixel);        return (int) (rgb[1] * 255.0f + 0.5f);    }    /**     * Returns the blue color component for the specified pixel, scaled     * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB.  A      * color conversion is done if necessary.  The pixel value is specified     * as an <code>int</code>.     * 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.     * @param pixel the specified pixel     * @return the blue color component for the specified pixel, from      *         0 to 255 in the sRGB <code>ColorSpace</code>.     */    final public int getBlue(int pixel) {        if (is_sRGB) {            return getsRGBComponentFromsRGB(pixel, 2);        } else if (is_LinearRGB) {            return getsRGBComponentFromLinearRGB(pixel, 2);        }        float rgb[] = getDefaultRGBComponents(pixel);        return (int) (rgb[2] * 255.0f + 0.5f);    }    /**     * Returns the alpha component for the specified pixel, scaled     * from 0 to 255.  The pixel value is specified as an <code>int</code>.     * @param pixel the specified pixel     * @return the value of the alpha component of <code>pixel</code>     *         from 0 to 255.         */    final public int getAlpha(int pixel) {	if (!supportsAlpha) return 255;	int a = ((pixel & maskArray[3]) >>> maskOffsets[3]);	if (scaleFactors[3] != 1.0f) {	    a = (int)(a * scaleFactors[3] + 0.5f);	}	return a;    }    /**     * Returns the color/alpha components of the pixel in the default     * RGB color model format.  A color conversion is done if necessary.     * The pixel value is specified as an <code>int</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 are each 0.     * @param pixel the specified pixel     * @return the RGB value of the color/alpha components of the specified     *         pixel.     * @see ColorModel#getRGBdefault     */    final public int getRGB(int pixel) {        if (is_sRGB || is_LinearRGB) {	    return (getAlpha(pixel) << 24)	        | (getRed(pixel) << 16)	        | (getGreen(pixel) << 8)	        | (getBlue(pixel) << 0);        }        float rgb[] = getDefaultRGBComponents(pixel);        return (getAlpha(pixel) << 24)            | (((int) (rgb[0] * 255.0f + 0.5f)) << 16)            | (((int) (rgb[1] * 255.0f + 0.5f)) << 8)            | (((int) (rgb[2] * 255.0f + 0.5f)) << 0);    }        /**     * Returns the red color component for the specified pixel, scaled     * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB.  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.     * 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 red 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 red 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 getRed(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 getRed(pixel);    }       /**     * Returns the green color component for the specified pixel, scaled     * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB.  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.     * 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 green 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 green 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 getGreen(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 getGreen(pixel);    }       /**     * Returns the blue color component for the specified pixel, scaled     * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB.  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.

⌨️ 快捷键说明

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