Search in sources :

Example 11 with RasterFormatException

use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.

the class ShortBandedRaster method createWritableChild.

/**
     * Creates a Writable subRaster given a region of the Raster.  The x and y
     * coordinates specify the horizontal and vertical offsets
     * from the upper-left corner of this Raster to the upper-left corner
     * of the subRaster.  A subset of the bands of the parent Raster may
     * be specified.  If this is null, then all the bands are present in the
     * subRaster. A translation to the subRaster may also be specified.
     * Note that the subRaster will reference the same
     * DataBuffers as the parent Raster, but using different offsets.
     * @param x               X offset.
     * @param y               Y offset.
     * @param width           Width (in pixels) of the subraster.
     * @param height          Height (in pixels) of the subraster.
     * @param x0              Translated X origin of the subraster.
     * @param y0              Translated Y origin of the subraster.
     * @param bandList        Array of band indices.
     * @exception RasterFormatException
     *            if the specified bounding box is outside of the parent Raster.
     */
public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x + width < x) || (x + width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y + height < y) || (y + height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }
    SampleModel sm;
    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;
    int deltaX = x0 - x;
    int deltaY = y0 - y;
    return new ShortBandedRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this);
}
Also used : BandedSampleModel(java.awt.image.BandedSampleModel) SampleModel(java.awt.image.SampleModel) Rectangle(java.awt.Rectangle) Point(java.awt.Point) RasterFormatException(java.awt.image.RasterFormatException) Point(java.awt.Point)

Example 12 with RasterFormatException

use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.

the class IntegerInterleavedRaster method createWritableChild.

/**
     * Creates a subraster given a region of the raster.  The x and y
     * coordinates specify the horizontal and vertical offsets
     * from the upper-left corner of this raster to the upper-left corner
     * of the subraster.  A subset of the bands of the parent Raster may
     * be specified.  If this is null, then all the bands are present in the
     * subRaster. A translation to the subRaster may also be specified.
     * Note that the subraster will reference the same
     * DataBuffer as the parent raster, but using different offsets.
     * @param x               X offset.
     * @param y               Y offset.
     * @param width           Width (in pixels) of the subraster.
     * @param height          Height (in pixels) of the subraster.
     * @param x0              Translated X origin of the subraster.
     * @param y0              Translated Y origin of the subraster.
     * @param bandList        Array of band indices.
     * @exception RasterFormatException
     *            if the specified bounding box is outside of the parent raster.
     */
public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x + width < x) || (x + width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside raster");
    }
    if ((y + height < y) || (y + height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside raster");
    }
    SampleModel sm;
    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;
    int deltaX = x0 - x;
    int deltaY = y0 - y;
    return new IntegerInterleavedRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this);
}
Also used : SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) SampleModel(java.awt.image.SampleModel) Rectangle(java.awt.Rectangle) Point(java.awt.Point) RasterFormatException(java.awt.image.RasterFormatException) Point(java.awt.Point)

Example 13 with RasterFormatException

use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.

the class IntegerComponentRaster method verify.

/**
     * Verify that the layout parameters are consistent with the data.
     *
     * The method verifies whether scanline stride and pixel stride do not
     * cause an integer overflow during calculation of a position of the pixel
     * in data buffer. It also verifies whether the data buffer has enough data
     *  to correspond the raster layout attributes.
     *
     * @throws RasterFormatException if an integer overflow is detected,
     * or if data buffer has not enough capacity.
     */
protected final void verify() {
    /* Need to re-verify the dimensions since a sample model may be
         * specified to the constructor
         */
    if (width <= 0 || height <= 0 || height > (Integer.MAX_VALUE / width)) {
        throw new RasterFormatException("Invalid raster dimension");
    }
    if (dataOffsets[0] < 0) {
        throw new RasterFormatException("Data offset (" + dataOffsets[0] + ") must be >= 0");
    }
    if ((long) minX - sampleModelTranslateX < 0 || (long) minY - sampleModelTranslateY < 0) {
        throw new RasterFormatException("Incorrect origin/translate: (" + minX + ", " + minY + ") / (" + sampleModelTranslateX + ", " + sampleModelTranslateY + ")");
    }
    // we can be sure that width and height are greater than 0
    if (scanlineStride < 0 || scanlineStride > (Integer.MAX_VALUE / height)) {
        // integer overflow
        throw new RasterFormatException("Incorrect scanline stride: " + scanlineStride);
    }
    if (height > 1 || minY - sampleModelTranslateY > 0) {
        // buffer should contain at least one scanline
        if (scanlineStride > data.length) {
            throw new RasterFormatException("Incorrect scanline stride: " + scanlineStride);
        }
    }
    int lastScanOffset = (height - 1) * scanlineStride;
    if (pixelStride < 0 || pixelStride > (Integer.MAX_VALUE / width) || pixelStride > data.length) {
        // integer overflow
        throw new RasterFormatException("Incorrect pixel stride: " + pixelStride);
    }
    int lastPixelOffset = (width - 1) * pixelStride;
    if (lastPixelOffset > (Integer.MAX_VALUE - lastScanOffset)) {
        // integer overflow
        throw new RasterFormatException("Incorrect raster attributes");
    }
    lastPixelOffset += lastScanOffset;
    int index;
    int maxIndex = 0;
    for (int i = 0; i < numDataElements; i++) {
        if (dataOffsets[i] > (Integer.MAX_VALUE - lastPixelOffset)) {
            throw new RasterFormatException("Incorrect band offset: " + dataOffsets[i]);
        }
        index = lastPixelOffset + dataOffsets[i];
        if (index > maxIndex) {
            maxIndex = index;
        }
    }
    if (data.length <= maxIndex) {
        throw new RasterFormatException("Data array too small (should be > " + maxIndex + " )");
    }
}
Also used : RasterFormatException(java.awt.image.RasterFormatException) Point(java.awt.Point)

