Search in sources :

Example 6 with DataBuffer

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

the class D3DSurfaceData method getRaster.

public synchronized Raster getRaster(int x, int y, int w, int h) {
    if (wrn == null) {
        DirectColorModel dcm = (DirectColorModel) getColorModel();
        SampleModel smHw;
        int dataType = 0;
        int scanStride = width;
        if (dcm.getPixelSize() > 16) {
            dataType = DataBuffer.TYPE_INT;
        } else {
            // 15, 16
            dataType = DataBuffer.TYPE_USHORT;
        }
        // note that we have to use the surface width and height here,
        // not the passed w,h
        smHw = new SinglePixelPackedSampleModel(dataType, width, height, scanStride, dcm.getMasks());
        DataBuffer dbn = new D3DDataBufferNative(this, dataType, width, height);
        wrn = WritableRasterNative.createNativeRaster(smHw, dbn);
    }
    return wrn;
}
Also used : SampleModel(java.awt.image.SampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DirectColorModel(java.awt.image.DirectColorModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DataBuffer(java.awt.image.DataBuffer)

Example 7 with DataBuffer

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

the class ImageUtil method getUnpackedBinaryData.

/**
     * Returns the binary data unpacked into an array of bytes.
     * The line stride will be the width of the <code>Raster</code>.
     *
     * @throws IllegalArgumentException if <code>isBinary()</code> returns
     * <code>false</code> with the <code>SampleModel</code> of the
     * supplied <code>Raster</code> as argument.
     */
public static byte[] getUnpackedBinaryData(Raster raster, Rectangle rect) {
    SampleModel sm = raster.getSampleModel();
    if (!isBinary(sm)) {
        throw new IllegalArgumentException(I18N.getString("ImageUtil0"));
    }
    int rectX = rect.x;
    int rectY = rect.y;
    int rectWidth = rect.width;
    int rectHeight = rect.height;
    DataBuffer dataBuffer = raster.getDataBuffer();
    int dx = rectX - raster.getSampleModelTranslateX();
    int dy = rectY - raster.getSampleModelTranslateY();
    MultiPixelPackedSampleModel mpp = (MultiPixelPackedSampleModel) sm;
    int lineStride = mpp.getScanlineStride();
    int eltOffset = dataBuffer.getOffset() + mpp.getOffset(dx, dy);
    int bitOffset = mpp.getBitOffset(dx);
    byte[] bdata = new byte[rectWidth * rectHeight];
    int maxY = rectY + rectHeight;
    int maxX = rectX + rectWidth;
    int k = 0;
    if (dataBuffer instanceof DataBufferByte) {
        byte[] data = ((DataBufferByte) dataBuffer).getData();
        for (int y = rectY; y < maxY; y++) {
            int bOffset = eltOffset * 8 + bitOffset;
            for (int x = rectX; x < maxX; x++) {
                byte b = data[bOffset / 8];
                bdata[k++] = (byte) ((b >>> (7 - bOffset & 7)) & 0x0000001);
                bOffset++;
            }
            eltOffset += lineStride;
        }
    } else if (dataBuffer instanceof DataBufferShort || dataBuffer instanceof DataBufferUShort) {
        short[] data = dataBuffer instanceof DataBufferShort ? ((DataBufferShort) dataBuffer).getData() : ((DataBufferUShort) dataBuffer).getData();
        for (int y = rectY; y < maxY; y++) {
            int bOffset = eltOffset * 16 + bitOffset;
            for (int x = rectX; x < maxX; x++) {
                short s = data[bOffset / 16];
                bdata[k++] = (byte) ((s >>> (15 - bOffset % 16)) & 0x0000001);
                bOffset++;
            }
            eltOffset += lineStride;
        }
    } else if (dataBuffer instanceof DataBufferInt) {
        int[] data = ((DataBufferInt) dataBuffer).getData();
        for (int y = rectY; y < maxY; y++) {
            int bOffset = eltOffset * 32 + bitOffset;
            for (int x = rectX; x < maxX; x++) {
                int i = data[bOffset / 32];
                bdata[k++] = (byte) ((i >>> (31 - bOffset % 32)) & 0x0000001);
                bOffset++;
            }
            eltOffset += lineStride;
        }
    }
    return bdata;
}
Also used : DataBufferShort(java.awt.image.DataBufferShort) ComponentSampleModel(java.awt.image.ComponentSampleModel) SampleModel(java.awt.image.SampleModel) MultiPixelPackedSampleModel(java.awt.image.MultiPixelPackedSampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) MultiPixelPackedSampleModel(java.awt.image.MultiPixelPackedSampleModel) DataBufferInt(java.awt.image.DataBufferInt) DataBufferByte(java.awt.image.DataBufferByte) DataBufferUShort(java.awt.image.DataBufferUShort) Point(java.awt.Point) DataBuffer(java.awt.image.DataBuffer)

Example 8 with DataBuffer

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

the class PathGraphics method hasTransparentPixels.

/**
     * Return true if the BufferedImage argument has non-opaque
     * bits in it and therefore can not be directly rendered by
     * GDI. Return false if the image is opaque. If this function
     * can not tell for sure whether the image has transparent
     * pixels then it assumes that it does.
     */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null ? true : colorModel.getTransparency() != ColorModel.OPAQUE;
    /*
         * For the default INT ARGB check the image to see if any pixels are
         * really transparent. If there are no transparent pixels then the
         * transparency of the color model can be ignored.
         * We assume that IndexColorModel images have already been
         * checked for transparency and will be OPAQUE unless they actually
         * have transparent pixels present.
         */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB || bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db = bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt && sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm = (SinglePixelPackedSampleModel) sm;
                // Stealing the data array for reading only...
                int[] int_data = SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y + h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x + w; i++) {
                        if ((int_data[yoff + i] & 0xff000000) != 0xff000000) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }
    return hasTransparency;
}
Also used : SampleModel(java.awt.image.SampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) IndexColorModel(java.awt.image.IndexColorModel) ColorModel(java.awt.image.ColorModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DataBufferInt(java.awt.image.DataBufferInt) Paint(java.awt.Paint) DataBuffer(java.awt.image.DataBuffer)

Example 9 with DataBuffer

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

the class RenderableImageProducer method run.

/**
     * The runnable method for this class. This will produce an image using
     * the current RenderableImage and RenderContext and send it to all the
     * ImageConsumer currently registered with this class.
     */
public void run() {
    // First get the rendered image
    RenderedImage rdrdImage;
    if (rc != null) {
        rdrdImage = rdblImage.createRendering(rc);
    } else {
        rdrdImage = rdblImage.createDefaultRendering();
    }
    // And its ColorModel
    ColorModel colorModel = rdrdImage.getColorModel();
    Raster raster = rdrdImage.getData();
    SampleModel sampleModel = raster.getSampleModel();
    DataBuffer dataBuffer = raster.getDataBuffer();
    if (colorModel == null) {
        colorModel = ColorModel.getRGBdefault();
    }
    int minX = raster.getMinX();
    int minY = raster.getMinY();
    int width = raster.getWidth();
    int height = raster.getHeight();
    Enumeration icList;
    ImageConsumer ic;
    // Set up the ImageConsumers
    icList = ics.elements();
    while (icList.hasMoreElements()) {
        ic = (ImageConsumer) icList.nextElement();
        ic.setDimensions(width, height);
        ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES | ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME);
    }
    // Get RGB pixels from the raster scanline by scanline and
    // send to consumers.
    int[] pix = new int[width];
    int i, j;
    int numBands = sampleModel.getNumBands();
    int[] tmpPixel = new int[numBands];
    for (j = 0; j < height; j++) {
        for (i = 0; i < width; i++) {
            sampleModel.getPixel(i, j, tmpPixel, dataBuffer);
            pix[i] = colorModel.getDataElement(tmpPixel, 0);
        }
        // Now send the scanline to the Consumers
        icList = ics.elements();
        while (icList.hasMoreElements()) {
            ic = (ImageConsumer) icList.nextElement();
            ic.setPixels(0, j, width, 1, colorModel, pix, 0, width);
        }
    }
    // Now tell the consumers we're done.
    icList = ics.elements();
    while (icList.hasMoreElements()) {
        ic = (ImageConsumer) icList.nextElement();
        ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
    }
}
Also used : SampleModel(java.awt.image.SampleModel) Enumeration(java.util.Enumeration) ColorModel(java.awt.image.ColorModel) DirectColorModel(java.awt.image.DirectColorModel) ImageConsumer(java.awt.image.ImageConsumer) Raster(java.awt.image.Raster) RenderedImage(java.awt.image.RenderedImage) DataBuffer(java.awt.image.DataBuffer)

