Search in sources :

Example 1 with SunWritableRaster

use of sun.awt.image.SunWritableRaster in project jdk8u_jdk by JetBrains.

the class Raster method createBandedRaster.

/**
     * Creates a Raster based on a BandedSampleModel with the
     * specified DataBuffer, width, height, scanline stride, bank
     * indices, and band offsets.  The number of bands is inferred
     * from bankIndices.length and bandOffsets.length, which must be
     * the same.  The upper left corner of the Raster is given by the
     * location argument.  If location is null, (0, 0) will be used.
     * @param dataBuffer the <code>DataBuffer</code> that contains the
     *        image data
     * @param w         the width in pixels of the image data
     * @param h         the height in pixels of the image data
     * @param scanlineStride the line stride of the image data
     * @param bankIndices the bank indices for each band
     * @param bandOffsets the offsets of all bands
     * @param location  the upper-left corner of the <code>Raster</code>
     * @return a WritableRaster object with the specified
     *         <code>DataBuffer</code>, width, height, scanline stride,
     *         bank indices and band offsets.
     * @throws RasterFormatException if <code>w</code> or <code>h</code>
     *         is less than or equal to zero, or computing either
     *         <code>location.x + w</code> or
     *         <code>location.y + h</code> results in integer
     *         overflow
     * @throws IllegalArgumentException if <code>dataType</code> is not
     *         one of the supported data types, which are
     *         <code>DataBuffer.TYPE_BYTE</code>,
     *         <code>DataBuffer.TYPE_USHORT</code>
     *         or <code>DataBuffer.TYPE_INT</code>
     * @throws NullPointerException if <code>dataBuffer</code> is null
     */
public static WritableRaster createBandedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location) {
    if (dataBuffer == null) {
        throw new NullPointerException("DataBuffer cannot be null");
    }
    if (location == null) {
        location = new Point(0, 0);
    }
    int dataType = dataBuffer.getDataType();
    int bands = bankIndices.length;
    if (bandOffsets.length != bands) {
        throw new IllegalArgumentException("bankIndices.length != bandOffsets.length");
    }
    BandedSampleModel bsm = new BandedSampleModel(dataType, w, h, scanlineStride, bankIndices, bandOffsets);
    switch(dataType) {
        case DataBuffer.TYPE_BYTE:
            return new ByteBandedRaster(bsm, dataBuffer, location);
        case DataBuffer.TYPE_USHORT:
            return new ShortBandedRaster(bsm, dataBuffer, location);
        case DataBuffer.TYPE_INT:
            return new SunWritableRaster(bsm, dataBuffer, location);
        default:
            throw new IllegalArgumentException("Unsupported data type " + dataType);
    }
}
Also used : ShortBandedRaster(sun.awt.image.ShortBandedRaster) ByteBandedRaster(sun.awt.image.ByteBandedRaster) SunWritableRaster(sun.awt.image.SunWritableRaster) Point(java.awt.Point) Point(java.awt.Point)

Example 2 with SunWritableRaster

use of sun.awt.image.SunWritableRaster in project jdk8u_jdk by JetBrains.

the class Raster method createPackedRaster.

/**
     * Creates a Raster based on a MultiPixelPackedSampleModel with the
     * specified DataBuffer, width, height, and bits per pixel.  The upper
     * left corner of the Raster is given by the location argument.  If
     * location is null, (0, 0) will be used.
     * @param dataBuffer the <code>DataBuffer</code> that contains the
     *        image data
     * @param w         the width in pixels of the image data
     * @param h         the height in pixels of the image data
     * @param bitsPerPixel the number of bits for each pixel
     * @param location  the upper-left corner of the <code>Raster</code>
     * @return a WritableRaster object with the specified
     *         <code>DataBuffer</code>, width, height, and
     *         bits per pixel.
     * @throws RasterFormatException if <code>w</code> or <code>h</code>
     *         is less than or equal to zero, or computing either
     *         <code>location.x + w</code> or
     *         <code>location.y + h</code> results in integer
     *         overflow
     * @throws IllegalArgumentException if <code>dataType</code> is not
     *         one of the supported data types, which are
     *         <code>DataBuffer.TYPE_BYTE</code>,
     *         <code>DataBuffer.TYPE_USHORT</code>
     *         or <code>DataBuffer.TYPE_INT</code>
     * @throws RasterFormatException if <code>dataBuffer</code> has more
     *         than one bank.
     * @throws NullPointerException if <code>dataBuffer</code> is null
     */
