java.awt.color.ColorSpace#TYPE_GRAY源码实例Demo

下面列出了java.awt.color.ColorSpace#TYPE_GRAY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u60   文件: BogusColorSpace.java
/**
 * Return the type given the number of components.
 *
 * @param numComponents The number of components in the
 * <code>ColorSpace</code>.
 * @exception IllegalArgumentException if <code>numComponents</code>
 * is less than 1.
 */
private static int getType(int numComponents) {
    if(numComponents < 1) {
        throw new IllegalArgumentException("numComponents < 1!");
    }

    int type;
    switch(numComponents) {
    case 1:
        type = ColorSpace.TYPE_GRAY;
        break;
    default:
        // Based on the constant definitions TYPE_2CLR=12 through
        // TYPE_FCLR=25. This will return unknown types for
        // numComponents > 15.
        type = numComponents + 10;
    }

    return type;
}
 
源代码2 项目: openjdk-jdk8u   文件: JPEG.java
/**
 * Given an image type, return the Adobe transform corresponding to
 * that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
 * with an Adobe marker segment.  If <code>input</code> is true, then
 * the image type is considered before colorspace conversion.
 */
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
    int retval = ADOBE_IMPOSSIBLE;
    ColorModel cm = imageType.getColorModel();
    switch (cm.getColorSpace().getType()) {
    case ColorSpace.TYPE_GRAY:
        retval = ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_RGB:
        retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = ADOBE_YCC;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
    }
    return retval;
}
 
源代码3 项目: jdk8u-dev-jdk   文件: JPEG.java
/**
 * Given an image type, return the Adobe transform corresponding to
 * that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
 * with an Adobe marker segment.  If <code>input</code> is true, then
 * the image type is considered before colorspace conversion.
 */
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
    int retval = ADOBE_IMPOSSIBLE;
    ColorModel cm = imageType.getColorModel();
    switch (cm.getColorSpace().getType()) {
    case ColorSpace.TYPE_GRAY:
        retval = ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_RGB:
        retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = ADOBE_YCC;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
    }
    return retval;
}
 
源代码4 项目: openjdk-8   文件: JPEG.java
/**
 * Given an image type, return the Adobe transform corresponding to
 * that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
 * with an Adobe marker segment.  If <code>input</code> is true, then
 * the image type is considered before colorspace conversion.
 */
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
    int retval = ADOBE_IMPOSSIBLE;
    ColorModel cm = imageType.getColorModel();
    switch (cm.getColorSpace().getType()) {
    case ColorSpace.TYPE_GRAY:
        retval = ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_RGB:
        retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = ADOBE_YCC;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
    }
    return retval;
}
 
源代码5 项目: JDKSourceCode1.8   文件: JFIFMarkerSegment.java
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
 
源代码6 项目: commons-imaging   文件: PaletteFactory.java
public boolean isGrayscale(final BufferedImage src) {
    final int width = src.getWidth();
    final int height = src.getHeight();

    if (ColorSpace.TYPE_GRAY == src.getColorModel().getColorSpace().getType()) {
        return true;
    }

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            final int argb = src.getRGB(x, y);

            final int red = 0xff & (argb >> 16);
            final int green = 0xff & (argb >> 8);
            final int blue = 0xff & (argb >> 0);

            if (red != green || red != blue) {
                return false;
            }
        }
    }
    return true;
}
 
源代码7 项目: jdk8u_jdk   文件: TestCompressionBI_BITFIELDS.java
protected void compareImages(BufferedImage src, BufferedImage dst) {
    ColorSpace srcCS = src.getColorModel().getColorSpace();
    ColorSpace dstCS = dst.getColorModel().getColorSpace();
    if (!srcCS.equals(dstCS) && srcCS.getType() == ColorSpace.TYPE_GRAY) {
        System.out.println("Workaround color difference with GRAY.");
        BufferedImage tmp  =
            new BufferedImage(src.getWidth(), src.getHeight(),
                              BufferedImage.TYPE_INT_RGB);
        Graphics g = tmp.createGraphics();
        g.drawImage(src, 0, 0, null);
        src = tmp;
    }
    int y = h / 2;
    for (int i = 0; i < colors.length; i++) {
        int x = dx * i + dx / 2;
        int srcRgb = src.getRGB(x, y);
        int dstRgb = dst.getRGB(x, y);

        if (srcRgb != dstRgb) {
            throw new RuntimeException("Test failed due to color difference: " +
                                       "src_pixel=" + Integer.toHexString(srcRgb) +
                                       "dst_pixel=" + Integer.toHexString(dstRgb));
        }
    }
}
 
