Search in sources :

Example 16 with ComponentColorModel

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

ComponentColorModel (java.awt.image.ComponentColorModel)16 ColorModel (java.awt.image.ColorModel)12 ColorSpace (java.awt.color.ColorSpace)9 BufferedImage (java.awt.image.BufferedImage)9 WritableRaster (java.awt.image.WritableRaster)7 DirectColorModel (java.awt.image.DirectColorModel)6 IndexColorModel (java.awt.image.IndexColorModel)5 Point (java.awt.Point)4 Graphics2D (java.awt.Graphics2D)2 ComponentSampleModel (java.awt.image.ComponentSampleModel)2 DataBufferByte (java.awt.image.DataBufferByte)2 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)2 SampleModel (java.awt.image.SampleModel)2 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)2 Color (java.awt.Color)1 Graphics (java.awt.Graphics)1 AffineTransform (java.awt.geom.AffineTransform)1 ColorConvertOp (java.awt.image.ColorConvertOp)1 DataBuffer (java.awt.image.DataBuffer)1 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)1