Search in sources :

Example 96 with ColorModel

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

the class GLXGraphicsConfig method createCompatibleImage.

@Override
public BufferedImage createCompatibleImage(int width, int height) {
    ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    WritableRaster raster = model.createCompatibleWritableRaster(width, height);
    return new BufferedImage(model, raster, model.isAlphaPremultiplied(), null);
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) DirectColorModel(java.awt.image.DirectColorModel) BufferedImage(java.awt.image.BufferedImage)

Example 97 with ColorModel

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

the class GLXGraphicsConfig method createAcceleratedImage.

/**
     * Creates a new hidden-acceleration image of the given width and height
     * that is associated with the target Component.
     */
@Override
public Image createAcceleratedImage(Component target, int width, int height) {
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr = model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied());
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) OffScreenImage(sun.awt.image.OffScreenImage)

Example 98 with ColorModel

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

the class X11GraphicsConfig method createAcceleratedImage.

/**
     * Creates a new hidden-acceleration image of the given width and height
     * that is associated with the target Component.
     */
public Image createAcceleratedImage(Component target, int width, int height) {
    // As of 1.7 we no longer create pmoffscreens here...
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr = model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied());
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) OffScreenImage(sun.awt.image.OffScreenImage)

Example 99 with ColorModel

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

the class WGLVolatileSurfaceManager method initAcceleratedSurface.

/**
     * Create a pbuffer-based SurfaceData object (or init the backbuffer
     * of an existing window if this is a double buffered GraphicsConfig).
     */
protected SurfaceData initAcceleratedSurface() {
    SurfaceData sData;
    Component comp = vImg.getComponent();
    WComponentPeer peer = (comp != null) ? (WComponentPeer) comp.getPeer() : null;
    try {
        boolean createVSynced = false;
        boolean forceback = false;
        if (context instanceof Boolean) {
            forceback = ((Boolean) context).booleanValue();
            if (forceback) {
                BufferCapabilities caps = peer.getBackBufferCaps();
                if (caps instanceof ExtendedBufferCapabilities) {
                    ExtendedBufferCapabilities ebc = (ExtendedBufferCapabilities) caps;
                    if (ebc.getVSync() == VSYNC_ON && ebc.getFlipContents() == COPIED) {
                        createVSynced = true;
                        forceback = false;
                    }
                }
            }
        }
        if (forceback) {
            // peer must be non-null in this case
            sData = WGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
        } else {
            WGLGraphicsConfig gc = (WGLGraphicsConfig) vImg.getGraphicsConfig();
            ColorModel cm = gc.getColorModel(vImg.getTransparency());
            int type = vImg.getForcedAccelSurfaceType();
            // use the forced type, otherwise choose one based on caps
            if (type == OGLSurfaceData.UNDEFINED) {
                type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ? OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
            }
            if (createVSynced) {
                sData = WGLSurfaceData.createData(peer, vImg, type);
            } else {
                sData = WGLSurfaceData.createData(gc, vImg.getWidth(), vImg.getHeight(), cm, vImg, type);
            }
        }
    } catch (NullPointerException ex) {
        sData = null;
    } catch (OutOfMemoryError er) {
        sData = null;
    }
    return sData;
}
Also used : ExtendedBufferCapabilities(sun.java2d.pipe.hw.ExtendedBufferCapabilities) SurfaceData(sun.java2d.SurfaceData) ExtendedBufferCapabilities(sun.java2d.pipe.hw.ExtendedBufferCapabilities) BufferCapabilities(java.awt.BufferCapabilities) ColorModel(java.awt.image.ColorModel) WComponentPeer(sun.awt.windows.WComponentPeer) Component(java.awt.Component)

Example 100 with ColorModel

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

ColorModel (java.awt.image.ColorModel)188 BufferedImage (java.awt.image.BufferedImage)92 IndexColorModel (java.awt.image.IndexColorModel)80 WritableRaster (java.awt.image.WritableRaster)57 ComponentColorModel (java.awt.image.ComponentColorModel)47 SampleModel (java.awt.image.SampleModel)40 DirectColorModel (java.awt.image.DirectColorModel)39 ColorSpace (java.awt.color.ColorSpace)28 Raster (java.awt.image.Raster)24 Rectangle (java.awt.Rectangle)21 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)20 Point (java.awt.Point)15 ComponentSampleModel (java.awt.image.ComponentSampleModel)15 Graphics2D (java.awt.Graphics2D)13 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)13 IOException (java.io.IOException)13 ColorConvertOp (java.awt.image.ColorConvertOp)12 DataBuffer (java.awt.image.DataBuffer)12 DataBufferInt (java.awt.image.DataBufferInt)11 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)11