源代码8 项目: dragonwell8_jdk   文件: JFIFMarkerSegment.java
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
 
源代码9 项目: openjdk-8-source   文件: JPEGImageWriter.java
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
        retval = JPEG.JCS_GRAYSCALE;
        break;
    case ColorSpace.TYPE_RGB:
        if (alpha) {
            retval = JPEG.JCS_RGBA;
        } else {
            retval = JPEG.JCS_RGB;
        }
        break;
    case ColorSpace.TYPE_YCbCr:
        if (alpha) {
            retval = JPEG.JCS_YCbCrA;
        } else {
            retval = JPEG.JCS_YCbCr;
        }
        break;
    case ColorSpace.TYPE_3CLR:
        if (cs == JPEG.JCS.getYCC()) {
            if (alpha) {
                retval = JPEG.JCS_YCCA;
            } else {
                retval = JPEG.JCS_YCC;
            }
        }
    case ColorSpace.TYPE_CMYK:
        retval = JPEG.JCS_CMYK;
        break;
    }
return retval;
}
 
源代码10 项目: jdk8u-jdk   文件: JPEGImageWriter.java
private int getSrcCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        switch (cs.getType()) {
        case ColorSpace.TYPE_GRAY:
            retval = JPEG.JCS_GRAYSCALE;
            break;
        case ColorSpace.TYPE_RGB:
            if (alpha) {
                retval = JPEG.JCS_RGBA;
            } else {
                retval = JPEG.JCS_RGB;
            }
            break;
        case ColorSpace.TYPE_YCbCr:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            break;
        case ColorSpace.TYPE_3CLR:
            if (cs == JPEG.JCS.getYCC()) {
                if (alpha) {
                    retval = JPEG.JCS_YCCA;
                } else {
                    retval = JPEG.JCS_YCC;
                }
            }
        case ColorSpace.TYPE_CMYK:
            retval = JPEG.JCS_CMYK;
            break;
        }
    }
    return retval;
}
 
源代码11 项目: hottub   文件: BufferedBufImgOps.java
/**************************** RescaleOp support *****************************/

    public static boolean isRescaleOpValid(RescaleOp rop,
                                           BufferedImage srcImg)
    {
        int numFactors = rop.getNumFactors();
        ColorModel srcCM = srcImg.getColorModel();

        if (srcCM instanceof IndexColorModel) {
            throw new
                IllegalArgumentException("Rescaling cannot be "+
                                         "performed on an indexed image");
        }
        if (numFactors != 1 &&
            numFactors != srcCM.getNumColorComponents() &&
            numFactors != srcCM.getNumComponents())
        {
            throw new IllegalArgumentException("Number of scaling constants "+
                                               "does not equal the number of"+
                                               " of color or color/alpha "+
                                               " components");
        }

        int csType = srcCM.getColorSpace().getType();
        if (csType != ColorSpace.TYPE_RGB &&
            csType != ColorSpace.TYPE_GRAY)
        {
            // Not prepared to deal with other color spaces
            return false;
        }

        if (numFactors == 2 || numFactors > 4) {
            // Not really prepared to handle this at the native level, so...
            return false;
        }

        return true;
    }
 
