Java 类java.awt.color.ColorSpace 实例源码

项目:openjdk-jdk10    文件: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();
    }
}
项目:openjdk-jdk10    文件: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));
        }
    }
}
项目:openjdk-jdk10    文件:Color.java   
/**
 * Returns a {@code float} array containing only the color
 * components of the {@code Color} in the
 * {@code ColorSpace} specified by the {@code cspace}
 * parameter. If {@code compArray} is {@code null}, an array
 * with length equal to the number of components in
 * {@code cspace} is created for the return value.  Otherwise,
 * {@code compArray} must have at least this length, and it is
 * filled in with the components and returned.
 * @param cspace a specified {@code ColorSpace}
 * @param compArray an array that this method fills with the color
 *          components of this {@code Color} in the specified
 *          {@code ColorSpace}
 * @return the color components in a {@code float} array.
 */
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
    if (cs == null) {
        cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    }
    float f[];
    if (fvalue == null) {
        f = new float[3];
        f[0] = ((float)getRed())/255f;
        f[1] = ((float)getGreen())/255f;
        f[2] = ((float)getBlue())/255f;
    } else {
        f = fvalue;
    }
    float tmp[] = cs.toCIEXYZ(f);
    float tmpout[] = cspace.fromCIEXYZ(tmp);
    if (compArray == null) {
        return tmpout;
    }
    for (int i = 0 ; i < tmpout.length ; i++) {
        compArray[i] = tmpout[i];
    }
    return compArray;
}
项目:OpenJSharp    文件:Color.java   
/**
 * Returns a <code>float</code> array containing only the color
 * components of the <code>Color</code> in the
 * <code>ColorSpace</code> specified by the <code>cspace</code>
 * parameter. If <code>compArray</code> is <code>null</code>, an array
 * with length equal to the number of components in
 * <code>cspace</code> is created for the return value.  Otherwise,
 * <code>compArray</code> must have at least this length, and it is
 * filled in with the components and returned.
 * @param cspace a specified <code>ColorSpace</code>
 * @param compArray an array that this method fills with the color
 *          components of this <code>Color</code> in the specified
 *          <code>ColorSpace</code>
 * @return the color components in a <code>float</code> array.
 */
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
    if (cs == null) {
        cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    }
    float f[];
    if (fvalue == null) {
        f = new float[3];
        f[0] = ((float)getRed())/255f;
        f[1] = ((float)getGreen())/255f;
        f[2] = ((float)getBlue())/255f;
    } else {
        f = fvalue;
    }
    float tmp[] = cs.toCIEXYZ(f);
    float tmpout[] = cspace.fromCIEXYZ(tmp);
    if (compArray == null) {
        return tmpout;
    }
    for (int i = 0 ; i < tmpout.length ; i++) {
        compArray[i] = tmpout[i];
    }
    return compArray;
}
项目:OpenJSharp    文件:ComponentColorModel.java   
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;
}
项目:openjdk-jdk10    文件:WGLGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:jdk8u-jdk    文件: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;
}
项目:jdk8u-jdk    文件:GLXGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:OpenJSharp    文件: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;
}
项目:imagingbook-common    文件:LabColorSpace.java   
public static void main(String[] args) {
    int sr = 128;
    int sg = 1;
    int sb = 128;
    System.out.format("Input (sRGB) = %d, %d, %d\n", sr, sg, sb);
    System.out.format("XYZref = %10g, %10g, %10g\n", Xref,Yref,Zref);

    ColorSpace cs = new LabColorSpace();
    //float[] luv = cs.fromCIEXYZ(new float[] {.1f,.5f,.9f});
    float[] lab = cs.fromRGB(new float[] {sr/255f, sg/255f, sb/255f});

    System.out.format("Lab = %8f, %8f, %8f\n", lab[0],lab[2],lab[2]);
    //float[] xyz = cs.toCIEXYZ(luv);
    float[] srgb = cs.toRGB(lab);
    System.out.format("sRGB = %8f, %8f, %8f\n", 
            Math.rint(255*srgb[0]), Math.rint(255*srgb[1]), Math.rint(255*srgb[2]));
}
项目:OpenJSharp    文件: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();
    }
}
项目:openjdk-jdk10    文件:UNIXToolkit.java   
/**
 * This method is used by JNI as a callback from load_stock_icon.
 * Image data is passed back to us via this method and loaded into the
 * local BufferedImage and then returned via getStockIcon.
 *
 * Do NOT call this method directly.
 */
