Search in sources :

Example 46 with DataBufferInt

use of java.awt.image.DataBufferInt in project Lucee by lucee.

the class Image method jpgImage.

private static BufferedImage jpgImage(BufferedImage src) {
    int w = src.getWidth();
    int h = src.getHeight();
    SampleModel srcSM = src.getSampleModel();
    WritableRaster srcWR = src.getRaster();
    java.awt.image.DataBuffer srcDB = srcWR.getDataBuffer();
    ColorModel rgb = new DirectColorModel(32, 0xff0000, 65280, 255);
    int[] bitMasks = new int[] { 0xff0000, 65280, 255 };
    SampleModel csm = new SinglePixelPackedSampleModel(3, w, h, bitMasks);
    int[] data = new int[w * h];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int[] pix = null;
            int[] sample = srcSM.getPixel(j, i, pix, srcDB);
            if (sample[3] == 0 && sample[2] == 0 && sample[1] == 0 && sample[0] == 0)
                data[i * w + j] = 0xffffff;
            else
                data[i * w + j] = sample[0] << 16 | sample[1] << 8 | sample[2];
        }
    }
    java.awt.image.DataBuffer db = new DataBufferInt(data, w * h * 3);
    WritableRaster wr = Raster.createWritableRaster(csm, db, new Point(0, 0));
    return new BufferedImage(rgb, wr, false, null);
}
Also used : SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DataBufferInt(java.awt.image.DataBufferInt) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) SampleModel(java.awt.image.SampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) WritableRaster(java.awt.image.WritableRaster) IndexColorModel(java.awt.image.IndexColorModel) DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) PackedColorModel(java.awt.image.PackedColorModel) ColorModel(java.awt.image.ColorModel) DirectColorModel(java.awt.image.DirectColorModel)

Example 47 with DataBufferInt

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

Aggregations

DataBufferInt (java.awt.image.DataBufferInt)47 BufferedImage (java.awt.image.BufferedImage)29 DataBuffer (java.awt.image.DataBuffer)16 DataBufferByte (java.awt.image.DataBufferByte)14 Graphics2D (java.awt.Graphics2D)11 Point (java.awt.Point)11 WritableRaster (java.awt.image.WritableRaster)11 DataBufferShort (java.awt.image.DataBufferShort)10 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)10 SampleModel (java.awt.image.SampleModel)8 Rectangle (java.awt.Rectangle)6 DataBufferUShort (java.awt.image.DataBufferUShort)6 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)6 ComponentSampleModel (java.awt.image.ComponentSampleModel)5 DirectColorModel (java.awt.image.DirectColorModel)5 IndexColorModel (java.awt.image.IndexColorModel)5 ColorModel (java.awt.image.ColorModel)4 ByteBuffer (java.nio.ByteBuffer)3 CartesianMesh (cbit.vcell.solvers.CartesianMesh)2 Dimension (java.awt.Dimension)2