public static WritableRaster createPackedRaster(DataBuffer dataBuffer, int w, int h, int bitsPerPixel, Point location) {
    if (dataBuffer == null) {
        throw new NullPointerException("DataBuffer cannot be null");
    }
    if (location == null) {
        location = new Point(0, 0);
    }
    int dataType = dataBuffer.getDataType();
    if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT && dataType != DataBuffer.TYPE_INT) {
        throw new IllegalArgumentException("Unsupported data type " + dataType);
    }
    if (dataBuffer.getNumBanks() != 1) {
        throw new RasterFormatException("DataBuffer for packed Rasters" + " must only have 1 bank.");
    }
    MultiPixelPackedSampleModel mppsm = new MultiPixelPackedSampleModel(dataType, w, h, bitsPerPixel);
    if (dataType == DataBuffer.TYPE_BYTE && (bitsPerPixel == 1 || bitsPerPixel == 2 || bitsPerPixel == 4)) {
        return new BytePackedRaster(mppsm, dataBuffer, location);
    } else {
        return new SunWritableRaster(mppsm, dataBuffer, location);
    }
}
Also used : BytePackedRaster(sun.awt.image.BytePackedRaster) SunWritableRaster(sun.awt.image.SunWritableRaster) Point(java.awt.Point) Point(java.awt.Point)

Example 3 with SunWritableRaster

use of sun.awt.image.SunWritableRaster in project imageio-ext by geosolutions-it.

the class ImageIOUtils method makeGenericBandedWritableRaster.

/**
 * Returns a generic banded WritableRaster
 *
 * @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;
}
Also used : BandedSampleModel(java.awt.image.BandedSampleModel) SunWritableRaster(sun.awt.image.SunWritableRaster) Point(java.awt.Point) DataBufferByte(java.awt.image.DataBufferByte) DataBufferFloat(java.awt.image.DataBufferFloat) Point(java.awt.Point) DataBuffer(java.awt.image.DataBuffer)

Example 4 with SunWritableRaster

use of sun.awt.image.SunWritableRaster in project imageio-ext by geosolutions-it.

the class ImageIOUtils method makeGenericPixelInterleavedWritableRaster.

/**
 * Returns a generic pixel interleaved WritableRaster
 *
 * @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;
}
Also used : DataBufferShort(java.awt.image.DataBufferShort) DataBufferDouble(java.awt.image.DataBufferDouble) PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) SunWritableRaster(sun.awt.image.SunWritableRaster) Point(java.awt.Point) DataBufferByte(java.awt.image.DataBufferByte) DataBufferFloat(java.awt.image.DataBufferFloat) DataBufferUShort(java.awt.image.DataBufferUShort) Point(java.awt.Point) DataBuffer(java.awt.image.DataBuffer)

Aggregations

Point (java.awt.Point)4 SunWritableRaster (sun.awt.image.SunWritableRaster)4 DataBuffer (java.awt.image.DataBuffer)2 DataBufferByte (java.awt.image.DataBufferByte)2 DataBufferFloat (java.awt.image.DataBufferFloat)2 BandedSampleModel (java.awt.image.BandedSampleModel)1 DataBufferDouble (java.awt.image.DataBufferDouble)1 DataBufferShort (java.awt.image.DataBufferShort)1 DataBufferUShort (java.awt.image.DataBufferUShort)1 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)1 ByteBandedRaster (sun.awt.image.ByteBandedRaster)1 BytePackedRaster (sun.awt.image.BytePackedRaster)1 ShortBandedRaster (sun.awt.image.ShortBandedRaster)1