Example 10 with DataBuffer

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

the class UnmanagedDrawImagePerformance method makeUnmanagedBI.

private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
    final DataBuffer db = img.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            img.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return img;
}
Also used : DataBufferShort(java.awt.image.DataBufferShort) DataBufferInt(java.awt.image.DataBufferInt) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) DataBuffer(java.awt.image.DataBuffer)

Aggregations

DataBuffer (java.awt.image.DataBuffer)28 DataBufferInt (java.awt.image.DataBufferInt)16 SampleModel (java.awt.image.SampleModel)14 DataBufferByte (java.awt.image.DataBufferByte)13 BufferedImage (java.awt.image.BufferedImage)11 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)10 DataBufferShort (java.awt.image.DataBufferShort)9 Point (java.awt.Point)8 WritableRaster (java.awt.image.WritableRaster)8 ComponentSampleModel (java.awt.image.ComponentSampleModel)6 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)6 DataBufferUShort (java.awt.image.DataBufferUShort)5 DirectColorModel (java.awt.image.DirectColorModel)4 Graphics2D (java.awt.Graphics2D)3 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)3 Rectangle (java.awt.Rectangle)2 ColorSpace (java.awt.color.ColorSpace)2 ColorModel (java.awt.image.ColorModel)2 Raster (java.awt.image.Raster)2 ByteBuffer (java.nio.ByteBuffer)2