java.awt.image.BandedSampleModel Java Examples

The following examples show how to use java.awt.image.BandedSampleModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntegerRaster.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs IntegerRaster with the given size.
 * @param _nrow the number of rows
 * @param _ncol the number of columns
 */
public IntegerRaster(int _nrow, int _ncol) {
  nrow = _nrow;
  ncol = _ncol;
  dimension = new Dimension(ncol, nrow);
  int size = nrow*ncol;
  ComponentColorModel ccm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8, 8, 8}, false, // hasAlpha
    false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
  BandedSampleModel csm = new BandedSampleModel(DataBuffer.TYPE_BYTE, ncol, nrow, ncol, new int[] {0, 1, 2}, new int[] {0, 0, 0});
  rgbData = new byte[3][size];
  DataBuffer databuffer = new DataBufferByte(rgbData, size);
  WritableRaster raster = Raster.createWritableRaster(csm, databuffer, new Point(0, 0));
  image = new BufferedImage(ccm, raster, false, null);
  // col in x direction, row in y direction
  xmin = 0;
  xmax = ncol;
  ymin = nrow;
  ymax = 0; // zero is on top
}
 
Example #2
Source File: RgbeImageParser.java    From commons-imaging with Apache License 2.0 6 votes vote down vote up
@Override
public BufferedImage getBufferedImage(final ByteSource byteSource, final Map<String, Object> params)
        throws ImageReadException, IOException {
    try (RgbeInfo info = new RgbeInfo(byteSource)) {
        // It is necessary to create our own BufferedImage here as the
        // org.apache.commons.imaging.common.IBufferedImageFactory interface does
        // not expose this complexity
        final DataBuffer buffer = new DataBufferFloat(info.getPixelData(),
                info.getWidth() * info.getHeight());

        final BufferedImage ret = new BufferedImage(new ComponentColorModel(
                ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
                Transparency.OPAQUE, buffer.getDataType()),
                Raster.createWritableRaster(
                        new BandedSampleModel(buffer.getDataType(),
                                info.getWidth(), info.getHeight(), 3),
                        buffer,
                        new Point()), false, null);
        return ret;
    }
}
 
Example #3
Source File: ByteBandedRaster.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #4
Source File: ShortBandedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #5
Source File: ByteBandedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferByte that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBufferByte dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent)
{
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dataBuffer.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dataBuffer, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #6
Source File: GetSamplesTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #7
Source File: ShortBandedRaster.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #8
Source File: ShortBandedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                         DataBufferUShort dataBuffer,
                         Rectangle aRegion,
                         Point origin,
                         ShortBandedRaster parent)
{
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dataBuffer.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dataBuffer, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #9
Source File: GetSamplesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #10
Source File: ByteBandedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #11
Source File: GetSamplesTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #12
Source File: ByteBandedRaster.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #13
Source File: ShortBandedRaster.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #14
Source File: GetSamplesTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #15
Source File: ByteBandedRaster.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #16
Source File: ShortBandedRaster.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #17
Source File: GetSamplesTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #18
Source File: ImageBuilder.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SampleModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int width = fa.getInt(instance, "width");          // NOI18N
    int height = fa.getInt(instance, "height");  // NOI18N
    int dataType = fa.getInt(instance, "dataType");   // NOI18N
    int scanlineStride = fa.getInt(instance, "scanlineStride");  // NOI18N
    int[] bankIndices = fa.getIntArray(instance, "bankIndices", false);  // NOI18N
    int[] bandOffsets = fa.getIntArray(instance, "bandOffsets", false);  // NOI18N
    return new BandedSampleModel(dataType, width, height, scanlineStride, bankIndices, bandOffsets);
}
 
Example #19
Source File: ByteBandedRaster.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #20
Source File: ShortBandedRaster.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #21
Source File: GetSamplesTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #22
Source File: ByteBandedRaster.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #23
Source File: ShortBandedRaster.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #24
Source File: GetSamplesTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #25
Source File: ByteBandedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #26
Source File: ShortBandedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #27
Source File: GetSamplesTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}
 
Example #28
Source File: ByteBandedRaster.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
 
Example #29
Source File: ShortBandedRaster.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #30
Source File: GetSamplesTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();

    classes.add(ComponentSampleModel.class);
    classes.add(MultiPixelPackedSampleModel.class);
    classes.add(SinglePixelPackedSampleModel.class);
    classes.add(BandedSampleModel.class);
    classes.add(PixelInterleavedSampleModel.class);

    for (Class<? extends SampleModel> c : classes) {
        doTest(c);
    }
}