Search in sources :

Example 11 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.

the class AlphaTest method main.

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");
}
Also used : ColorConvertOp(java.awt.image.ColorConvertOp) ColorSpace(java.awt.color.ColorSpace) BufferedImage(java.awt.image.BufferedImage)

Example 12 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.

the class ColConvDCMTest method testSubImage.

static boolean testSubImage(int x0, int y0, int dx, int dy, int type, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
Also used : ColorConvertOp(java.awt.image.ColorConvertOp) BufferedImage(java.awt.image.BufferedImage)

Example 13 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.

the class ColCvtAlpha method main.

public static void main(String[] args) {
    BufferedImage src = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);
    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }
    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] { 8, 8 }, true, src.getColorModel().isAlphaPremultiplied(), Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 100, 100, 2, 200, new int[] { 0, 1 });
    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0, 0));
    BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);
    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException("Incorrect destination alpha value.");
        }
    }
}
Also used : PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) SampleModel(java.awt.image.SampleModel) ColorConvertOp(java.awt.image.ColorConvertOp) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) WritableRaster(java.awt.image.WritableRaster) Color(java.awt.Color) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point)

Example 14 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.

the class ColCvtIntARGB method main.

public static void main(String[] args) {
    //
    // Build a 1 pixel ARGB, non-premultiplied image
    //
    BufferedImage src = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    // Set src pixel value
    Color pelColor = new Color(100, 100, 100, 128);
    src.setRGB(0, 0, pelColor.getRGB());
    //
    // ColorConvertOp filter
    //
    ColorConvertOp op = new ColorConvertOp(null);
    //
    // Test ARGB -> ARGB_PRE
    //
    BufferedImage dst = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
    op.filter(src, dst);
    if (((dst.getRGB(0, 0) >> 24) & 0xff) != 128) {
        throw new RuntimeException("Incorrect destination alpha value.");
    }
    //
    // Test ARGB -> ARGB
    //
    dst = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    op.filter(src, dst);
    if (((dst.getRGB(0, 0) >> 24) & 0xff) != 128) {
        throw new RuntimeException("Incorrect destination alpha value.");
    }
}
Also used : ColorConvertOp(java.awt.image.ColorConvertOp) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage)

Example 15 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.

the class InvalidRenderIntentTest method main.

public static void main(String[] args) {
    ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);
    byte[] raw_data = pSRGB.getData();
    setRenderingIntent(0x1000000, raw_data);
    ICC_Profile p = ICC_Profile.getInstance(raw_data);
    ICC_ColorSpace cs = new ICC_ColorSpace(p);
    // perfrom test color conversion
    ColorConvertOp op = new ColorConvertOp(cs, ColorSpace.getInstance(CS_sRGB), null);
    BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    try {
        op.filter(src.getRaster(), dst.getRaster());
    } catch (CMMException e) {
        throw new RuntimeException("Test failed.", e);
    }
    System.out.println("Test passed.");
}
Also used : ICC_ColorSpace(java.awt.color.ICC_ColorSpace) ColorConvertOp(java.awt.image.ColorConvertOp) ICC_Profile(java.awt.color.ICC_Profile) CMMException(java.awt.color.CMMException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ColorConvertOp (java.awt.image.ColorConvertOp)15 BufferedImage (java.awt.image.BufferedImage)14 ColorSpace (java.awt.color.ColorSpace)4 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)3 ColorModel (java.awt.image.ColorModel)3 Color (java.awt.Color)2 Point (java.awt.Point)2 IndexColorModel (java.awt.image.IndexColorModel)2 IIOException (javax.imageio.IIOException)2 Foundation (com.intellij.ui.mac.foundation.Foundation)1 ID (com.intellij.ui.mac.foundation.ID)1 Vector3f (com.jme3.math.Vector3f)1 Rectangle (java.awt.Rectangle)1 CMMException (java.awt.color.CMMException)1 ICC_Profile (java.awt.color.ICC_Profile)1 BufferedImageOp (java.awt.image.BufferedImageOp)1 ComponentColorModel (java.awt.image.ComponentColorModel)1 DataBufferByte (java.awt.image.DataBufferByte)1 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)1 RenderedImage (java.awt.image.RenderedImage)1