Search in sources :

Example 6 with PixelInterleavedSampleModel

use of java.awt.image.PixelInterleavedSampleModel 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)

Aggregations

Point (java.awt.Point)6 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)6 SampleModel (java.awt.image.SampleModel)4 BufferedImage (java.awt.image.BufferedImage)3 WritableRaster (java.awt.image.WritableRaster)3 ColorModel (java.awt.image.ColorModel)2 DataBuffer (java.awt.image.DataBuffer)2 DataBufferByte (java.awt.image.DataBufferByte)2 DirectColorModel (java.awt.image.DirectColorModel)2 IndexColorModel (java.awt.image.IndexColorModel)2 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)2 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)2 Color (java.awt.Color)1 ColorSpace (java.awt.color.ColorSpace)1 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)1 AffineTransform (java.awt.geom.AffineTransform)1 ColorConvertOp (java.awt.image.ColorConvertOp)1 ComponentColorModel (java.awt.image.ComponentColorModel)1 ImagingOpException (java.awt.image.ImagingOpException)1 Raster (java.awt.image.Raster)1