public void loadIconCallback(byte[] data, int width, int height,
        int rowStride, int bps, int channels, boolean alpha) {
    // Reset the stock image to null.
    tmpImage = null;

    // Create a new BufferedImage based on the data returned from the
    // JNI call.
    DataBuffer dataBuf = new DataBufferByte(data, (rowStride * height));
    // Maybe test # channels to determine band offsets?
    WritableRaster raster = Raster.createInterleavedRaster(dataBuf,
            width, height, rowStride, channels,
            (alpha ? BAND_OFFSETS_ALPHA : BAND_OFFSETS), null);
    ColorModel colorModel = new ComponentColorModel(
            ColorSpace.getInstance(ColorSpace.CS_sRGB), alpha, false,
            ColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);

    // Set the local image so we can return it later from
    // getStockIcon().
    tmpImage = new BufferedImage(colorModel, raster, false, null);
}
项目:OpenJSharp    文件:CGLGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:OpenJSharp    文件:D3DGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:OpenJSharp    文件:UNIXToolkit.java   
/**
 * This method is used by JNI as a callback from load_stock_icon.
 * Image data is passed back to us via this method and loaded into the
 * local BufferedImage and then returned via getStockIcon.
 *
 * Do NOT call this method directly.
 */
public void loadIconCallback(byte[] data, int width, int height,
        int rowStride, int bps, int channels, boolean alpha) {
    // Reset the stock image to null.
    tmpImage = null;

    // Create a new BufferedImage based on the data returned from the
    // JNI call.
    DataBuffer dataBuf = new DataBufferByte(data, (rowStride * height));
    // Maybe test # channels to determine band offsets?
    WritableRaster raster = Raster.createInterleavedRaster(dataBuf,
            width, height, rowStride, channels,
            (alpha ? BAND_OFFSETS_ALPHA : BAND_OFFSETS), null);
    ColorModel colorModel = new ComponentColorModel(
            ColorSpace.getInstance(ColorSpace.CS_sRGB), alpha, false,
            ColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);

    // Set the local image so we can return it later from
    // getStockIcon().
    tmpImage = new BufferedImage(colorModel, raster, false, null);
}
项目:openjdk-jdk10    文件:GLXGraphicsConfig.java   
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
项目:ServerlessPlatform    文件:ImageService.java   
public void blackNWhite(String link, String email) throws Exception{
    try{
        download(link);
        doLogging("Request came for blackNWhite ", "INFO");
        String outPath=null;
        String fileName=null;
        String imageName = null;
        int lastSlashIndex = link.lastIndexOf('/');
        imageName = link.substring(lastSlashIndex + 1);
        String path = Path+imageName;
        BufferedImage src = ImageIO.read(new File(path));
        ColorConvertOp op =new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
        BufferedImage dest = op.filter(src, null);
        fileName = path.substring(path.lastIndexOf("/")+1);
        path = path.substring(0, path.lastIndexOf("/")+1);
        outPath=path+"BNW_"+fileName;
        ImageIO.write(dest, "jpg", new File(outPath));
        sendMail(outPath, email);
    }
    catch(Exception e){
        doLogging("Failed somewhere "+e.getMessage()+e.getStackTrace(), "Error");
    }

}
项目:jdk8u-jdk    文件:DataConversionTests.java   
public Context(TestEnvironment env, Result result, ColorSpace cs) {
    this.cs = cs;
    this.env = env;
    this.res = result;

    numComponents = cs.getNumComponents();

    val = new float[numComponents];

    for (int i = 0; i < numComponents; i++) {
        float min = cs.getMinValue(i);
        float max = cs.getMaxValue(i);

        val[i] = 0.5f * (max - min);
    }

    rgb = new float[]{0.5f, 0.5f, 0.5f};
    cie = new float[]{0.5f, 0.5f, 0.5f};
}
项目:jdk8u-jdk    文件:ImageTypeSpecifier.java   
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
项目:openjdk-jdk10    文件:ImageTypeSpecifier.java   
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
项目:incubator-netbeans    文件:ImageBuilder.java   
@Override
public ColorModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int bits = fa.getInt(instance, "pixel_bits"); // NOI18N
    int rmask = fa.getInt(instance, "red_mask"); // NOI18N
    int gmask = fa.getInt(instance, "green_mask"); // NOI18N
    int bmask = fa.getInt(instance, "blue_mask"); // NOI18N
    int amask = fa.getInt(instance, "alpha_mask"); // NOI18N
    boolean ap = fa.getBoolean(instance, "isAlphaPremultiplied"); // NOI18N
    int transferType = fa.getInt(instance, "transferType"); // NOI18N
    return new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), bits, rmask, gmask, bmask, amask, ap, transferType);
}
项目:incubator-netbeans    文件:ImageBuilder.java   
@Override
public ColorModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int[] bits = fa.getIntArray(instance, "nBits", false);// NOI18N
    int transparency = fa.getInt(instance, "transparency"); // NOI18N
    boolean hasAlpha = fa.getBoolean(instance, "supportsAlpha"); // NOI18N
    boolean ap = fa.getBoolean(instance, "isAlphaPremultiplied"); // NOI18N
    int transferType = fa.getInt(instance, "transferType"); // NOI18N
    return new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), bits, hasAlpha, ap, transparency, transferType);
}
项目:openjdk-jdk10    文件:JPEG.java   
/**
 * Returns {@code true} if the given {@code ColorSpace}
 * object is an instance of ICC_ColorSpace but is not one of the
 * standard {@code ColorSpaces} returned by
 * {@code ColorSpace.getInstance()}.
 */
