Example usage for java.awt.image DataBufferByte DataBufferByte

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

Introduction

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

Prototype

public DataBufferByte(int size) 

Source Link

Document

Constructs a byte-based DataBuffer with a single bank and the specified size.

Usage

From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java

/**
 * Returns a generic banded WritableRaster
 * /*from w  w w .  ja  v a 2 s.  c  o  m*/
 * @param numElems
 * @param numLines
 * @param bandOffsets
 * @param dataType
 * @return
 */
public static WritableRaster makeGenericBandedWritableRaster(int numElems, int numLines, int numBands,
        int dataType) {
    int[] bandOffsets = new int[numBands];
    for (int i = 0; i < numBands; ++i)
        bandOffsets[i] = i;

    DataBuffer d = null;
    if (dataType == DataBuffer.TYPE_BYTE)
        d = new DataBufferByte(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_FLOAT)
        d = new DataBufferFloat(numElems * numLines * numBands);
    else
        throw new IllegalArgumentException("Invalid datatype: " + dataType);

    BandedSampleModel bsm = new BandedSampleModel(dataType, numElems, numLines, bandOffsets.length, bandOffsets,
            bandOffsets);

    SunWritableRaster ras = new SunWritableRaster(bsm, d, new Point(0, 0));
    return ras;
}

From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java

/**
 * Returns a generic pixel interleaved WritableRaster
 * /*  w ww. j  ava2s  . com*/
 * @param numElems
 * @param numLines
 * @param bandOffsets
 * @param dataType
 * @return
 */
public static WritableRaster makeGenericPixelInterleavedWritableRaster(int numElems, int numLines, int numBands,
        int dataType) {
    int[] bandOffsets = new int[numBands];
    for (int i = 0; i < numBands; ++i)
        bandOffsets[i] = i;

    DataBuffer d = null;
    if (dataType == DataBuffer.TYPE_BYTE)
        d = new DataBufferByte(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_SHORT)
        d = new DataBufferShort(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_USHORT)
        d = new DataBufferUShort(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_FLOAT)
        d = new DataBufferFloat(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_DOUBLE)
        d = new DataBufferDouble(numElems * numLines * numBands);
    else
        throw new IllegalArgumentException("Invalid datatype: " + dataType);

    PixelInterleavedSampleModel pism = new PixelInterleavedSampleModel(dataType, numElems, numLines,
            bandOffsets.length, numElems * bandOffsets.length, bandOffsets);

    SunWritableRaster ras = new SunWritableRaster(pism, d, new Point(0, 0));
    return ras;
}

From source file:org.apache.xmlgraphics.image.codec.png.PNGImageDecoder.java

private WritableRaster createRaster(final int width, final int height, final int bands,
        final int scanlineStride, final int bitDepth) {

    DataBuffer dataBuffer;/*ww  w  . j av  a 2s.c o  m*/
    WritableRaster ras = null;
    final 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,
                this.bandOffsets[bands], origin);
    } else {
        dataBuffer = new DataBufferUShort(height * scanlineStride);
        ras = Raster.createInterleavedRaster(dataBuffer, width, height, scanlineStride, bands,
                this.bandOffsets[bands], origin);
    }

    return ras;
}