源代码12 项目: openjdk-8-source   文件: JPEGImageWriter.java
private int getDefaultDestCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        switch (cs.getType()) {
        case ColorSpace.TYPE_GRAY:
            retval = JPEG.JCS_GRAYSCALE;
            break;
        case ColorSpace.TYPE_RGB:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            break;
        case ColorSpace.TYPE_YCbCr:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            break;
        case ColorSpace.TYPE_3CLR:
            if (cs == JPEG.JCS.getYCC()) {
                if (alpha) {
                    retval = JPEG.JCS_YCCA;
                } else {
                    retval = JPEG.JCS_YCC;
                }
            }
        case ColorSpace.TYPE_CMYK:
            retval = JPEG.JCS_YCCK;
            break;
        }
    }
    return retval;
}
 
源代码13 项目: jdk8u-dev-jdk   文件: JPEGImageWriter.java
private int getDefaultDestCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        switch (cs.getType()) {
        case ColorSpace.TYPE_GRAY:
            retval = JPEG.JCS_GRAYSCALE;
            break;
        case ColorSpace.TYPE_RGB:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            break;
        case ColorSpace.TYPE_YCbCr:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            break;
        case ColorSpace.TYPE_3CLR:
            if (cs == JPEG.JCS.getYCC()) {
                if (alpha) {
                    retval = JPEG.JCS_YCCA;
                } else {
                    retval = JPEG.JCS_YCC;
                }
            }
        case ColorSpace.TYPE_CMYK:
            retval = JPEG.JCS_YCCK;
            break;
        }
    }
    return retval;
}
 
源代码14 项目: jdk8u60   文件: ComponentColorModel.java
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];
            }
        }
    }
}
 
源代码15 项目: openjdk-jdk8u-backup   文件: ComponentColorModel.java
/**
 * 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.
 * The returned value is in a non pre-multiplied format. If
 * the alpha is premultiplied, this method divides it out of the
 * color components (if the alpha value is 0, the color values will be 0).
 * Since <code>ComponentColorModel</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 pixel from which you want to get the color/alpha components,
 * specified by an array of data elements of type <CODE>transferType</CODE>.
 *
 * @return The color/alpha components for the specified pixel, as an int.
 *
 * @throws ClassCastException If <CODE>inData</CODE> is not a primitive array
 * of type <CODE>transferType</CODE>.
 * @throws ArrayIndexOutOfBoundsException if <CODE>inData</CODE> is not
 * large enough to hold a pixel value for this
 * <CODE>ColorModel</CODE>.
 * @throws UnsupportedOperationException If the transfer type of
 * this <CODE>ComponentColorModel</CODE>
 * is not one of the supported transfer types:
 * <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 ColorModel#getRGBdefault
 */
public int getRGB(Object inData) {
    if (needScaleInit) {
        initScale();
    }
    if (is_sRGB_stdScale || is_LinearRGB_stdScale) {
        return (getAlpha(inData) << 24)
            | (getRed(inData) << 16)
            | (getGreen(inData) << 8)
            | (getBlue(inData));
    } else if (colorSpaceType == ColorSpace.TYPE_GRAY) {
        int gray = getRed(inData); // Red sRGB component should equal
                                   // green and blue components
        return (getAlpha(inData) << 24)
            | (gray << 16)
            | (gray <<  8)
            | gray;
    }
    float[] norm = getNormalizedComponents(inData, null, 0);
    // Note that getNormalizedComponents returns non-premult values
    float[] rgb = colorSpace.toRGB(norm);
    return (getAlpha(inData) << 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);
}
 
源代码16 项目: hottub   文件: ComponentColorModel.java
/**
 * 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.
 * The returned value is in a non pre-multiplied format. If
 * the alpha is premultiplied, this method divides it out of the
 * color components (if the alpha value is 0, the color values will be 0).
 * Since <code>ComponentColorModel</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 pixel from which you want to get the color/alpha components,
 * specified by an array of data elements of type <CODE>transferType</CODE>.
 *
 * @return The color/alpha components for the specified pixel, as an int.
 *
 * @throws ClassCastException If <CODE>inData</CODE> is not a primitive array
 * of type <CODE>transferType</CODE>.
 * @throws ArrayIndexOutOfBoundsException if <CODE>inData</CODE> is not
 * large enough to hold a pixel value for this
 * <CODE>ColorModel</CODE>.
 * @throws UnsupportedOperationException If the transfer type of
 * this <CODE>ComponentColorModel</CODE>
 * is not one of the supported transfer types:
 * <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 ColorModel#getRGBdefault
 */
