Example usage for java.awt.image PixelInterleavedSampleModel PixelInterleavedSampleModel

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

Introduction

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

Prototype

public PixelInterleavedSampleModel(int dataType, int w, int h, int pixelStride, int scanlineStride,
        int[] bandOffsets) 

Source Link

Document

Constructs a PixelInterleavedSampleModel with the specified parameters.

Usage

From source file:com.bc.ceres.jai.opimage.ReinterpretOpImage.java

static RenderedImage create(RenderedImage source, double factor, double offset, ScalingType scalingType,
        InterpretationType interpretationType, Map<Object, Object> config) {
    final ImageLayout imageLayout;
    if (config != null && config.get(JAI.KEY_IMAGE_LAYOUT) instanceof ImageLayout) {
        imageLayout = (ImageLayout) config.get(JAI.KEY_IMAGE_LAYOUT);
    } else {/*from  w w  w .ja va2  s  . c  o  m*/
        final int targetDataType = ReinterpretDescriptor.getTargetDataType(
                source.getSampleModel().getDataType(), factor, offset, scalingType, interpretationType);
        final PixelInterleavedSampleModel sampleModel = new PixelInterleavedSampleModel(targetDataType,
                source.getTileWidth(), source.getTileHeight(), 1, source.getTileWidth(), new int[] { 0 });
        imageLayout = ReinterpretDescriptor.createTargetImageLayout(source, sampleModel);
    }

    return new ReinterpretOpImage(source, imageLayout, config, factor, offset, scalingType, interpretationType);
}

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

/**
 * Returns a generic pixel interleaved WritableRaster
 * /*from  w  w  w  .  j a v  a 2  s. c o  m*/
 * @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.mrgeo.data.raster.RasterWritable.java

private static Raster read(final byte[] rasterBytes, Writable payload) throws IOException {
    WritableRaster raster;/*from   w  w  w  . jav a2  s . co  m*/

    final ByteBuffer rasterBuffer = ByteBuffer.wrap(rasterBytes);

    @SuppressWarnings("unused")
    final int headersize = rasterBuffer.getInt(); // this isn't really used anymore...
    final int height = rasterBuffer.getInt();
    final int width = rasterBuffer.getInt();
    final int bands = rasterBuffer.getInt();
    final int datatype = rasterBuffer.getInt();
    final SampleModelType sampleModelType = SampleModelType.values()[rasterBuffer.getInt()];

    SampleModel model;
    switch (sampleModelType) {
    case BANDED:
        model = new BandedSampleModel(datatype, width, height, bands);
        break;
    case MULTIPIXELPACKED:
        throw new NotImplementedException("MultiPixelPackedSampleModel not implemented yet");
        // model = new MultiPixelPackedSampleModel(dataType, w, h, numberOfBits)
    case PIXELINTERLEAVED: {
        final int pixelStride = rasterBuffer.getInt();
        final int scanlineStride = rasterBuffer.getInt();
        final int bandcnt = rasterBuffer.getInt();
        final int[] bandOffsets = new int[bandcnt];
        for (int i = 0; i < bandcnt; i++) {
            bandOffsets[i] = rasterBuffer.getInt();
        }
        model = new PixelInterleavedSampleModel(datatype, width, height, pixelStride, scanlineStride,
                bandOffsets);
        break;
    }
    case SINGLEPIXELPACKED:
        throw new NotImplementedException("SinglePixelPackedSampleModel not implemented yet");
        // model = new SinglePixelPackedSampleModel(dataType, w, h, bitMasks);
    case COMPONENT: {
        final int pixelStride = rasterBuffer.getInt();
        final int scanlineStride = rasterBuffer.getInt();
        final int bandcnt = rasterBuffer.getInt();
        final int[] bandOffsets = new int[bandcnt];
        for (int i = 0; i < bandcnt; i++) {
            bandOffsets[i] = rasterBuffer.getInt();
        }
        model = new ComponentSampleModel(datatype, width, height, pixelStride, scanlineStride, bandOffsets);
        break;
    }
    default:
        throw new RasterWritableException("Unknown RasterSampleModel type");
    }

    // include the header size param in the count
    int startdata = rasterBuffer.position();

    // calculate the data size
    int[] samplesize = model.getSampleSize();
    int samplebytes = 0;
    for (int ss : samplesize) {
        // bits to bytes
        samplebytes += (ss / 8);
    }
    int databytes = model.getHeight() * model.getWidth() * samplebytes;

    // final ByteBuffer rasterBuffer = ByteBuffer.wrap(rasterBytes, headerbytes, databytes);
    // the corner of the raster is always 0,0
    raster = Raster.createWritableRaster(model, null);

    switch (datatype) {
    case DataBuffer.TYPE_BYTE: {
        // we can't use the byte buffer explicitly because the header info is
        // still in it...
        final byte[] bytedata = new byte[databytes];
        rasterBuffer.get(bytedata);

        raster.setDataElements(0, 0, width, height, bytedata);
        break;
    }
    case DataBuffer.TYPE_FLOAT: {
        final FloatBuffer floatbuff = rasterBuffer.asFloatBuffer();
        final float[] floatdata = new float[databytes / RasterUtils.FLOAT_BYTES];

        floatbuff.get(floatdata);

        raster.setDataElements(0, 0, width, height, floatdata);
        break;
    }
    case DataBuffer.TYPE_DOUBLE: {
        final DoubleBuffer doublebuff = rasterBuffer.asDoubleBuffer();
        final double[] doubledata = new double[databytes / RasterUtils.DOUBLE_BYTES];

        doublebuff.get(doubledata);

        raster.setDataElements(0, 0, width, height, doubledata);

        break;
    }
    case DataBuffer.TYPE_INT: {
        final IntBuffer intbuff = rasterBuffer.asIntBuffer();
        final int[] intdata = new int[databytes / RasterUtils.INT_BYTES];

        intbuff.get(intdata);

        raster.setDataElements(0, 0, width, height, intdata);

        break;
    }
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT: {
        final ShortBuffer shortbuff = rasterBuffer.asShortBuffer();
        final short[] shortdata = new short[databytes / RasterUtils.SHORT_BYTES];
        shortbuff.get(shortdata);
        raster.setDataElements(0, 0, width, height, shortdata);
        break;
    }
    default:
        throw new RasterWritableException("Error trying to read raster.  Bad raster data type");
    }

    // should we even try to extract the payload?
    if (payload != null) {
        // test to see if this is a raster with a possible payload
        final int payloadStart = startdata + databytes;
        if (rasterBytes.length > payloadStart) {
            // extract the payload
            final ByteArrayInputStream bais = new ByteArrayInputStream(rasterBytes, payloadStart,
                    rasterBytes.length - payloadStart);
            final DataInputStream dis = new DataInputStream(bais);
            payload.readFields(dis);
        }
    }
    return raster;
}

