/** * 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} 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} * @return a WritableRaster object with the specified * {@code DataBuffer}, width, height, and * bits per pixel. * @throws RasterFormatException if {@code w} or {@code h} * is less than or equal to zero, or computing either * {@code location.x + w} or * {@code location.y + h} results in integer * overflow * @throws IllegalArgumentException if {@code dataType} is not * one of the supported data types, which are * {@code DataBuffer.TYPE_BYTE}, * {@code DataBuffer.TYPE_USHORT} * or {@code DataBuffer.TYPE_INT} * @throws RasterFormatException if {@code dataBuffer} has more * than one bank. * @throws NullPointerException if {@code dataBuffer} 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 (dataBuffer instanceof DataBufferByte && (bitsPerPixel == 1 || bitsPerPixel == 2 || bitsPerPixel == 4)) { return new BytePackedRaster(mppsm, (DataBufferByte) dataBuffer, location); } else { return new SunWritableRaster(mppsm, dataBuffer, location); } }
/** * 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); } }
/** * Creates a Raster with the specified SampleModel and DataBuffer. * The upper left corner of the Raster is given by the location argument. * If location is null, (0, 0) will be used. * @param sm the specified <code>SampleModel</code> * @param db the specified <code>DataBuffer</code> * @param location the upper-left corner of the <code>Raster</code> * @return a <code>Raster</code> with the specified * <code>SampleModel</code>, <code>DataBuffer</code>, and * location. * @throws RasterFormatException if computing either * <code>location.x + sm.getWidth()</code> or * <code>location.y + sm.getHeight()</code> results in integer * overflow * @throws RasterFormatException if <code>db</code> has more * than one bank and <code>sm</code> is a * PixelInterleavedSampleModel, SinglePixelPackedSampleModel, * or MultiPixelPackedSampleModel. * @throws NullPointerException if either SampleModel or DataBuffer is * null */ public static Raster createRaster(SampleModel sm, DataBuffer db, Point location) { if ((sm == null) || (db == null)) { throw new NullPointerException("SampleModel and DataBuffer cannot be null"); } if (location == null) { location = new Point(0,0); } int dataType = sm.getDataType(); if (sm instanceof PixelInterleavedSampleModel) { switch(dataType) { case DataBuffer.TYPE_BYTE: return new ByteInterleavedRaster(sm, db, location); case DataBuffer.TYPE_USHORT: return new ShortInterleavedRaster(sm, db, location); } } else if (sm instanceof SinglePixelPackedSampleModel) { switch(dataType) { case DataBuffer.TYPE_BYTE: return new ByteInterleavedRaster(sm, db, location); case DataBuffer.TYPE_USHORT: return new ShortInterleavedRaster(sm, db, location); case DataBuffer.TYPE_INT: return new IntegerInterleavedRaster(sm, db, location); } } else if (sm instanceof MultiPixelPackedSampleModel && dataType == DataBuffer.TYPE_BYTE && sm.getSampleSize(0) < 8) { return new BytePackedRaster(sm, db, location); } // we couldn't do anything special - do the generic thing return new Raster(sm,db,location); }
/** * Creates a WritableRaster with the specified SampleModel and DataBuffer. * The upper left corner of the Raster is given by the location argument. * If location is null, (0, 0) will be used. * @param sm the specified <code>SampleModel</code> * @param db the specified <code>DataBuffer</code> * @param location the upper-left corner of the * <code>WritableRaster</code> * @return a <code>WritableRaster</code> with the specified * <code>SampleModel</code>, <code>DataBuffer</code>, and * location. * @throws RasterFormatException if computing either * <code>location.x + sm.getWidth()</code> or * <code>location.y + sm.getHeight()</code> results in integer * overflow * @throws RasterFormatException if <code>db</code> has more * than one bank and <code>sm</code> is a * PixelInterleavedSampleModel, SinglePixelPackedSampleModel, * or MultiPixelPackedSampleModel. * @throws NullPointerException if either SampleModel or DataBuffer is null */ public static WritableRaster createWritableRaster(SampleModel sm, DataBuffer db, Point location) { if ((sm == null) || (db == null)) { throw new NullPointerException("SampleModel and DataBuffer cannot be null"); } if (location == null) { location = new Point(0,0); } int dataType = sm.getDataType(); if (sm instanceof PixelInterleavedSampleModel) { switch(dataType) { case DataBuffer.TYPE_BYTE: return new ByteInterleavedRaster(sm, db, location); case DataBuffer.TYPE_USHORT: return new ShortInterleavedRaster(sm, db, location); } } else if (sm instanceof SinglePixelPackedSampleModel) { switch(dataType) { case DataBuffer.TYPE_BYTE: return new ByteInterleavedRaster(sm, db, location); case DataBuffer.TYPE_USHORT: return new ShortInterleavedRaster(sm, db, location); case DataBuffer.TYPE_INT: return new IntegerInterleavedRaster(sm, db, location); } } else if (sm instanceof MultiPixelPackedSampleModel && dataType == DataBuffer.TYPE_BYTE && sm.getSampleSize(0) < 8) { return new BytePackedRaster(sm, db, location); } // we couldn't do anything special - do the generic thing return new SunWritableRaster(sm,db,location); }
/** * Creates a Raster with the specified SampleModel and DataBuffer. * The upper left corner of the Raster is given by the location argument. * If location is null, (0, 0) will be used. * @param sm the specified <code>SampleModel</code> * @param db the specified <code>DataBuffer</code> * @param location the upper-left corner of the <code>Raster</code> * @return a <code>Raster</code> with the specified * <code>SampleModel</code>, <code>DataBuffer</code>, and * location. * @throws RasterFormatException if computing either * <code>location.x + sm.getWidth()</code> or * <code>location.y + sm.getHeight()</code> results in integer * overflow * @throws RasterFormatException if <code>dataBuffer</code> has more * than one bank and the <code>sampleModel</code> is * PixelInterleavedSampleModel, SinglePixelPackedSampleModel, * or MultiPixelPackedSampleModel. * @throws NullPointerException if either SampleModel or DataBuffer is * null */ public static Raster createRaster(SampleModel sm, DataBuffer db, Point location) { if ((sm == null) || (db == null)) { throw new NullPointerException("SampleModel and DataBuffer cannot be null"); } if (location == null) { location = new Point(0,0); } int dataType = sm.getDataType(); if (sm instanceof PixelInterleavedSampleModel) { switch(dataType) { case DataBuffer.TYPE_BYTE: return new ByteInterleavedRaster(sm, db, location); case DataBuffer.TYPE_USHORT: return new ShortInterleavedRaster(sm, db, location); } } else if (sm instanceof SinglePixelPackedSampleModel) { switch(dataType) { case DataBuffer.TYPE_BYTE: return new ByteInterleavedRaster(sm, db, location); case DataBuffer.TYPE_USHORT: return new ShortInterleavedRaster(sm, db, location); case DataBuffer.TYPE_INT: return new IntegerInterleavedRaster(sm, db, location); } } else if (sm instanceof MultiPixelPackedSampleModel && dataType == DataBuffer.TYPE_BYTE && sm.getSampleSize(0) < 8) { return new BytePackedRaster(sm, db, location); } // we couldn't do anything special - do the generic thing return new Raster(sm,db,location); }
/** * Creates a WritableRaster with the specified SampleModel and DataBuffer. * The upper left corner of the Raster is given by the location argument. * If location is null, (0, 0) will be used. * @param sm the specified <code>SampleModel</code> * @param db the specified <code>DataBuffer</code> * @param location the upper-left corner of the * <code>WritableRaster</code> * @return a <code>WritableRaster</code> with the specified * <code>SampleModel</code>, <code>DataBuffer</code>, and * location. * @throws RasterFormatException if computing either * <code>location.x + sm.getWidth()</code> or * <code>location.y + sm.getHeight()</code> results in integer * overflow * @throws RasterFormatException if <code>dataBuffer</code> has more * than one bank and the <code>sampleModel</code> is * PixelInterleavedSampleModel, SinglePixelPackedSampleModel, * or MultiPixelPackedSampleModel. * @throws NullPointerException if either SampleModel or DataBuffer is null */ public static WritableRaster createWritableRaster(SampleModel sm, DataBuffer db, Point location) { if ((sm == null) || (db == null)) { throw new NullPointerException("SampleModel and DataBuffer cannot be null"); } if (location == null) { location = new Point(0,0); } int dataType = sm.getDataType(); if (sm instanceof PixelInterleavedSampleModel) { switch(dataType) { case DataBuffer.TYPE_BYTE: return new ByteInterleavedRaster(sm, db, location); case DataBuffer.TYPE_USHORT: return new ShortInterleavedRaster(sm, db, location); } } else if (sm instanceof SinglePixelPackedSampleModel) { switch(dataType) { case DataBuffer.TYPE_BYTE: return new ByteInterleavedRaster(sm, db, location); case DataBuffer.TYPE_USHORT: return new ShortInterleavedRaster(sm, db, location); case DataBuffer.TYPE_INT: return new IntegerInterleavedRaster(sm, db, location); } } else if (sm instanceof MultiPixelPackedSampleModel && dataType == DataBuffer.TYPE_BYTE && sm.getSampleSize(0) < 8) { return new BytePackedRaster(sm, db, location); } // we couldn't do anything special - do the generic thing return new SunWritableRaster(sm,db,location); }