public int getRGB(Object inData) {
    if (needScaleInit) {
        initScale();
    }
    if (is_sRGB_stdScale || is_LinearRGB_stdScale) {
        return (getAlpha(inData) << 24)
            | (getRed(inData) << 16)
            | (getGreen(inData) << 8)
            | (getBlue(inData));
    } else if (colorSpaceType == ColorSpace.TYPE_GRAY) {
        int gray = getRed(inData); // Red sRGB component should equal
                                   // green and blue components
        return (getAlpha(inData) << 24)
            | (gray << 16)
            | (gray <<  8)
            | gray;
    }
    float[] norm = getNormalizedComponents(inData, null, 0);
    // Note that getNormalizedComponents returns non-premult values
    float[] rgb = colorSpace.toRGB(norm);
    return (getAlpha(inData) << 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);
}
 
源代码17 项目: openjdk-8   文件: X11SurfaceData.java
public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
                                         int transparency,
                                         boolean pixmapSurface)
{
    boolean transparent = (transparency == Transparency.BITMASK);
    SurfaceType sType;
    ColorModel cm = gc.getColorModel();
    switch (cm.getPixelSize()) {
    case 24:
        if (gc.getBitsPerPixel() == 24) {
            if (cm instanceof DirectColorModel) {
                // 4517321: We will always use ThreeByteBgr for 24 bpp
                // surfaces, regardless of the pixel masks reported by
                // X11.  Despite ambiguity in the X11 spec in how 24 bpp
                // surfaces are treated, it appears that the best
                // SurfaceType for these configurations (including
                // some Matrox Millenium and ATI Radeon boards) is
                // ThreeByteBgr.
                sType = transparent ? X11SurfaceData.ThreeByteBgrX11_BM : X11SurfaceData.ThreeByteBgrX11;
            } else {
                throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                          "depth/cm combo: " +
                                                          cm.getPixelSize()  +
                                                          ", " + cm);
            }
            break;
        }
        // Fall through for 32 bit case
    case 32:
        if (cm instanceof DirectColorModel) {
            if (((SunToolkit)java.awt.Toolkit.getDefaultToolkit()
                 ).isTranslucencyCapable(gc) && !pixmapSurface)
            {
                sType = X11SurfaceData.IntArgbPreX11;
            } else {
                if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
                    sType = transparent ? X11SurfaceData.IntRgbX11_BM :
                                          X11SurfaceData.IntRgbX11;
                } else {
                    sType = transparent ? X11SurfaceData.IntBgrX11_BM :
                                          X11SurfaceData.IntBgrX11;
                }
            }
        } else if (cm instanceof ComponentColorModel) {
               sType = X11SurfaceData.FourByteAbgrPreX11;
        } else {

            throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                      "depth/cm combo: " +
                                                      cm.getPixelSize()  +
                                                      ", " + cm);
        }
        break;
    case 15:
        sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
        break;
    case 16:
        if ((cm instanceof DirectColorModel) &&
            (((DirectColorModel)cm).getGreenMask() == 0x3e0))
        {
            // fix for 4352984: Riva128 on Linux
            sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
        } else {
            sType = transparent ? X11SurfaceData.UShort565RgbX11_BM : X11SurfaceData.UShort565RgbX11;
        }
        break;
    case  12:
        if (cm instanceof IndexColorModel) {
            sType = transparent ?
                X11SurfaceData.UShortIndexedX11_BM :
                X11SurfaceData.UShortIndexedX11;
        } else {
            throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                      "depth: " +
                                                      cm.getPixelSize() +
                                                      " cm="+cm);
        }
        break;
    case 8:
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY &&
            cm instanceof ComponentColorModel) {
            sType = transparent ? X11SurfaceData.ByteGrayX11_BM : X11SurfaceData.ByteGrayX11;
        } else if (cm instanceof IndexColorModel &&
                   isOpaqueGray((IndexColorModel)cm)) {
            sType = transparent ? X11SurfaceData.Index8GrayX11_BM : X11SurfaceData.Index8GrayX11;
        } else {
            sType = transparent ? X11SurfaceData.ByteIndexedX11_BM : X11SurfaceData.ByteIndexedOpaqueX11;
        }
        break;
    default:
        throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                  "depth: " +
                                                  cm.getPixelSize());
    }
    return sType;
}
 