Example 14 with RasterFormatException

use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.

the class IntegerComponentRaster method createWritableChild.

/**
     * Creates a subraster given a region of the raster.  The x and y
     * coordinates specify the horizontal and vertical offsets
     * from the upper-left corner of this raster to the upper-left corner
     * of the subraster.  A subset of the bands of the parent Raster may
     * be specified.  If this is null, then all the bands are present in the
     * subRaster. A translation to the subRaster may also be specified.
     * Note that the subraster will reference the same
     * DataBuffer as the parent raster, but using different offsets.
     * @param x               X offset.
     * @param y               Y offset.
     * @param width           Width (in pixels) of the subraster.
     * @param height          Height (in pixels) of the subraster.
     * @param x0              Translated X origin of the subraster.
     * @param y0              Translated Y origin of the subraster.
     * @param bandList        Array of band indices.
     * @exception RasterFormatException
     *            if the specified bounding box is outside of the parent raster.
     */
public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x + width < x) || (x + width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside raster");
    }
    if ((y + height < y) || (y + height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside raster");
    }
    SampleModel sm;
    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;
    int deltaX = x0 - x;
    int deltaY = y0 - y;
    return new IntegerComponentRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this);
}
Also used : SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) SampleModel(java.awt.image.SampleModel) Rectangle(java.awt.Rectangle) Point(java.awt.Point) RasterFormatException(java.awt.image.RasterFormatException) Point(java.awt.Point)

Example 15 with RasterFormatException

use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.

the class BytePackedRaster method createWritableChild.

/**
     * Creates a Writable subRaster given a region of the Raster. The x and y
     * coordinates specify the horizontal and vertical offsets
     * from the upper-left corner of this Raster to the upper-left corner
     * of the subRaster.  The bandList is ignored.
     * A translation to the subRaster may also be specified.
     * Note that the subRaster will reference the same
     * DataBuffer as the parent Raster, but using different offsets.
     * @param x               X offset.
     * @param y               Y offset.
     * @param width           Width (in pixels) of the subraster.
     * @param height          Height (in pixels) of the subraster.
     * @param x0              Translated X origin of the subraster.
     * @param y0              Translated Y origin of the subraster.
     * @param bandList        Array of band indices.
     * @exception RasterFormatException
     *            if the specified bounding box is outside of the parent Raster.
     */
public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside the raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside the raster");
    }
    if ((x + width < x) || (x + width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y + height < y) || (y + height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }
    SampleModel sm;
    if (bandList != null) {
        sm = sampleModel.createSubsetSampleModel(bandList);
    } else {
        sm = sampleModel;
    }
    int deltaX = x0 - x;
    int deltaY = y0 - y;
    return new BytePackedRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this);
}
Also used : MultiPixelPackedSampleModel(java.awt.image.MultiPixelPackedSampleModel) SampleModel(java.awt.image.SampleModel) Rectangle(java.awt.Rectangle) Point(java.awt.Point) RasterFormatException(java.awt.image.RasterFormatException) Point(java.awt.Point)

Aggregations

RasterFormatException (java.awt.image.RasterFormatException)17 Point (java.awt.Point)14 Rectangle (java.awt.Rectangle)10 SampleModel (java.awt.image.SampleModel)9 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)6 ComponentSampleModel (java.awt.image.ComponentSampleModel)4 BandedSampleModel (java.awt.image.BandedSampleModel)2 BufferedImage (java.awt.image.BufferedImage)2 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)2 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)1 WritableRaster (java.awt.image.WritableRaster)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 IIOImage (javax.imageio.IIOImage)1 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)1 ImageWriteParam (javax.imageio.ImageWriteParam)1 ImageWriter (javax.imageio.ImageWriter)1 IIOMetadata (javax.imageio.metadata.IIOMetadata)1 ImageOutputStream (javax.imageio.stream.ImageOutputStream)1