From source file:org.photovault.dcraw.AHDInterpolateOp.java

static private ImageLayout layoutHelper(RenderedImage src, int downSample) {
    int width = src.getWidth() / downSample;
    int height = src.getHeight() / downSample;
    PixelInterleavedSampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_USHORT, width,
            height, 3, width * 3, new int[] { 0, 1, 2 });
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
    ColorModel c = new ComponentColorModel(cs, false, false, ColorModel.OPAQUE, DataBuffer.TYPE_USHORT);
    ImageLayout il = new ImageLayout(0, 0, 256, 256, sampleModel, c);
    il.setWidth(width);/*from w ww  .j  a v  a2s.c o  m*/
    il.setHeight(height);
    return il;
}

From source file:org.photovault.dcraw.DCRawReaderOp.java

public DCRawReaderOp(File f, RenderingHints hints) {
    super(null, hints, null, 1, 1, 1, 1);
    file = f;//from  w w w.ja v a  2 s.  c o m
    lrd = lr.libraw_init(0);
    lrd.output_params.half_size = 1;
    lr.libraw_open_file(lrd, f.getAbsolutePath());
    sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_USHORT, lrd.sizes.width, lrd.sizes.height, 1,
            lrd.sizes.width, new int[] { 0 });
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorModel c = new ComponentColorModel(cs, false, false, ColorModel.OPAQUE, DataBuffer.TYPE_USHORT);
    ImageLayout il = new ImageLayout(0, 0, 256, 256, sampleModel, c);
    setImageLayout(il);
    minX = 0;
    minY = 0;
    width = lrd.sizes.width;
    height = lrd.sizes.height;
    bayerfilter = lrd.idata.filters;
    cam_mul = lrd.color.cam_mul;
    setProperty("bayerfilter", lrd.idata.filters);
    setProperty("dcraw_cam_mul", cam_mul);
    setProperty("dcraw_cam_xyz", lrd.color.cam_xyz);
    setProperty("dcraw_rgb_cam", lrd.color.rgb_cam);
    setProperty("dcraw_black", lrd.color.black);
    setProperty("dcraw_max", lrd.color.maximum);
    setProperty("dcraw_black", lrd.color.black);
    setProperty("dcraw_margin_top", lrd.sizes.top_margin);
    setProperty("dcraw_margin_left", lrd.sizes.left_margin);
}