源代码18 项目: jdk8u-dev-jdk   文件: ComponentColorModel.java
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];
            }
        }
    }
}
 
源代码19 项目: openjdk-8-source   文件: ComponentColorModel.java
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];
            }
        }
    }
}
 
源代码20 项目: openjdk-8-source   文件: X11SurfaceData.java
public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
                                         int transparency,
                                         boolean pixmapSurface)
{
    boolean transparent = (transparency == Transparency.BITMASK);
    SurfaceType sType;
    ColorModel cm = gc.getColorModel();
    switch (cm.getPixelSize()) {
    case 24:
        if (gc.getBitsPerPixel() == 24) {
            if (cm instanceof DirectColorModel) {
                // 4517321: We will always use ThreeByteBgr for 24 bpp
                // surfaces, regardless of the pixel masks reported by
                // X11.  Despite ambiguity in the X11 spec in how 24 bpp
                // surfaces are treated, it appears that the best
                // SurfaceType for these configurations (including
                // some Matrox Millenium and ATI Radeon boards) is
                // ThreeByteBgr.
                sType = transparent ? X11SurfaceData.ThreeByteBgrX11_BM : X11SurfaceData.ThreeByteBgrX11;
            } else {
                throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                          "depth/cm combo: " +
                                                          cm.getPixelSize()  +
                                                          ", " + cm);
            }
            break;
        }
        // Fall through for 32 bit case
    case 32:
        if (cm instanceof DirectColorModel) {
            if (((SunToolkit)java.awt.Toolkit.getDefaultToolkit()
                 ).isTranslucencyCapable(gc) && !pixmapSurface)
            {
                sType = X11SurfaceData.IntArgbPreX11;
            } else {
                if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
                    sType = transparent ? X11SurfaceData.IntRgbX11_BM :
                                          X11SurfaceData.IntRgbX11;
                } else {
                    sType = transparent ? X11SurfaceData.IntBgrX11_BM :
                                          X11SurfaceData.IntBgrX11;
                }
            }
        } else if (cm instanceof ComponentColorModel) {
               sType = X11SurfaceData.FourByteAbgrPreX11;
        } else {

            throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                      "depth/cm combo: " +
                                                      cm.getPixelSize()  +
                                                      ", " + cm);
        }
        break;
    case 15:
        sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
        break;
    case 16:
        if ((cm instanceof DirectColorModel) &&
            (((DirectColorModel)cm).getGreenMask() == 0x3e0))
        {
            // fix for 4352984: Riva128 on Linux
            sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
        } else {
            sType = transparent ? X11SurfaceData.UShort565RgbX11_BM : X11SurfaceData.UShort565RgbX11;
        }
        break;
    case  12:
        if (cm instanceof IndexColorModel) {
            sType = transparent ?
                X11SurfaceData.UShortIndexedX11_BM :
                X11SurfaceData.UShortIndexedX11;
        } else {
            throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                      "depth: " +
                                                      cm.getPixelSize() +
                                                      " cm="+cm);
        }
        break;
    case 8:
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY &&
            cm instanceof ComponentColorModel) {
            sType = transparent ? X11SurfaceData.ByteGrayX11_BM : X11SurfaceData.ByteGrayX11;
        } else if (cm instanceof IndexColorModel &&
                   isOpaqueGray((IndexColorModel)cm)) {
            sType = transparent ? X11SurfaceData.Index8GrayX11_BM : X11SurfaceData.Index8GrayX11;
        } else {
            sType = transparent ? X11SurfaceData.ByteIndexedX11_BM : X11SurfaceData.ByteIndexedOpaqueX11;
        }
        break;
    default:
        throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                  "depth: " +
                                                  cm.getPixelSize());
    }
    return sType;
}