static boolean isNonStandardICC(ColorSpace cs) {
    boolean retval = false;
    if ((cs instanceof ICC_ColorSpace)
        && (!cs.isCS_sRGB())
        && (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_CIEXYZ)))
        && (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_GRAY)))
        && (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB)))
        && (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_PYCC)))
        ) {
        retval = true;
    }
    return retval;
}
项目:GlitchKernel    文件:DataAsSound.java   
@Override
public byte[] glitchPixels(byte[] inputImageBytes) throws Exception 
{
    int audioBitRate = ((Integer) getPixelGlitchParameters().get("bitRateBlend")).intValue();
    float bitRateBlend = (float) audioBitRate / 10;
    if(bitRateBlend < 0.1F || bitRateBlend > 0.9F)
    {
        return null;
    }

    BufferedImage inputImage = ImageUtil.getImageFromBytes(inputImageBytes);
    InputStream imageInputStream = new ByteArrayInputStream(inputImageBytes);
    AudioInputStream distortionAudioStream = new AudioInputStream(imageInputStream, new AudioFormat(AudioFormat.Encoding.ULAW, ThreadLocalRandom.current().nextInt(8000,  20000), 8, 5, 9, ThreadLocalRandom.current().nextInt(8000,  20000), true), inputImageBytes.length);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    AudioSystem.write(distortionAudioStream, Type.WAVE, outputStream);
    BufferedImage outputImage = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
    byte[] imageData = ((DataBufferByte) outputImage.getRaster().getDataBuffer()).getData();
    System.arraycopy(outputStream.toByteArray(),0,imageData,0,outputStream.toByteArray().length);
    int[] abgrOffsets = {3, 2, 1, 0}; 
    DataBuffer outputBuffer = new DataBufferByte(imageData, imageData.length);
    WritableRaster raster = Raster.createInterleavedRaster(outputBuffer, inputImage.getWidth(), inputImage.getHeight(), 4 * inputImage.getWidth(), 4, abgrOffsets, null);
    ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    BufferedImage rasterizedImage = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
    rasterizedImage = resizeImage(rasterizedImage, inputImage.getWidth() * 4, inputImage.getHeight() * 4);
    Graphics2D g2d = rasterizedImage.createGraphics();
    g2d.setComposite(AlphaComposite.SrcOver.derive(bitRateBlend));
    g2d.drawImage(inputImage, 0, 0, null);
    g2d.dispose();
    rasterizedImage = rasterizedImage.getSubimage(0, 0, inputImage.getWidth(), inputImage.getHeight());
    return ImageUtil.getImageBytes(rasterizedImage);
}
项目:openjdk-jdk10    文件:EqualHashCodeTest.java   
public static void main(String[] args) throws Exception {
    boolean passed = true;
    try {
        df1 = new DataFlavor( "application/postscript" );
        df2 = new DataFlavor( "application/*" );
    } catch (ClassNotFoundException e1) {
        throw new RuntimeException("Could not create DataFlavors. This should never happen.");
    } catch (IllegalArgumentException e2) {
        passed = false;
    }
    if (df1.hashCode() != df2.hashCode()) {
        passed = false;
    }
    dim1 = new Dimension(3, 18);
    dim2 = new Dimension(3, 18);
    if (dim1.hashCode() != dim2.hashCode()) {
        passed = false;
    }
    insets1 = new Insets(3, 4, 7, 11);
    insets2 = new Insets(3, 4, 7, 11);
    if (insets1.hashCode() != insets2.hashCode()) {
        passed = false;
    }
    cm1 = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                  ColorModelBits, true, true,
                                  Transparency.OPAQUE, 0);
    cm2 = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                  ColorModelBits, true, true,
                                  Transparency.OPAQUE, 0);
    if (cm1.hashCode() != cm2.hashCode()) {
        passed = false;
    }
    if (!passed)
        throw new RuntimeException("Test FAILED");
}
项目:openjdk-jdk10    文件:AlphaTest.java   
public static void main(String[] args) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);

    ColorConvertOp op = new ColorConvertOp(cs, null);
    // create source image filled with an opaque color
    BufferedImage src = createSrc();
    int srcAlpha = getAlpha(src);

    System.out.printf("Src alpha: 0x%02x\n", srcAlpha);

    // create clear (transparent black) destination image
    BufferedImage dst = createDst();
    int dstAlpha = getAlpha(dst);
    System.out.printf("Dst alpha: 0x%02x\n", dstAlpha);


    dst = op.filter(src, dst);
    dstAlpha = getAlpha(dst);
    // we expect that destination image is opaque
    // i.e. alpha is transferred from source to
    // the destination
    System.out.printf("Result alpha: 0x%02x\n", dstAlpha);

    if (srcAlpha != dstAlpha) {
        throw new RuntimeException("Test failed!");
    }
    System.out.println("Test passed");
}
项目:OpenJSharp    文件:CMMTests.java   
protected static ColorSpace getColorSpace(TestEnvironment env) {
    ColorSpace cs;
    Boolean usePlatfrom = true; //(Boolean)env.getModifier(usePlatfromProfiles);

    int cs_code = env.getIntValue(csList);
    if (usePlatfrom) {
        cs = ColorSpace.getInstance(cs_code);
    } else {
        String resource = "profiles/";
        switch (cs_code) {
            case ColorSpace.CS_CIEXYZ:
                resource += "CIEXYZ.pf";
                break;
            case ColorSpace.CS_GRAY:
                resource += "GRAY.pf";
                break;
            case ColorSpace.CS_LINEAR_RGB:
                resource += "LINEAR_RGB.pf";
                break;
            case ColorSpace.CS_PYCC:
                resource += "PYCC.pf";
                break;
            case ColorSpace.CS_sRGB:
                resource += "sRGB.pf";
                break;
            default:
                throw new RuntimeException("Unknown color space: " + cs_code);
        }

        try {
            InputStream is = CMMTests.class.getResourceAsStream(resource);
            ICC_Profile p = ICC_Profile.getInstance(is);

            cs = new ICC_ColorSpace(p);
        } catch (IOException e) {
            throw new RuntimeException("Unable load profile from resource " + resource, e);
        }
    }
    return cs;
}
项目:jdk8u-jdk    文件:X11GraphicsConfig.java   
public static ComponentColorModel createABGRCCM() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = {8, 8, 8, 8};
    int[] bOffs = {3, 2, 1, 0};
    return new ComponentColorModel(cs, nBits, true, true,
                                   Transparency.TRANSLUCENT,
                                   DataBuffer.TYPE_BYTE);
}
项目:openjdk-jdk10    文件:BMPSubsamplingTest.java   
private BufferedImage create3ByteImage(int[] nBits, int[] bOffs) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel =
        new ComponentColorModel(cs, nBits,
                                false, false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    WritableRaster raster =
        Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                                       w, h,
                                       w*3, 3,
                                       bOffs, null);
    return new BufferedImage(colorModel, raster, false, null);
}
项目:openjdk-jdk10    文件:IndexingTest.java   
protected static ComponentColorModel createBitmaskColorModel() {
    ComponentColorModel cm =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                true, false, Transparency.BITMASK,
                                DataBuffer.TYPE_BYTE);
    return cm;
}
项目:OpenJSharp    文件:DataConversionTests.java   
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context) ctx;
    final ColorSpace cs = ictx.cs;

    final float[] val = ictx.cie;
    do {
        try {
            cs.fromCIEXYZ(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
项目:OpenJSharp    文件:DataConversionTests.java   
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context) ctx;
    final ColorSpace cs = ictx.cs;

    final float[] val = ictx.val;

    do {
        try {
            cs.toCIEXYZ(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
项目:OpenJSharp    文件:Color.java   
/**
 * Returns a <code>float</code> array containing the color and alpha
 * components of the <code>Color</code>, in the
 * <code>ColorSpace</code> specified by the <code>cspace</code>
 * parameter.  If <code>compArray</code> is <code>null</code>, an
 * array with length equal to the number of components in
 * <code>cspace</code> plus one is created for the return value.
 * Otherwise, <code>compArray</code> must have at least this
 * length, and it is filled in with the components and returned.
 * @param cspace a specified <code>ColorSpace</code>
 * @param compArray an array that this method fills with the
 *          color and alpha components of this <code>Color</code> in
 *          the specified <code>ColorSpace</code> and returns
 * @return the color and alpha components in a <code>float</code>
 *          array.
 */
public float[] getComponents(ColorSpace cspace, float[] compArray) {
    if (cs == null) {
        cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    }
    float f[];
    if (fvalue == null) {
        f = new float[3];
        f[0] = ((float)getRed())/255f;
        f[1] = ((float)getGreen())/255f;
        f[2] = ((float)getBlue())/255f;
    } else {
        f = fvalue;
    }
    float tmp[] = cs.toCIEXYZ(f);
    float tmpout[] = cspace.fromCIEXYZ(tmp);
    if (compArray == null) {
        compArray = new float[tmpout.length + 1];
    }
    for (int i = 0 ; i < tmpout.length ; i++) {
        compArray[i] = tmpout[i];
    }
    if (fvalue == null) {
        compArray[tmpout.length] = ((float)getAlpha())/255f;
    } else {
        compArray[tmpout.length] = falpha;
    }
    return compArray;
}
项目:openjdk-jdk10    文件:Color.java   
/**
 * Creates a color in the specified {@code ColorSpace}
 * with the color components specified in the {@code float}
 * array and the specified alpha.  The number of components is
 * determined by the type of the {@code ColorSpace}.  For
 * example, RGB requires 3 components, but CMYK requires 4
 * components.
 * @param cspace the {@code ColorSpace} to be used to
 *                  interpret the components
 * @param components an arbitrary number of color components
 *                      that is compatible with the {@code ColorSpace}
 * @param alpha alpha value
 * @throws IllegalArgumentException if any of the values in the
 *         {@code components} array or {@code alpha} is
 *         outside of the range 0.0 to 1.0
 * @see #getComponents
 * @see #getColorComponents
 */
public Color(ColorSpace cspace, float components[], float alpha) {
    boolean rangeError = false;
    String badComponentString = "";
    int n = cspace.getNumComponents();
    fvalue = new float[n];
    for (int i = 0; i < n; i++) {
        if (components[i] < 0.0 || components[i] > 1.0) {
            rangeError = true;
            badComponentString = badComponentString + "Component " + i
                                 + " ";
        } else {
            fvalue[i] = components[i];
        }
    }
    if (alpha < 0.0 || alpha > 1.0) {
        rangeError = true;
        badComponentString = badComponentString + "Alpha";
    } else {
        falpha = alpha;
    }
    if (rangeError) {
        throw new IllegalArgumentException(
            "Color parameter outside of expected range: " +
            badComponentString);
    }
    frgbvalue = cspace.toRGB(fvalue);
    cs = cspace;
    value = ((((int)(falpha*255)) & 0xFF) << 24) |
            ((((int)(frgbvalue[0]*255)) & 0xFF) << 16) |
            ((((int)(frgbvalue[1]*255)) & 0xFF) << 8)  |
            ((((int)(frgbvalue[2]*255)) & 0xFF) << 0);
}
项目:jdk8u-jdk    文件:JPEG.java   
public static ColorSpace getYCC() {
    if (!yccInited) {
        try {
            YCC = ColorSpace.getInstance(ColorSpace.CS_PYCC);
        } catch (IllegalArgumentException e) {
            // PYCC.pf may not always be installed
        } finally {
            yccInited = true;
        }
    }
    return YCC;
}
项目:openjdk-jdk10    文件:DataConversionTests.java   
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context) ctx;
    final ColorSpace cs = ictx.cs;

    final float[] rgb = ictx.rgb;
    do {
        try {
            cs.fromRGB(rgb);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
项目:OpenJSharp    文件:JPEG.java   
public static ColorSpace getYCC() {
    if (!yccInited) {
        try {
            YCC = ColorSpace.getInstance(ColorSpace.CS_PYCC);
        } catch (IllegalArgumentException e) {
            // PYCC.pf may not always be installed
        } finally {
            yccInited = true;
        }
    }
    return YCC;
}
项目:OpenJSharp    文件:JPEG.java   
/**
 * Returns <code>true</code> if the given <code>ColorSpace</code>
 * object is an instance of ICC_ColorSpace but is not one of the
 * standard <code>ColorSpaces</code> returned by
 * <code>ColorSpace.getInstance()</code>.
 */
static boolean isNonStandardICC(ColorSpace cs) {
    boolean retval = false;
    if ((cs instanceof ICC_ColorSpace)
        && (!cs.isCS_sRGB())
        && (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_CIEXYZ)))
        && (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_GRAY)))
        && (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB)))
        && (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_PYCC)))
        ) {
        retval = true;
    }
    return retval;
}
项目:openjdk-jdk10    文件:DataConversionTests.java   
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context) ctx;
    final ColorSpace cs = ictx.cs;

    final float[] val = ictx.cie;
    do {
        try {
            cs.fromCIEXYZ(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
项目:jdk8u-jdk    文件:RenderToCustomBufferTest.java   
private static BufferedImage createCustomBuffer() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm = new ComponentColorModel(cs, false, false,
            Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
    WritableRaster wr = cm.createCompatibleWritableRaster(width, height);

    return new BufferedImage(cm, wr, false, null);
}