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

📄 componentcolormodel.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                         "compatible with transferType " + transferType);        }        setupLUTs();    }    /**     * 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>.  The number of significant     * bits per color and alpha component will be 8, 16, 32, 16, 32,  or 64,     * respectively.  The number of color components will be the     * number of components in the <CODE>ColorSpace</CODE>.  There will be     * an alpha component if <CODE>hasAlpha</CODE> is <CODE>true</CODE>.     * 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 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 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     * @since 1.4     */    public ComponentColorModel (ColorSpace colorSpace,                                boolean hasAlpha,                                boolean isAlphaPremultiplied,                                int transparency,                                int transferType) {        this(colorSpace, null, hasAlpha, isAlphaPremultiplied,             transparency, transferType);    }    private static int bitsHelper(int transferType,                                  ColorSpace colorSpace,                                  boolean hasAlpha) {        int numBits = DataBuffer.getDataTypeSize(transferType);        int numComponents = colorSpace.getNumComponents();        if (hasAlpha) {            ++numComponents;        }        return numBits * numComponents;    }    private static int[] bitsArrayHelper(int[] origBits,                                         int transferType,                                         ColorSpace colorSpace,                                         boolean hasAlpha) {        switch(transferType) {            case DataBuffer.TYPE_BYTE:            case DataBuffer.TYPE_USHORT:            case DataBuffer.TYPE_INT:                if (origBits != null) {                    return origBits;                }                break;            default:                break;        }        int numBits = DataBuffer.getDataTypeSize(transferType);        int numComponents = colorSpace.getNumComponents();        if (hasAlpha) {            ++numComponents;        }        int[] bits = new int[numComponents];        for (int i = 0; i < numComponents; i++) {            bits[i] = numBits;        }        return bits;    }    private void setupLUTs() {        // REMIND: there is potential to accelerate sRGB, LinearRGB,        // LinearGray, ICCGray, and non-ICC Gray spaces with non-standard        // scaling, if that becomes important        //        // NOTE: The is_xxx_stdScale and nonStdScale booleans are provisionally        // set here when this method is called at construction time.  These        // variables may be set again when initScale is called later.        // When setupLUTs returns, nonStdScale is true if (the transferType        // is not float or double) AND (some minimum ColorSpace component        // value is not 0.0 OR some maximum ColorSpace component value        // is not 1.0).  This is correct for the calls to        // getNormalizedComponents(Object, float[], int) from initScale().        // initScale() may change the value nonStdScale based on the        // return value of getNormalizedComponents() - this will only        // happen if getNormalizedComponents() has been overridden by a        // subclass to make the mapping of min/max pixel sample values        // something different from min/max color component values.        if (is_sRGB) {            is_sRGB_stdScale = true;            nonStdScale = false;        } else if (ColorModel.isLinearRGBspace(colorSpace)) {            // Note that the built-in Linear RGB space has a normalized            // range of 0.0 - 1.0 for each coordinate.  Usage of these            // LUTs makes that assumption.            is_LinearRGB_stdScale = true;            nonStdScale = false;            if (transferType == DataBuffer.TYPE_BYTE) {                tosRGB8LUT = ColorModel.getLinearRGB8TosRGB8LUT();                fromsRGB8LUT8 = ColorModel.getsRGB8ToLinearRGB8LUT();            } else {                tosRGB8LUT = ColorModel.getLinearRGB16TosRGB8LUT();                fromsRGB8LUT16 = ColorModel.getsRGB8ToLinearRGB16LUT();            }        } else if ((colorSpaceType == ColorSpace.TYPE_GRAY) &&                   (colorSpace instanceof ICC_ColorSpace) &&                   (colorSpace.getMinValue(0) == 0.0f) &&                   (colorSpace.getMaxValue(0) == 1.0f)) {            // Note that a normalized range of 0.0 - 1.0 for the gray            // component is required, because usage of these LUTs makes            // that assumption.            ICC_ColorSpace ics = (ICC_ColorSpace) colorSpace;            is_ICCGray_stdScale = true;            nonStdScale = false;            fromsRGB8LUT16 = ColorModel.getsRGB8ToLinearRGB16LUT();            if (ColorModel.isLinearGRAYspace(ics)) {                is_LinearGray_stdScale = true;                if (transferType == DataBuffer.TYPE_BYTE) {                    tosRGB8LUT = ColorModel.getGray8TosRGB8LUT(ics);                } else {                    tosRGB8LUT = ColorModel.getGray16TosRGB8LUT(ics);                }            } else {                if (transferType == DataBuffer.TYPE_BYTE) {                    tosRGB8LUT = ColorModel.getGray8TosRGB8LUT(ics);                    fromLinearGray16ToOtherGray8LUT =                        ColorModel.getLinearGray16ToOtherGray8LUT(ics);                } else {                    tosRGB8LUT = ColorModel.getGray16TosRGB8LUT(ics);                    fromLinearGray16ToOtherGray16LUT =                        ColorModel.getLinearGray16ToOtherGray16LUT(ics);                }            }        } else if (needScaleInit) {            // if transferType is byte, ushort, int, or short and we            // don't already know the ColorSpace has minVlaue == 0.0f and            // maxValue == 1.0f for all components, we need to check that            // now and setup the min[] and diffMinMax[] arrays if necessary.            nonStdScale = false;            for (int i = 0; i < numColorComponents; i++) {                if ((colorSpace.getMinValue(i) != 0.0f) ||                    (colorSpace.getMaxValue(i) != 1.0f)) {                    nonStdScale = true;                    break;                }            }            if (nonStdScale) {                min = new float[numColorComponents];                diffMinMax = new float[numColorComponents];                for (int i = 0; i < numColorComponents; i++) {                    min[i] = colorSpace.getMinValue(i);                    diffMinMax[i] = colorSpace.getMaxValue(i) - min[i];                }            }        }    }    private void initScale() {        // This method is called the first time any method which uses        // pixel sample value to color component value scaling information        // is called if the transferType supports non-standard scaling        // as defined above (byte, ushort, int, and short), unless the        // method is getNormalizedComponents(Object, float[], int) (that        // method must be overridden to use non-standard scaling).  This        // method also sets up the noUnnorm boolean variable for these        // transferTypes.  After this method is called, the nonStdScale        // variable will be true if getNormalizedComponents() maps a        // sample value of 0 to anything other than 0.0f OR maps a        // sample value of 2^^n - 1 (2^^15 - 1 for short transferType)        // to anything other than 1.0f.  Note that this can be independent        // of the colorSpace min/max component values, if the        // getNormalizedComponents() method has been overridden for some        // reason, e.g. to provide greater dynamic range in the sample        // values than in the color component values.  Unfortunately,        // this method can't be called at construction time, since a        // subclass may still have uninitialized state that would cause        // getNormalizedComponents() to return an incorrect result.        needScaleInit = false; // only needs to called once        if (nonStdScale || signed) {            // The unnormalized form is only supported for unsigned            // transferTypes and when the ColorSpace min/max values            // are 0.0/1.0.  When this method is called nonStdScale is            // true if the latter condition does not hold.  In addition,            // the unnormalized form requires that the full range of            // the pixel sample values map to the full 0.0 - 1.0 range            // of color component values.  That condition is checked            // later in this method.            noUnnorm = true;        } else {            noUnnorm = false;        }        float[] lowVal, highVal;        switch (transferType) {        case DataBuffer.TYPE_BYTE:            {                byte[] bpixel = new byte[numComponents];                for (int i = 0; i < numColorComponents; i++) {                    bpixel[i] = 0;                }                if (supportsAlpha) {                    bpixel[numColorComponents] =                        (byte) ((1 << nBits[numColorComponents]) - 1);                }                lowVal = getNormalizedComponents(bpixel, null, 0);                for (int i = 0; i < numColorComponents; i++) {                    bpixel[i] = (byte) ((1 << nBits[i]) - 1);                }                highVal = getNormalizedComponents(bpixel, null, 0);            }            break;        case DataBuffer.TYPE_USHORT:            {                short[] uspixel = new short[numComponents];                for (int i = 0; i < numColorComponents; i++) {                    uspixel[i] = 0;                }                if (supportsAlpha) {                    uspixel[numColorComponents] =                        (short) ((1 << nBits[numColorComponents]) - 1);                }                lowVal = getNormalizedComponents(uspixel, null, 0);                for (int i = 0; i < numColorComponents; i++) {                    uspixel[i] = (short) ((1 << nBits[i]) - 1);                }                highVal = getNormalizedComponents(uspixel, null, 0);            }            break;        case DataBuffer.TYPE_INT:            {                int[] ipixel = new int[numComponents];                for (int i = 0; i < numColorComponents; i++) {                    ipixel[i] = 0;                }                if (supportsAlpha) {                    ipixel[numColorComponents] =                        ((1 << nBits[numColorComponents]) - 1);                }                lowVal = getNormalizedComponents(ipixel, null, 0);                for (int i = 0; i < numColorComponents; i++) {                    ipixel[i] = ((1 << nBits[i]) - 1);                }                highVal = getNormalizedComponents(ipixel, null, 0);            }            break;        case DataBuffer.TYPE_SHORT:            {                short[] spixel = new short[numComponents];                for (int i = 0; i < numColorComponents; i++) {                    spixel[i] = 0;                }                if (supportsAlpha) {                    spixel[numColorComponents] = 32767;                }

⌨️ 快捷键说明

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