Search in sources :

Example 26 with DataBuffer

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

the class PNGImageReader method createRaster.

private WritableRaster createRaster(int width, int height, int bands, int scanlineStride, int bitDepth) {
    DataBuffer dataBuffer;
    WritableRaster ras = null;
    Point origin = new Point(0, 0);
    if ((bitDepth < 8) && (bands == 1)) {
        dataBuffer = new DataBufferByte(height * scanlineStride);
        ras = Raster.createPackedRaster(dataBuffer, width, height, bitDepth, origin);
    } else if (bitDepth <= 8) {
        dataBuffer = new DataBufferByte(height * scanlineStride);
        ras = Raster.createInterleavedRaster(dataBuffer, width, height, scanlineStride, bands, bandOffsets[bands], origin);
    } else {
        dataBuffer = new DataBufferUShort(height * scanlineStride);
        ras = Raster.createInterleavedRaster(dataBuffer, width, height, scanlineStride, bands, bandOffsets[bands], origin);
    }
    return ras;
}
Also used : WritableRaster(java.awt.image.WritableRaster) Point(java.awt.Point) DataBufferByte(java.awt.image.DataBufferByte) DataBufferUShort(java.awt.image.DataBufferUShort) DataBuffer(java.awt.image.DataBuffer)

Example 27 with DataBuffer

use of java.awt.image.DataBuffer in project jlineup by otto-de.

the class ImageService method bufferedImagesEqualQuick.

// A very fast byte buffer based image comparison for images containing INT or BYTE type representations
public static boolean bufferedImagesEqualQuick(BufferedImage image1, BufferedImage image2) {
    DataBuffer dataBuffer1 = image1.getRaster().getDataBuffer();
    DataBuffer dataBuffer2 = image2.getRaster().getDataBuffer();
    if (dataBuffer1 instanceof DataBufferByte && dataBuffer2 instanceof DataBufferByte) {
        DataBufferByte dataBufferBytes1 = (DataBufferByte) dataBuffer1;
        DataBufferByte dataBufferBytes2 = (DataBufferByte) dataBuffer2;
        for (int bank = 0; bank < dataBufferBytes1.getNumBanks(); bank++) {
            byte[] bytes1 = dataBufferBytes1.getData(bank);
            byte[] bytes2 = dataBufferBytes2.getData(bank);
            if (!Arrays.equals(bytes1, bytes2)) {
                return false;
            }
        }
    } else if (dataBuffer1 instanceof DataBufferInt && dataBuffer2 instanceof DataBufferInt) {
        DataBufferInt dataBufferInt1 = (DataBufferInt) dataBuffer1;
        DataBufferInt dataBufferInt2 = (DataBufferInt) dataBuffer2;
        for (int bank = 0; bank < dataBufferInt1.getNumBanks(); bank++) {
            int[] ints1 = dataBufferInt1.getData(bank);
            int[] ints2 = dataBufferInt2.getData(bank);
            if (!Arrays.equals(ints1, ints2)) {
                return false;
            }
        }
    } else {
        return false;
    }
    return true;
}
Also used : DataBufferInt(java.awt.image.DataBufferInt) DataBufferByte(java.awt.image.DataBufferByte) DataBuffer(java.awt.image.DataBuffer)

Example 28 with DataBuffer

use of java.awt.image.DataBuffer in project tigervnc by TigerVNC.

the class ModifiablePixelBuffer method maskRect.

// Copy pixel data to the buffer through a mask
// pixels is a pointer to the pixel to be copied to r.tl.
// maskPos specifies the pixel offset in the mask to start from.
// mask_ is a pointer to the mask bits at (0,0).
// pStride and mStride are the strides of the pixel and mask buffers.
public void maskRect(Rect r, Object pixels, byte[] mask_) {
    Rect cr = getRect().intersect(r);
    if (cr.is_empty())
        return;
    WritableRaster data = getBufferRW(cr);
    // FIXME
    ColorModel cm = format.getColorModel();
    SampleModel sm = cm.createCompatibleSampleModel(r.width(), r.height());
    DataBuffer db = null;
    ByteBuffer src = ByteBuffer.wrap((byte[]) pixels).order(format.getByteOrder());
    Buffer dst;
    switch(sm.getTransferType()) {
        case TYPE_INT:
            dst = IntBuffer.allocate(src.remaining()).put(src.asIntBuffer());
            db = new DataBufferInt(((IntBuffer) dst).array(), r.area());
            break;
        case TYPE_BYTE:
            db = new DataBufferByte(src.array(), r.area());
            break;
        case TYPE_SHORT:
            dst = ShortBuffer.allocate(src.remaining()).put(src.asShortBuffer());
            db = new DataBufferShort(((ShortBuffer) dst).array(), r.area());
            break;
    }
    assert (db != null);
    Raster raster = Raster.createRaster(sm, db, new java.awt.Point(0, 0));
    ColorConvertOp converter = format.getColorConvertOp(cm.getColorSpace());
    WritableRaster t = data.createCompatibleWritableRaster();
    converter.filter(raster, t);
    int w = cr.width();
    int h = cr.height();
    Point offset = new Point(cr.tl.x - r.tl.x, cr.tl.y - r.tl.y);
    int maskBytesPerRow = (w + 7) / 8;
    synchronized (image) {
        for (int y = 0; y < h; y++) {
            int cy = offset.y + y;
            for (int x = 0; x < w; x++) {
                int cx = offset.x + x;
                int byte_ = cy * maskBytesPerRow + y / 8;
                int bit = 7 - cx % 8;
                if ((mask_[byte_] & (1 << bit)) != 0)
                    data.setDataElements(x + cx, y + cy, t.getDataElements(x + cx, y + cy, null));
            }
        }
    }
    commitBufferRW(r);
}
Also used : DataBuffer(java.awt.image.DataBuffer) 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