Search in sources :

Example 11 with ImageRepresentation

use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.

the class WCustomCursor method createNativeCursor.

@Override
protected void createNativeCursor(Image im, int[] pixels, int w, int h, int xHotSpot, int yHotSpot) {
    BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = bimage.getGraphics();
    try {
        if (im instanceof ToolkitImage) {
            ImageRepresentation ir = ((ToolkitImage) im).getImageRep();
            ir.reconstruct(ImageObserver.ALLBITS);
        }
        g.drawImage(im, 0, 0, w, h, null);
    } finally {
        g.dispose();
    }
    Raster raster = bimage.getRaster();
    DataBuffer buffer = raster.getDataBuffer();
    // REMIND: native code should use ScanStride _AND_ width
    int[] data = ((DataBufferInt) buffer).getData();
    byte[] andMask = new byte[w * h / 8];
    int npixels = pixels.length;
    for (int i = 0; i < npixels; i++) {
        int ibyte = i / 8;
        int omask = 1 << (7 - (i % 8));
        if ((pixels[i] & 0xff000000) == 0) {
            // Transparent bit
            andMask[ibyte] |= omask;
        }
    }
    {
        int ficW = raster.getWidth();
        if (raster instanceof IntegerComponentRaster) {
            ficW = ((IntegerComponentRaster) raster).getScanlineStride();
        }
        createCursorIndirect(((DataBufferInt) bimage.getRaster().getDataBuffer()).getData(), andMask, ficW, raster.getWidth(), raster.getHeight(), xHotSpot, yHotSpot);
    }
}
Also used : ImageRepresentation(sun.awt.image.ImageRepresentation) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster) ToolkitImage(sun.awt.image.ToolkitImage)

Aggregations

ImageRepresentation (sun.awt.image.ImageRepresentation)11 ToolkitImage (sun.awt.image.ToolkitImage)7 Graphics2D (java.awt.Graphics2D)1 ColorSpace (java.awt.color.ColorSpace)1 AffineTransform (java.awt.geom.AffineTransform)1 BufferedImage (java.awt.image.BufferedImage)1 ColorModel (java.awt.image.ColorModel)1 ComponentColorModel (java.awt.image.ComponentColorModel)1 DataBufferByte (java.awt.image.DataBufferByte)1 DirectColorModel (java.awt.image.DirectColorModel)1 WritableRaster (java.awt.image.WritableRaster)1 IntegerComponentRaster (sun.awt.image.IntegerComponentRaster)1