Example usage for java.awt.image DataBufferInt DataBufferInt

List of usage examples for java.awt.image DataBufferInt DataBufferInt

Introduction

In this page you can find the example usage for java.awt.image DataBufferInt DataBufferInt.

Prototype

public DataBufferInt(int[][] dataArray, int size) 

Source Link

Document

Constructs an integer-based DataBuffer with the specified arrays.

Usage

From source file:de.codesourcery.jasm16.emulator.devices.impl.RawImage.java

public RawImage(int width, int height) {
    data = new int[width * height];

    final DataBufferInt dataBuffer = new DataBufferInt(data, width * height);

    final ColorModel cm = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    final SampleModel sm = cm.createCompatibleSampleModel(width, height);
    final WritableRaster wr = Raster.createWritableRaster(sm, dataBuffer, null);

    image = new BufferedImage(cm, wr, false, null);
}

From source file:GrabandFadewithRasters.java

public void init() {
    URL url;//from w  w  w. j av  a2  s . c o m
    try {
        url = new URL(imageURLString);
        originalImage = getImage(url);
    } catch (MalformedURLException me) {
        showStatus("Malformed URL: " + me.getMessage());
    }

    try {
        PixelGrabber grabber = new PixelGrabber(originalImage, 0, 0, -1, -1, true);
        if (grabber.grabPixels()) {
            width = grabber.getWidth();
            height = grabber.getHeight();
            originalPixelArray = (int[]) grabber.getPixels();

            mis = new MemoryImageSource(width, height, originalPixelArray, 0, width);
            mis.setAnimated(true);
            newImage = createImage(mis);
        } else {
            System.err.println("Grabbing Failed");
        }
    } catch (InterruptedException ie) {
        System.err.println("Pixel Grabbing Interrupted");
    }

    DataBufferInt dbi = new DataBufferInt(originalPixelArray, width * height);

    int bandmasks[] = { 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff };
    SampleModel sm;
    sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, width, height, bandmasks);

    raster = Raster.createWritableRaster(sm, dbi, null);
}

From source file:de.mfo.jsurf.grid.RotationGrid.java

static BufferedImage createBufferedImageFromRGB(ImgBuffer ib) {
    int w = ib.width;
    int h = ib.height;

    DirectColorModel colormodel = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    SampleModel sampleModel = colormodel.createCompatibleSampleModel(w, h);
    DataBufferInt data = new DataBufferInt(ib.rgbBuffer, w * h);
    WritableRaster raster = WritableRaster.createWritableRaster(sampleModel, data, new Point(0, 0));
    return new BufferedImage(colormodel, raster, false, null);
}

From source file:lucee.runtime.img.Image.java

private 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//from w  ww  .jav a  2 s .  c o m
                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);
}

From source file:org.geoserver.jai.ConcurrentTileFactory.java

/**
 * Builds a new tile, eventually recycling the data array backing it
 *//*from  w  ww .  ja va2 s .  co  m*/
public WritableRaster createTile(SampleModel sampleModel, Point location) {
    // sanity checks
    if (sampleModel == null) {
        throw new NullPointerException("sampleModel cannot be null");
    }
    if (location == null) {
        location = new Point(0, 0);
    }

    DataBuffer db = null;

    // get the three elements making the key into the recycled array map
    int type = sampleModel.getTransferType();
    long numBanks = 0;
    long size = 0;
    if (sampleModel instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel) sampleModel;
        numBanks = getNumBanksCSM(csm);
        size = getBufferSizeCSM(csm);
    } else if (sampleModel instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel) sampleModel;
        numBanks = 1;
        int dataTypeSize = DataBuffer.getDataTypeSize(type);
        size = mppsm.getScanlineStride() * mppsm.getHeight()
                + (mppsm.getDataBitOffset() + dataTypeSize - 1) / dataTypeSize;
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sampleModel;
        numBanks = 1;
        size = sppsm.getScanlineStride() * (sppsm.getHeight() - 1) + sppsm.getWidth();
    }

    if (size > 0) {
        // try to build a new data buffer starting from 
        Object array = recycledArrays.getRecycledArray(type, numBanks, size);
        if (array != null) {
            switch (type) {
            case DataBuffer.TYPE_BYTE: {
                byte[][] bankData = (byte[][]) array;
                for (int i = 0; i < numBanks; i++) {
                    Arrays.fill(bankData[i], (byte) 0);
                }
                db = new DataBufferByte(bankData, (int) size);
            }
                break;
            case DataBuffer.TYPE_USHORT: {
                short[][] bankData = (short[][]) array;
                for (int i = 0; i < numBanks; i++) {
                    Arrays.fill(bankData[i], (short) 0);
                }
                db = new DataBufferUShort(bankData, (int) size);
            }
                break;
            case DataBuffer.TYPE_SHORT: {
                short[][] bankData = (short[][]) array;
                for (int i = 0; i < numBanks; i++) {
                    Arrays.fill(bankData[i], (short) 0);
                }
                db = new DataBufferShort(bankData, (int) size);
            }
                break;
            case DataBuffer.TYPE_INT: {
                int[][] bankData = (int[][]) array;
                for (int i = 0; i < numBanks; i++) {
                    Arrays.fill(bankData[i], 0);
                }
                db = new DataBufferInt(bankData, (int) size);
            }
                break;
            case DataBuffer.TYPE_FLOAT: {
                float[][] bankData = (float[][]) array;
                for (int i = 0; i < numBanks; i++) {
                    Arrays.fill(bankData[i], 0.0F);
                }
                db = DataBufferUtils.createDataBufferFloat(bankData, (int) size);
            }
                break;
            case DataBuffer.TYPE_DOUBLE: {
                double[][] bankData = (double[][]) array;
                for (int i = 0; i < numBanks; i++) {
                    Arrays.fill(bankData[i], 0.0);
                }
                db = DataBufferUtils.createDataBufferDouble(bankData, (int) size);
            }
                break;
            default:
                throw new IllegalArgumentException("Unknown array type");
            }
        }
    }

    if (db == null) {
        db = sampleModel.createDataBuffer();
    }

    return Raster.createWritableRaster(sampleModel, db, location);
}