0N/A/*
2362N/A * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
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 *
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 *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.image;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport java.awt.image.RasterFormatException;
0N/Aimport java.awt.image.SampleModel;
0N/Aimport java.awt.image.ComponentSampleModel;
0N/Aimport java.awt.image.PixelInterleavedSampleModel;
0N/Aimport java.awt.image.SinglePixelPackedSampleModel;
0N/Aimport java.awt.image.DataBuffer;
0N/Aimport java.awt.image.DataBufferUShort;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.Point;
0N/A
0N/A/**
0N/A * This class defines a Raster with pixels consisting of one or more 16-bit
0N/A * data elements stored in close proximity to each other in a short integer
0N/A * array. The bit precision per data element is that
0N/A * of the data type (that is, the bit precision for this Raster is 16).
0N/A * There is only one pixel stride and one scanline stride for all
0N/A * bands. This type of Raster can be used with a
0N/A * ComponentColorModel if there are multiple bands, or a
0N/A * IndexColorModel if there is only one band.
0N/A * <p>
0N/A * For example, 5-6-5 RGB image data can be represented by a
0N/A * ShortInterleavedRaster using a SinglePixelPackedSampleModel and
0N/A * a ComponentColorModel.
0N/A *
0N/A *
0N/A */
0N/Apublic class ShortInterleavedRaster extends ShortComponentRaster {
0N/A
0N/A /** A cached copy of minX + width for use in bounds checks. */
0N/A private int maxX;
0N/A
0N/A /** A cached copy of minY + height for use in bounds checks. */
0N/A private int maxY;
0N/A
0N/A /**
0N/A * Constructs a ShortInterleavedRaster with the given SampleModel.
0N/A * The Raster's upper left corner is origin and it is the same
0N/A * size as the SampleModel. A DataBuffer large enough to describe the
0N/A * Raster is automatically created. SampleModel must be of type
0N/A * PixelInterleavedSampleModel or SinglePixelPackedSampleModel.
0N/A * @param sampleModel The SampleModel that specifies the layout.
0N/A * @param origin The Point that specified the origin.
0N/A */
0N/A public ShortInterleavedRaster(SampleModel sampleModel, Point origin) {
0N/A this(sampleModel,
0N/A sampleModel.createDataBuffer(),
0N/A new Rectangle(origin.x,
0N/A origin.y,
0N/A sampleModel.getWidth(),
0N/A sampleModel.getHeight()),
0N/A origin,
0N/A null);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a ShortInterleavedRaster with the given SampleModel
0N/A * and DataBuffer. The Raster's upper left corner is origin and
0N/A * it is the same sizes the SampleModel. The DataBuffer is not
0N/A * initialized and must be a DataBufferUShort compatible with SampleModel.
0N/A * SampleModel must be of type PixelInterleavedSampleModel or
0N/A * SinglePixelPackedSampleModel.
0N/A * @param sampleModel The SampleModel that specifies the layout.
0N/A * @param dataBuffer The DataBufferUShort that contains the image data.
0N/A * @param origin The Point that specifies the origin.
0N/A */
0N/A public ShortInterleavedRaster(SampleModel sampleModel,
0N/A DataBuffer dataBuffer,
0N/A Point origin) {
0N/A this(sampleModel,
0N/A dataBuffer,
0N/A new Rectangle(origin.x,
0N/A origin.y,
0N/A sampleModel.getWidth(),
0N/A sampleModel.getHeight()),
0N/A origin,
0N/A null);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a ShortInterleavedRaster with the given SampleModel,
0N/A * DataBuffer, and parent. DataBuffer must be a DataBufferUShort and
0N/A * SampleModel must be of type PixelInterleavedSampleModel or
0N/A * SinglePixelPackedSampleModel. When translated into the base Raster's
0N/A * coordinate system, aRegion must be contained by the base Raster.
0N/A * Origin is the coodinate in the new Raster's coordinate system of
0N/A * the origin of the base Raster. (The base Raster is the Raster's
0N/A * ancestor which has no parent.)
0N/A *
0N/A * Note that this constructor should generally be called by other
0N/A * constructors or create methods, it should not be used directly.
0N/A * @param sampleModel The SampleModel that specifies the layout.
0N/A * @param dataBuffer The DataBufferUShort that contains the image data.
0N/A * @param aRegion The Rectangle that specifies the image area.
0N/A * @param origin The Point that specifies the origin.
0N/A * @param parent The parent (if any) of this raster.
0N/A */
0N/A public ShortInterleavedRaster(SampleModel sampleModel,
0N/A DataBuffer dataBuffer,
0N/A Rectangle aRegion,
0N/A Point origin,
0N/A ShortInterleavedRaster parent) {
0N/A
0N/A super(sampleModel, dataBuffer, aRegion, origin, parent);
0N/A this.maxX = minX + width;
0N/A this.maxY = minY + height;
0N/A
0N/A if(!(dataBuffer instanceof DataBufferUShort)) {
0N/A throw new RasterFormatException("ShortInterleavedRasters must "+
0N/A "have ushort DataBuffers");
0N/A }
0N/A
0N/A DataBufferUShort dbus = (DataBufferUShort)dataBuffer;
0N/A this.data = stealData(dbus, 0);
0N/A
0N/A // REMIND: need case for interleaved ComponentSampleModel
0N/A if ((sampleModel instanceof PixelInterleavedSampleModel) ||
0N/A (sampleModel instanceof ComponentSampleModel &&
0N/A sampleModel.getNumBands() == 1)) {
0N/A ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
0N/A
0N/A this.scanlineStride = csm.getScanlineStride();
0N/A this.pixelStride = csm.getPixelStride();
0N/A this.dataOffsets = csm.getBandOffsets();
0N/A int xOffset = aRegion.x - origin.x;
0N/A int yOffset = aRegion.y - origin.y;
0N/A for (int i = 0; i < getNumDataElements(); i++) {
0N/A dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
0N/A }
0N/A } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
0N/A SinglePixelPackedSampleModel sppsm =
0N/A (SinglePixelPackedSampleModel)sampleModel;
0N/A this.scanlineStride = sppsm.getScanlineStride();
0N/A this.pixelStride = 1;
0N/A this.dataOffsets = new int[1];
0N/A this.dataOffsets[0] = dbus.getOffset();
0N/A int xOffset = aRegion.x - origin.x;
0N/A int yOffset = aRegion.y - origin.y;
0N/A dataOffsets[0] += xOffset+yOffset*scanlineStride;
0N/A } else {
0N/A throw new RasterFormatException("ShortInterleavedRasters must "+
0N/A "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
0N/A " or 1 band ComponentSampleModel. Sample model is "+
0N/A sampleModel);
0N/A }
0N/A this.bandOffset = this.dataOffsets[0];
5708N/A verify();
0N/A }
0N/A
0N/A /**
0N/A * Returns a copy of the data offsets array. For each band the data offset
0N/A * is the index into the band's data array, of the first sample of the
0N/A * band.
0N/A */
0N/A public int[] getDataOffsets() {
0N/A return (int[]) dataOffsets.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns the data offset for the specified band. The data offset
0N/A * is the index into the data array in which the first sample
0N/A * of the first scanline is stored.
0N/A * @param band The band whose offset is returned.
0N/A */
0N/A public int getDataOffset(int band) {
0N/A return dataOffsets[band];
0N/A }
0N/A
0N/A /**
0N/A * Returns the scanline stride -- the number of data array elements between
0N/A * a given sample and the same sample in the same column of the next row.
0N/A */
0N/A public int getScanlineStride() {
0N/A return scanlineStride;
0N/A }
0N/A
0N/A /**
0N/A * Returns pixel stride -- the number of data array elements between two
0N/A * samples for the same band on the same scanline.
0N/A */
0N/A public int getPixelStride() {
0N/A return pixelStride;
0N/A }
0N/A
0N/A /**
0N/A * Returns a reference to the data array.
0N/A */
0N/A public short[] getDataStorage() {
0N/A return data;
0N/A }
0N/A
0N/A /**
0N/A * Returns the data elements for all bands at the specified
0N/A * location.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinate is out of bounds.
0N/A * A ClassCastException will be thrown if the input object is non null
0N/A * and references anything other than an array of transferType.
0N/A * @param x The X coordinate of the pixel location.
0N/A * @param y The Y coordinate of the pixel location.
0N/A * @param outData An object reference to an array of type defined by
0N/A * getTransferType() and length getNumDataElements().
0N/A * If null an array of appropriate type and size will be
0N/A * allocated.
0N/A * @return An object reference to an array of type defined by
0N/A * getTransferType() with the request pixel data.
0N/A */
0N/A public Object getDataElements(int x, int y, Object obj) {
0N/A if ((x < this.minX) || (y < this.minY) ||
0N/A (x >= this.maxX) || (y >= this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A short outData[];
0N/A if (obj == null) {
0N/A outData = new short[numDataElements];
0N/A } else {
0N/A outData = (short[])obj;
0N/A }
0N/A int off = (y-minY)*scanlineStride +
0N/A (x-minX)*pixelStride;
0N/A
0N/A for (int band = 0; band < numDataElements; band++) {
0N/A outData[band] = data[dataOffsets[band] + off];
0N/A }
0N/A
0N/A return outData;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of data elements from the specified rectangular
0N/A * region.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinates are out of bounds.
0N/A * A ClassCastException will be thrown if the input object is non null
0N/A * and references anything other than an array of transferType.
0N/A * <pre>
0N/A * short[] bandData = (short[])Raster.getDataElements(x, y, w, h, null);
0N/A * int numDataElements = Raster.getBands();
0N/A * short[] pixel = new short[numDataElements];
0N/A * // To find the data element at location (x2, y2)
0N/A * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
0N/A * pixel, 0, numDataElements);
0N/A * </pre>
0N/A * @param x The X coordinate of the upper left pixel location.
0N/A * @param y The Y coordinate of the upper left pixel location.
0N/A * @param width Width of the pixel rectangle.
0N/A * @param height Height of the pixel rectangle.
0N/A * @param outData An object reference to an array of type defined by
0N/A * getTransferType() and length w*h*getNumDataElements().
0N/A * If null an array of appropriate type and size will be
0N/A * allocated.
0N/A * @return An object reference to an array of type defined by
0N/A * getTransferType() with the request pixel data.
0N/A */
0N/A public Object getDataElements(int x, int y, int w, int h, Object obj) {
0N/A if ((x < this.minX) || (y < this.minY) ||
0N/A (x + w > this.maxX) || (y + h > this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A short outData[];
0N/A if (obj == null) {
0N/A outData = new short[w*h*numDataElements];
0N/A } else {
0N/A outData = (short[])obj;
0N/A }
0N/A int yoff = (y-minY)*scanlineStride +
0N/A (x-minX)*pixelStride;
0N/A
0N/A int xoff;
0N/A int off = 0;
0N/A int xstart;
0N/A int ystart;
0N/A
0N/A for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
0N/A xoff = yoff;
0N/A for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
0N/A for (int c = 0; c < numDataElements; c++) {
0N/A outData[off++] = data[dataOffsets[c] + xoff];
0N/A }
0N/A }
0N/A }
0N/A
0N/A return outData;
0N/A }
0N/A
0N/A /**
0N/A * Returns a short integer array of data elements from the
0N/A * specified rectangular region.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinates are out of bounds.
0N/A * <pre>
0N/A * short[] bandData = Raster.getShortData(x, y, w, h, null);
0N/A * // To find the data element at location (x2, y2)
0N/A * short dataElenent = bandData[((y2-y)*w + (x2-x))];
0N/A * </pre>
0N/A * @param x The X coordinate of the upper left pixel location.
0N/A * @param y The Y coordinate of the upper left pixel location.
0N/A * @param width Width of the sample rectangle.
0N/A * @param height Height of the sample rectangle.
0N/A * @param band The band to return.
0N/A * @param outData If non-null, data elements for all bands
0N/A * at the specified location are returned in this array.
0N/A * @return Data array with data elements for all bands.
0N/A */
0N/A public short[] getShortData(int x, int y, int w, int h,
0N/A int band, short[] outData) {
0N/A // Bounds check for 'band' will be performed automatically
0N/A if ((x < this.minX) || (y < this.minY) ||
0N/A (x + w > this.maxX) || (y + h > this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A if (outData == null) {
0N/A outData = new short[numDataElements*w*h];
0N/A }
0N/A int yoff = (y-minY)*scanlineStride +
0N/A (x-minX)*pixelStride+ dataOffsets[band];
0N/A int xoff;
0N/A int off = 0;
0N/A int xstart;
0N/A int ystart;
0N/A
0N/A if (pixelStride == 1) {
0N/A if (scanlineStride == w) {
0N/A System.arraycopy(data, yoff, outData, 0, w*h);
0N/A }
0N/A else {
0N/A for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
0N/A System.arraycopy(data, yoff, outData, off, w);
0N/A off += w;
0N/A }
0N/A }
0N/A }
0N/A else {
0N/A for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
0N/A xoff = yoff;
0N/A for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
0N/A outData[off++] = data[xoff];
0N/A }
0N/A }
0N/A }
0N/A
0N/A return outData;
0N/A }
0N/A
0N/A /**
0N/A * Returns a short integer array of data elements from the
0N/A * specified rectangular region.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinates are out of bounds.
0N/A * <pre>
0N/A * short[] bandData = Raster.getShortData(x, y, w, h, null);
0N/A * int numDataElements = Raster.getNumBands();
0N/A * short[] pixel = new short[numDataElements];
0N/A * // To find the data element at location (x2, y2)
0N/A * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
0N/A * pixel, 0, numDataElements);
0N/A * </pre>
0N/A * @param x The X coordinate of the upper left pixel location.
0N/A * @param y The Y coordinate of the upper left pixel location.
0N/A * @param width Width of the pixel rectangle.
0N/A * @param height Height of the pixel rectangle.
0N/A * @param outData If non-null, data elements for all bands
0N/A * at the specified location are returned in this array.
0N/A * @return Data array with data elements for all bands.
0N/A */
0N/A public short[] getShortData(int x, int y, int w, int h, short[] outData) {
0N/A if ((x < this.minX) || (y < this.minY) ||
0N/A (x + w > this.maxX) || (y + h > this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A if (outData == null) {
0N/A outData = new short[numDataElements*w*h];
0N/A }
0N/A int yoff = (y-minY)*scanlineStride +
0N/A (x-minX)*pixelStride;
0N/A int xoff;
0N/A int off = 0;
0N/A int xstart;
0N/A int ystart;
0N/A
0N/A for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
0N/A xoff = yoff;
0N/A for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
0N/A for (int c = 0; c < numDataElements; c++) {
0N/A outData[off++] = data[dataOffsets[c] + xoff];
0N/A }
0N/A }
0N/A }
0N/A
0N/A return outData;
0N/A }
0N/A
0N/A /**
0N/A * Stores the data elements for all bands at the specified location.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinate is out of bounds.
0N/A * A ClassCastException will be thrown if the input object is non null
0N/A * and references anything other than an array of transferType.
0N/A * @param x The X coordinate of the pixel location.
0N/A * @param y The Y coordinate of the pixel location.
0N/A * @param inData An object reference to an array of type defined by
0N/A * getTransferType() and length getNumDataElements()
0N/A * containing the pixel data to place at x,y.
0N/A */
0N/A public void setDataElements(int x, int y, Object obj) {
0N/A if ((x < this.minX) || (y < this.minY) ||
0N/A (x >= this.maxX) || (y >= this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A short inData[] = (short[])obj;
0N/A int off = (y-minY)*scanlineStride +
0N/A (x-minX)*pixelStride;
0N/A for (int i = 0; i < numDataElements; i++) {
0N/A data[dataOffsets[i] + off] = (short) inData[i];
0N/A }
0N/A markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Stores the Raster data at the specified location.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinates are out of bounds.
0N/A * @param x The X coordinate of the pixel location.
0N/A * @param y The Y coordinate of the pixel location.
0N/A * @param inRaster Raster of data to place at x,y location.
0N/A */
0N/A public void setDataElements(int x, int y, Raster inRaster) {
0N/A int dstOffX = x + inRaster.getMinX();
0N/A int dstOffY = y + inRaster.getMinY();
0N/A int width = inRaster.getWidth();
0N/A int height = inRaster.getHeight();
0N/A if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
0N/A (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A
0N/A setDataElements(dstOffX, dstOffY, width, height, inRaster);
0N/A }
0N/A
0N/A /**
0N/A * Stores the Raster data at the specified location.
0N/A * @param dstX The absolute X coordinate of the destination pixel
0N/A * that will receive a copy of the upper-left pixel of the
0N/A * inRaster
0N/A * @param dstY The absolute Y coordinate of the destination pixel
0N/A * that will receive a copy of the upper-left pixel of the
0N/A * inRaster
0N/A * @param width The number of pixels to store horizontally
0N/A * @param height The number of pixels to store vertically
0N/A * @param inRaster Raster of data to place at x,y location.
0N/A */
0N/A private void setDataElements(int dstX, int dstY,
0N/A int width, int height,
0N/A Raster inRaster) {
0N/A // Assume bounds checking has been performed previously
0N/A if (width <= 0 || height <= 0) {
0N/A return;
0N/A }
0N/A
0N/A // Write inRaster (minX, minY) to (dstX, dstY)
0N/A
0N/A int srcOffX = inRaster.getMinX();
0N/A int srcOffY = inRaster.getMinY();
0N/A Object tdata = null;
0N/A
0N/A// REMIND: Do something faster!
0N/A// if (inRaster instanceof ShortInterleavedRaster) {
0N/A// }
0N/A
0N/A for (int startY=0; startY < height; startY++) {
0N/A // Grab one scanline at a time
0N/A tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
0N/A width, 1, tdata);
0N/A setDataElements(dstX, dstY + startY, width, 1, tdata);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Stores an array of data elements into the specified rectangular
0N/A * region.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinates are out of bounds.
0N/A * A ClassCastException will be thrown if the input object is non null
0N/A * and references anything other than an array of transferType.
0N/A * The data elements in the
0N/A * data array are assumed to be packed. That is, a data element
0N/A * for the nth band at location (x2, y2) would be found at:
0N/A * <pre>
0N/A * inData[((y2-y)*w + (x2-x))*numDataElements + n]
0N/A * </pre>
0N/A * @param x The X coordinate of the upper left pixel location.
0N/A * @param y The Y coordinate of the upper left pixel location.
0N/A * @param w Width of the pixel rectangle.
0N/A * @param h Height of the pixel rectangle.
0N/A * @param inData An object reference to an array of type defined by
0N/A * getTransferType() and length w*h*getNumDataElements()
0N/A * containing the pixel data to place between x,y and
0N/A * x+h, y+h.
0N/A */
0N/A public void setDataElements(int x, int y, int w, int h, Object obj) {
0N/A if ((x < this.minX) || (y < this.minY) ||
0N/A (x + w > this.maxX) || (y + h > this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A short inData[] = (short[])obj;
0N/A int yoff = (y-minY)*scanlineStride +
0N/A (x-minX)*pixelStride;
0N/A int xoff;
0N/A int off = 0;
0N/A int xstart;
0N/A int ystart;
0N/A
0N/A for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
0N/A xoff = yoff;
0N/A for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
0N/A for (int c = 0; c < numDataElements; c++) {
0N/A data[dataOffsets[c] + xoff] = (short) inData[off++];
0N/A }
0N/A }
0N/A }
0N/A
0N/A markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Stores a short integer array of data elements into the
0N/A * specified rectangular region.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinates are out of bounds.
0N/A * The data elements in the
0N/A * data array are assumed to be packed. That is, a data element
0N/A * at location (x2, y2) would be found at:
0N/A * <pre>
0N/A * inData[((y2-y)*w + (x2-x))]
0N/A * </pre>
0N/A * @param x The X coordinate of the upper left pixel location.
0N/A * @param y The Y coordinate of the upper left pixel location.
0N/A * @param w Width of the pixel rectangle.
0N/A * @param h Height of the pixel rectangle.
0N/A * @param band The band to set.
0N/A * @param inData The data elements to be stored.
0N/A */
0N/A public void putShortData(int x, int y, int w, int h,
0N/A int band, short[] inData) {
0N/A // Bounds check for 'band' will be performed automatically
0N/A if ((x < this.minX) || (y < this.minY) ||
0N/A (x + w > this.maxX) || (y + h > this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A int yoff = (y-minY)*scanlineStride +
0N/A (x-minX)*pixelStride + dataOffsets[band];
0N/A int xoff;
0N/A int off = 0;
0N/A int xstart;
0N/A int ystart;
0N/A
0N/A if (pixelStride == 1) {
0N/A if (scanlineStride == w) {
0N/A System.arraycopy(inData, 0, data, yoff, w*h);
0N/A }
0N/A else {
0N/A for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
0N/A System.arraycopy(inData, off, data, yoff, w);
0N/A off += w;
0N/A }
0N/A }
0N/A }
0N/A else {
0N/A for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
0N/A xoff = yoff;
0N/A for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
0N/A data[xoff] = inData[off++];
0N/A }
0N/A }
0N/A }
0N/A
0N/A markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Stores a short integer array of data elements into the
0N/A * specified rectangular region.
0N/A * An ArrayIndexOutOfBounds exception will be thrown at runtime
0N/A * if the pixel coordinates are out of bounds.
0N/A * The data elements in the
0N/A * data array are assumed to be packed. That is, a data element
0N/A * for the nth band at location (x2, y2) would be found at:
0N/A * <pre>
0N/A * inData[((y2-y)*w + (x2-x))*numDataElements + n]
0N/A * </pre>
0N/A * @param x The X coordinate of the upper left pixel location.
0N/A * @param y The Y coordinate of the upper left pixel location.
0N/A * @param w Width of the pixel rectangle.
0N/A * @param h Height of the pixel rectangle.
0N/A * @param inData The data elements to be stored.
0N/A */
0N/A public void putShortData(int x, int y, int w, int h, short[] inData) {
0N/A if ((x < this.minX) || (y < this.minY) ||
0N/A (x + w > this.maxX) || (y + h > this.maxY)) {
0N/A throw new ArrayIndexOutOfBoundsException
0N/A ("Coordinate out of bounds!");
0N/A }
0N/A int yoff = (y-minY)*scanlineStride +
0N/A (x-minX)*pixelStride;
0N/A int xoff;
0N/A int off = 0;
0N/A int xstart;
0N/A int ystart;
0N/A
0N/A for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
0N/A xoff = yoff;
0N/A for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
0N/A for (int c = 0; c < numDataElements; c++) {
0N/A data[dataOffsets[c] + xoff] = inData[off++];
0N/A }
0N/A }
0N/A }
0N/A
0N/A markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Creates a subraster given a region of the raster. The x and y
0N/A * coordinates specify the horizontal and vertical offsets
0N/A * from the upper-left corner of this raster to the upper-left corner
0N/A * of the subraster. A subset of the bands of the parent Raster may
0N/A * be specified. If this is null, then all the bands are present in the
0N/A * subRaster. A translation to the subRaster may also be specified.
0N/A * Note that the subraster will reference the same
0N/A * band objects as the parent raster, but using different offsets.
0N/A * @param x X offset.
0N/A * @param y Y offset.
0N/A * @param width Width (in pixels) of the subraster.
0N/A * @param height Height (in pixels) of the subraster.
0N/A * @param x0 Translated X origin of the subraster.
0N/A * @param y0 Translated Y origin of the subraster.
0N/A * @param bandList Array of band indices.
0N/A * @exception RasterFormatException
0N/A * if the specified bounding box is outside of the parent raster.
0N/A */
0N/A public Raster createChild (int x, int y,
0N/A int width, int height,
0N/A int x0, int y0, int[] bandList) {
0N/A WritableRaster newRaster = createWritableChild(x, y,
0N/A width, height,
0N/A x0, y0,
0N/A bandList);
0N/A return (Raster) newRaster;
0N/A }
0N/A
0N/A /**
0N/A * Creates a Writable subRaster given a region of the Raster. The x and y
0N/A * coordinates specify the horizontal and vertical offsets
0N/A * from the upper-left corner of this Raster to the upper-left corner
0N/A * of the subRaster. A subset of the bands of the parent Raster may
0N/A * be specified. If this is null, then all the bands are present in the
0N/A * subRaster. A translation to the subRaster may also be specified.
0N/A * Note that the subRaster will reference the same
0N/A * DataBuffers as the parent Raster, but using different offsets.
0N/A * @param x X offset.
0N/A * @param y Y offset.
0N/A * @param width Width (in pixels) of the subraster.
0N/A * @param height Height (in pixels) of the subraster.
0N/A * @param x0 Translated X origin of the subraster.
0N/A * @param y0 Translated Y origin of the subraster.
0N/A * @param bandList Array of band indices.
0N/A * @exception RasterFormatException
0N/A * if the specified bounding box is outside of the parent Raster.
0N/A */
0N/A public WritableRaster createWritableChild(int x, int y,
0N/A int width, int height,
0N/A int x0, int y0,
0N/A int[] bandList) {
0N/A if (x < this.minX) {
0N/A throw new RasterFormatException("x lies outside the raster");
0N/A }
0N/A if (y < this.minY) {
0N/A throw new RasterFormatException("y lies outside the raster");
0N/A }
0N/A if ((x+width < x) || (x+width > this.minX + this.width)) {
0N/A throw new RasterFormatException("(x + width) is outside of Raster");
0N/A }
0N/A if ((y+height < y) || (y+height > this.minY + this.height)) {
0N/A throw new RasterFormatException("(y + height) is outside of Raster");
0N/A }
0N/A
0N/A SampleModel sm;
0N/A
0N/A if (bandList != null)
0N/A sm = sampleModel.createSubsetSampleModel(bandList);
0N/A else
0N/A sm = sampleModel;
0N/A
0N/A int deltaX = x0 - x;
0N/A int deltaY = y0 - y;
0N/A
0N/A return new ShortInterleavedRaster(sm,
0N/A dataBuffer,
0N/A new Rectangle(x0, y0, width, height),
0N/A new Point(sampleModelTranslateX+deltaX,
0N/A sampleModelTranslateY+deltaY),
0N/A this);
0N/A }
0N/A
0N/A /**
0N/A * Creates a Raster with the same layout but using a different
0N/A * width and height, and with new zeroed data arrays.
0N/A */
0N/A public WritableRaster createCompatibleWritableRaster(int w, int h) {
0N/A if (w <= 0 || h <=0) {
0N/A throw new RasterFormatException("negative "+
0N/A ((w <= 0) ? "width" : "height"));
0N/A }
0N/A
0N/A SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);
0N/A
0N/A return new ShortInterleavedRaster(sm, new Point(0, 0));
0N/A }
0N/A
0N/A /**
0N/A * Creates a Raster with the same layout and the same
0N/A * width and height, and with new zeroed data arrays. If
0N/A * the Raster is a subRaster, this will call
0N/A * createCompatibleRaster(width, height).
0N/A */
0N/A public WritableRaster createCompatibleWritableRaster() {
0N/A return createCompatibleWritableRaster(width,height);
0N/A }
0N/A
0N/A public String toString() {
0N/A return new String ("ShortInterleavedRaster: width = "+width
0N/A +" height = " + height
0N/A +" #numDataElements "+numDataElements);
0N/A // +" xOff = "+xOffset+" yOff = "+yOffset);
0N/A }
0N/A
0N/A}