0N/A * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any * This class defines a Raster with pixels consisting of one or more 32-bit * data elements stored in close proximity to each other in a integer array. * The bit precision per data element is that * of the data type (that is, the bit precision for this raster is 32). * There is only one pixel stride and one scanline stride for all * bands. For a given pixel, all samples fit in N data elements and these * N data elements hold samples for only one pixel. This type of Raster * can be used with a PackedColorModel. * For example, if there is only one data element per pixel, a * SinglePixelPackedSampleModel can be used to represent multiple * bands with a PackedColorModel (including a DirectColorModel) for /** private band offset for use by native code */ /** Data offsets for each band of image data. */ /** Scanline stride of the image data contained in this Raster. */ /** Pixel stride of the image data contained in this Raster. */ /** The image data array. */ /** The number of data elements required to store a pixel. */ /** A cached copy of minX + width for use in bounds checks. */ /** A cached copy of minY + height for use in bounds checks. */ static private native void initIDs();
/* ensure that the necessary native libraries are loaded */ * Constructs a IntegerComponentRaster with the given SampleModel. * The Raster's upper left corner is origin and it is the same * size as the SampleModel. A DataBuffer large enough to describe the * Raster is automatically created. SampleModel must be of type * SinglePixelPackedSampleModel. * @param sampleModel The SampleModel that specifies the layout. * @param origin The Point that specified the origin. * Constructs a IntegerComponentRaster with the given SampleModel * and DataBuffer. The Raster's upper left corner is origin and * it is the same sizes the SampleModel. The DataBuffer is not * initialized and must be a DataBufferInt compatible with SampleModel. * SampleModel must be of type SinglePixelPackedSampleModel. * @param sampleModel The SampleModel that specifies the layout. * @param dataBuffer The DataBufferInt that contains the image data. * @param origin The Point that specifies the origin. * Constructs a IntegerComponentRaster with the given SampleModel, * DataBuffer, and parent. DataBuffer must be a DataBufferInt and * SampleModel must be of type SinglePixelPackedSampleModel. * When translated into the base Raster's * coordinate system, aRegion must be contained by the base Raster. * Origin is the coodinate 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 DataBufferInt 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. " must only have 1 bank.");
" SinglePixelPackedSampleModel");
* Returns a copy of the data offsets array. For each band the data offset * is the index into the band's data array, of the first sample of the * Returns data offset for the specified band. The data offset * is the index into the data array in which the first sample * of the first scanline is stored. * Returns the scanline stride -- the number of data array elements between * a given sample and the sample in the same column of the next row. * Returns pixel stride -- the number of data array elements between two * samples for the same band on the same scanline. * Returns a reference to the data array. * Returns the data elements for all bands at the specified * An ArrayIndexOutOfBounds exception will be thrown at runtime * if the pixel coordinate is out of bounds. * A ClassCastException will be thrown if the input object is non null * and references anything other than an array of transferType. * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param outData An object reference to an array of type defined by * getTransferType() and length getNumDataElements(). * If null an array of appropriate type and size will be * @return An object reference to an array of type defined by * getTransferType() with the request pixel data. if ((x <
this.
minX) || (y <
this.
minY) ||
(
"Coordinate out of bounds!");
* Returns an array of data elements from the specified rectangular * An ArrayIndexOutOfBounds exception will be thrown at runtime * if the pixel coordinates are out of bounds. * A ClassCastException will be thrown if the input object is non null * and references anything other than an array of transferType. * int[] bandData = (int[])raster.getDataElements(x, y, w, h, null); * int numDataElements = raster.getNumDataElements(); * int[] pixel = new int[numDataElements]; * // To find a data element at location (x2, y2) * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements, * pixel, 0, numDataElements); * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate of the upper left pixel location. * @param width Width of the pixel rectangle. * @param height Height of the pixel rectangle. * @param outData An object reference to an array of type defined by * getTransferType() and length w*h*getNumDataElements(). * If null an array of appropriate type and size will be * @return An object reference to an array of type defined by * getTransferType() with the request pixel data. if ((x <
this.
minX) || (y <
this.
minY) ||
(x + w >
this.
maxX) || (y + h >
this.
maxY)) {
(
"Coordinate out of bounds!");
if (
obj instanceof int[]) {
* Stores the data elements for all bands at the specified location. * An ArrayIndexOutOfBounds exception will be thrown at runtime * if the pixel coordinate is out of bounds. * A ClassCastException will be thrown if the input object is non null * and references anything other than an array of transferType. * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param inData An object reference to an array of type defined by * getTransferType() and length getNumDataElements() * containing the pixel data to place at x,y. if ((x <
this.
minX) || (y <
this.
minY) ||
(
"Coordinate out of bounds!");
* Stores the Raster data at the specified location. * The transferType of the inputRaster must match this raster. * An ArrayIndexOutOfBoundsException will be thrown at runtime * if the pixel coordinates are out of bounds. * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param inRaster Raster of data to place at x,y location. (
"Coordinate out of bounds!");
* Stores the Raster data at the specified location. * @param dstX The absolute X coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * @param dstY The absolute Y coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * @param width The number of pixels to store horizontally * @param height The number of pixels to store vertically * @param inRaster Raster of data to place at x,y location. // Assume bounds checking has been performed previously // Write inRaster (minX, minY) to (dstX, dstY) // Extract the raster parameters // Fastest case. We can copy scanlines // Loop through all of the scanlines and copy the data * Stores an array of data elements into the specified rectangular * An ArrayIndexOutOfBounds exception will be thrown at runtime * if the pixel coordinates are out of bounds. * A ClassCastException will be thrown if the input object is non null * and references anything other than an array of transferType. * The data elements in the * data array are assumed to be packed. That is, a data element * for the nth band at location (x2, y2) would be found at: * inData[((y2-y)*w + (x2-x))*numDataElements + n] * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate of the upper left pixel location. * @param w Width of the pixel rectangle. * @param h Height of the pixel rectangle. * @param inData An object reference to an array of type defined by * getTransferType() and length w*h*getNumDataElements() * containing the pixel data to place between x,y and if ((x <
this.
minX) || (y <
this.
minY) ||
(x + w >
this.
maxX) || (y + h >
this.
maxY)) {
(
"Coordinate out of bounds!");
* 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 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. * 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. Note that the subraster will reference the same * DataBuffer as the parent raster, but using different offsets. * @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. * Creates a raster with the same band layout but using a different * width and height, and with new zeroed data arrays. ((w <=
0) ?
"width" :
"height"));
* Creates a raster with the same data layout and the same * width and height, and with new zeroed data arrays. If * the raster is a subraster, this will call * createCompatibleRaster(width, height). * 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 // we can be sure that width and height are greater than 0 return new String (
"IntegerComponentRaster: width = "+
width // * For debugging... prints a region of a one-band IntegerComponentRaster // public void print(int x, int y, int w, int h) { // // REMIND: Only works for 1 band! // System.out.println(this); // int offset = dataOffsets[0] + y*scanlineStride + x*pixelStride; // for (int yoff=0; yoff < h; yoff++, offset += scanlineStride) { // System.out.print("Line "+(sampleModelTranslateY+y+yoff)+": "); // for (int xoff = 0; xoff < w; xoff++, off+= pixelStride) { // System.out.print(Integer.toHexString(data[off])+" "); // System.out.println("");