Java Code Examples for java.awt.image.DataBuffer#getOffset()

The following examples show how to use java.awt.image.DataBuffer#getOffset() . 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: ByteInterleavedRaster.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 2
Source File: ByteInterleavedRaster.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 3
Source File: ByteInterleavedRaster.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 4
Source File: ByteInterleavedRaster.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 5
Source File: ByteInterleavedRaster.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 6
Source File: ByteInterleavedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 7
Source File: ByteInterleavedRaster.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 8
Source File: ByteInterleavedRaster.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 9
Source File: ByteInterleavedRaster.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 10
Source File: ByteInterleavedRaster.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 11
Source File: ByteInterleavedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 12
Source File: ByteInterleavedRaster.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * 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 ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

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

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}