home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-20 | 35.8 KB | 961 lines |
- /*
- * @(#)Raster.java 1.28 98/03/18
- *
- * Copyright 1997, 1998 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
- */
-
- /* ****************************************************************
- ******************************************************************
- ******************************************************************
- *** COPYRIGHT (c) Eastman Kodak Company, 1997
- *** As an unpublished work pursuant to Title 17 of the United
- *** States Code. All rights reserved.
- ******************************************************************
- ******************************************************************
- ******************************************************************/
-
-
- package java.awt.image;
- import java.awt.Rectangle;
- import java.awt.Point;
-
- import sun.awt.image.BytePackedRaster;
- import sun.awt.image.ShortComponentRaster;
- import sun.awt.image.ByteComponentRaster;
- import sun.awt.image.IntegerComponentRaster;
-
-
-
- /**
- * This class represents a rectanglular array of pixels and provides
- * methods for retrieving image data. It contains a DataBuffer object
- * that holds a buffer of image data in some format, a SampleModel
- * which describes the format is capable of storing and retrieving
- * Samples from the DataBuffer, and a Rect that defines the coordinate
- * space of the raster (upper left corner, width and height).
- *
- * The Raster's coordinate space is determined by a point and a rectangle.
- * The Point is the origin of the base Raster (this raster's ancestor
- * that has no parent.) The rectangle called the bounds determines the
- * span over which this Raster can process pixel and sample requests.
- * A point and a rectangle are needed so that sub rasters can use the
- * same DataBuffer and SampleModel as their parent rasters. The point
- * marks the origin of the SampleModel in the sub raster's coordinate
- * space (possibly translated from the parent's coordinate space.) The
- * rectangle defines the span of the sub raster. For base Rasters, the
- * upper left corner of the bounds rectangle is equal to the origin.
- *
- * All constructors are protected. The correct way to create a Raster
- * is to use one of the static create methods defined in this class.
- */
- public class Raster {
-
- /** SampleModel that describes how pixels are stored in the DataBuffer. */
- protected SampleModel sampleModel;
-
- /** DataBuffer that stores image data. */
- protected DataBuffer dataBuffer;
-
- /** The width of the Raster. */
- protected int width;
-
- /** The height of the Raster. */
- protected int height;
-
- /** The X offset from the global origin. */
- protected int minX;
-
- /** The Y offset from the global origin. */
- protected int minY;
-
- /** The X offset of the base Raster from the global origin. */
- protected int baseRasterOriginX;
-
- /** The Y offset of the base Raster from the global origin. */
- protected int baseRasterOriginY;
-
- /** The number of bands in the raster. */
- protected int numBands;
-
- /** The number of data elements per pixel. */
- protected int numDataElements;
-
- /** If non-null, the parent of this Raster. */
- protected Raster parent;
-
- static private native void initIDs();
- static {
- ColorModel.loadLibraries();
- initIDs();
- }
-
-
- /**
- * Creates a Raster based on a ComponentSampleModel with the specified
- * data type, width, height, and number of bands.
- */
- public static WritableRaster createComponentRaster(int dataType,
- int w, int h,
- int n,
- Point location) {
- int[] bOffs = new int[n];
- for (int i = 0; i < n; i++) {
- bOffs[i] = i;
- }
- return createComponentRaster(dataType, w, h, w*n, n, bOffs, location);
- }
-
- /**
- * Creates a Raster based on a ComponentSampleModel with the specified
- * data type, width, height, scanline stride, pixel stride, and band
- offsets.
- */
- public static WritableRaster createComponentRaster(int dataType,
- int w, int h,
- int scanlineStride,
- int pixelStride,
- int bandOffsets[],
- Point location){
- DataBuffer d;
- int n = bandOffsets.length;
-
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- d = new DataBufferByte(w*h*n);
- break;
-
- case DataBuffer.SHORT_DATA:
- d = new DataBufferShort(w*h*n);
- break;
-
- case DataBuffer.INT_DATA:
- d = new DataBufferInt(w*h*n);
- break;
-
- default:
- throw new IllegalArgumentException("Unknown data type " +
- dataType);
- }
- return createComponentRaster(dataType, w, h, scanlineStride,
- pixelStride, bandOffsets, d, location);
- }
-
- /**
- * Creates a Raster based on a SinglePixelPackedSampleModel with the
- * specified data type, width, height, and band masks.
- */
- public static WritableRaster createPackedRaster(int dataType,
- int w, int h,
- int bandMasks[],
- Point location) {
- DataBuffer d;
-
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- d = new DataBufferByte(w*h);
- break;
-
- case DataBuffer.SHORT_DATA:
- d = new DataBufferShort(w*h);
- break;
-
- case DataBuffer.INT_DATA:
- d = new DataBufferInt(w*h);
- break;
-
- default:
- throw new IllegalArgumentException("Unknown data type " +
- dataType);
- }
- return createPackedRaster(dataType, w, h, w, bandMasks, d, location);
- }
-
- /**
- * Creates a Raster based on a packed SampleModel with the specified
- * data type, width, height, number of bands, and bits per band.
- * If the number of bands is one, the SampleModel will be a
- * MultiPixelPackedSampleModel. If the number of bands is more
- * than one, the SampleModel will be a SinglePixelPackedSampleModel,
- * with each band having bitsPerBand bits. In either case, the
- * requirements on dataType and bitsPerBand imposed by the corresponding
- * SampleModel must be met.
- */
- public static WritableRaster createPackedRaster(int dataType,
- int w, int h,
- int n,
- int bitsPerBand,
- Point location) {
- DataBuffer d;
-
- if (n != 1) {
- int[] masks = new int[n];
- int mask = (1 << bitsPerBand) - 1;
- int shift;
-
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- shift = 8 - n;
- break;
- case DataBuffer.SHORT_DATA:
- shift = 16 - n;
- break;
- case DataBuffer.INT_DATA:
- shift = 32 - n;
- break;
- default:
- throw new IllegalArgumentException("Unknown data type " +
- dataType);
- }
-
- for (int i = 0; i < n; i++) {
- masks[i] = mask << shift;
- shift = shift - n;
- }
-
- return createPackedRaster(dataType, w, h, masks, location);
- }
-
- double fw = w;
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- d = new DataBufferByte((int)(Math.ceil(fw/(8/bitsPerBand)))*h);
- break;
-
- case DataBuffer.SHORT_DATA:
- d = new DataBufferShort((int)(Math.ceil(fw/(16/bitsPerBand)))*h);
- break;
-
- case DataBuffer.INT_DATA:
- d = new DataBufferInt((int)(Math.ceil(fw/(32/bitsPerBand)))*h);
- break;
-
- default:
- throw new IllegalArgumentException("Unknown data type " +
- dataType);
- }
- return createPackedRaster(dataType, w, h, bitsPerBand, d, location);
- }
-
- /**
- * Creates a Raster based on a ComponentSampleModel with the specified
- * data type, width, height, scanline stride, pixel stride, band offsets,
- * and data buffer.
- */
- public static WritableRaster createComponentRaster(int dataType,
- int w, int h,
- int scanlineStride,
- int pixelStride,
- int bandOffsets[],
- DataBuffer dataBuffer,
- Point location) {
- ComponentSampleModel csm = new ComponentSampleModel(dataType, w, h,
- pixelStride,
- scanlineStride,
- bandOffsets);
- if (location == null) {
- location = new Point(0,0);
- }
-
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- return new ByteComponentRaster(csm, dataBuffer, location);
-
- case DataBuffer.SHORT_DATA:
- return new ShortComponentRaster(csm, dataBuffer, location);
-
- case DataBuffer.INT_DATA:
- return new IntegerComponentRaster(csm, dataBuffer, location);
-
- default:
- throw new IllegalArgumentException("Unknown data type " +
- dataType);
- }
- }
-
- /**
- * Creates a Raster based on a SinglePixelPackedSampleModel with the
- * specified data type, width, height, scanline stride, band masks,
- * and data buffer.
- */
- public static WritableRaster createPackedRaster(int dataType,
- int w, int h,
- int scanlineStride,
- int bandMasks[],
- DataBuffer dataBuffer,
- Point location) {
- SinglePixelPackedSampleModel sppsm =
- new SinglePixelPackedSampleModel(dataType, w, h, scanlineStride,
- bandMasks);
- if (location == null) {
- location = new Point(0,0);
- }
-
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- return new ByteComponentRaster(sppsm, dataBuffer, location);
-
- case DataBuffer.SHORT_DATA:
- return new ShortComponentRaster(sppsm, dataBuffer, location);
-
- case DataBuffer.INT_DATA:
- return new IntegerComponentRaster(sppsm, dataBuffer, location);
-
- default:
- throw new IllegalArgumentException("Unknown data type " +
- dataType);
- }
- }
-
- /**
- * Creates a Raster based on a MultiPixelPackedSampleModel with the
- * specified data type, width, height, bits per pixel, and data buffer.
- */
- public static WritableRaster createPackedRaster(int dataType,
- int w, int h,
- int bitsPerPixel,
- DataBuffer dataBuffer,
- Point location) {
- MultiPixelPackedSampleModel sbpsm =
- new MultiPixelPackedSampleModel(dataType, w, h, bitsPerPixel);
-
- if (location == null) {
- location = new Point(0,0);
- }
-
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- return new BytePackedRaster(sbpsm, dataBuffer, location);
-
- case DataBuffer.SHORT_DATA:
- return new WritableRaster(sbpsm, dataBuffer, location);
-
- case DataBuffer.INT_DATA:
- return new WritableRaster(sbpsm, dataBuffer, location);
-
- default:
- throw new IllegalArgumentException("Unknown data type " +
- dataType);
- }
- }
-
-
- /**
- * Creates a Raster with the specified SampleModel
- */
- public static Raster createRaster(SampleModel sm,
- DataBuffer db,
- Point location) {
- if (location == null) {
- location = new Point(0,0);
- }
- int dataType = sm.getDataType();
-
- if (sm instanceof ComponentSampleModel) {
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- return new ByteComponentRaster(sm, db, location);
-
- case DataBuffer.SHORT_DATA:
- return new ShortComponentRaster(sm, db, location);
- }
- } else if (sm instanceof SinglePixelPackedSampleModel) {
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- return new ByteComponentRaster(sm, db, location);
-
- case DataBuffer.SHORT_DATA:
- return new ShortComponentRaster(sm, db, location);
-
- case DataBuffer.INT_DATA:
- return new IntegerComponentRaster(sm, db, location);
- }
- } else if (sm instanceof MultiPixelPackedSampleModel &&
- dataType == DataBuffer.BYTE_DATA) {
- return new BytePackedRaster(sm, db, location);
- }
-
- // we couldn't do anything special - do the generic thing
-
- return new Raster(sm,db,location);
- }
-
- /**
- * Creates a WritableRaster with the specified SampleModel
- */
- public static WritableRaster createWritableRaster(SampleModel sm,
- Point location) {
- if (location == null) {
- location = new Point(0,0);
- }
-
- return createWritableRaster(sm,
- sm.createCompatibleDataBuffer(),
- location);
- }
-
- /**
- * Creates a WritableRaster with the specified SampleModel
- * and DataBuffer
- */
- public static WritableRaster createWritableRaster(SampleModel sm,
- DataBuffer db,
- Point location) {
- if (location == null) {
- location = new Point(0,0);
- }
-
- int dataType = sm.getDataType();
-
- if (sm instanceof ComponentSampleModel) {
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- return new ByteComponentRaster(sm, db, location);
-
- case DataBuffer.SHORT_DATA:
- return new ShortComponentRaster(sm, db, location);
- }
- } else if (sm instanceof SinglePixelPackedSampleModel) {
- switch(dataType) {
- case DataBuffer.BYTE_DATA:
- return new ByteComponentRaster(sm, db, location);
-
- case DataBuffer.SHORT_DATA:
- return new ShortComponentRaster(sm, db, location);
-
- case DataBuffer.INT_DATA:
- return new IntegerComponentRaster(sm, db, location);
- }
- } else if (sm instanceof MultiPixelPackedSampleModel &&
- dataType == DataBuffer.BYTE_DATA) {
- return new BytePackedRaster(sm, db, location);
- }
-
- // we couldn't do anything special - do the generic thing
-
- return new WritableRaster(sm,db,location);
- }
-
- /**
- * Constructs a Raster 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.
- * @param sampleModel The SampleModel that specifies the layout.
- * @param origin The Point that specified the origin.
- */
- protected Raster(SampleModel sampleModel,
- Point origin) {
- this(sampleModel,
- sampleModel.createCompatibleDataBuffer(),
- new Rectangle(origin.x,
- origin.y,
- sampleModel.getWidth(),
- sampleModel.getHeight()),
- origin,
- null);
- }
-
- /**
- * Constructs a Raster with the given SampleModel and DataBuffer.
- * The Raster's upper left corner is origin and it is the same size
- * as the SampleModel. The DataBuffer is not initialized and must
- * be compatible with SampleModel.
- * @param sampleModel The SampleModel that specifies the layout.
- * @param dataBuffer The DataBufferShort that contains the image data.
- * @param origin The Point that specifies the origin.
- */
- protected Raster(SampleModel sampleModel,
- DataBuffer dataBuffer,
- Point origin) {
- this(sampleModel,
- dataBuffer,
- new Rectangle(origin.x,
- origin.y,
- sampleModel.getWidth(),
- sampleModel.getHeight()),
- origin,
- null);
- }
-
- /**
- * Constructs a Raster with the given SampleModel, DataBuffer, and
- * parent. 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 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.
- */
- protected Raster(SampleModel sampleModel,
- DataBuffer dataBuffer,
- Rectangle aRegion,
- Point baseOrigin,
- Raster parent) {
- this.sampleModel = sampleModel;
- this.dataBuffer = dataBuffer;
- minX = aRegion.x;
- minY = aRegion.y;
- width = aRegion.width;
- height = aRegion.height;
-
- baseRasterOriginX = baseOrigin.x;
- baseRasterOriginY = baseOrigin.y;
-
- numBands = sampleModel.getNumBands();
- numDataElements = sampleModel.getNumDataElements();
- this.parent = parent;
- }
-
-
- /** Returns the parent Raster (if any) of this Raster */
- public Raster getParent() {
- return parent;
- }
-
- /**
- * Returns the X coord of the origin of the base Raster in this Raster's
- * coordinate system.
- */
- final public int getBaseRasterOriginX() {
- return baseRasterOriginX;
- }
-
- /**
- * Returns the Y coord of the origin of the base Raster in this Raster's
- * coordinate system.
- */
- final public int getBaseRasterOriginY() {
- return baseRasterOriginY;
- }
-
- /*
- * Returns the X offset in pixels from the base Raster's upper left corner
- * to this Raster's upper left corner.
- */
- final public int getBaseSubRasterOffsetX() {
- return (minX-baseRasterOriginX);
- }
-
- /*
- * Returns the Y offset in pixels from the base Raster's upper left corner
- * to this Raster's upper left corner.
- */
- final public int getBaseSubRasterOffsetY() {
- return (minY-baseRasterOriginY);
- }
-
- /**
- * Create a compatible WritableRaster the same size as this Raster with
- * the same SampleModel and a new initialized DataBuffer.
- */
- public WritableRaster createCompatibleWritableRaster() {
- return createCompatibleWritableRaster(width,height);
- }
-
- /**
- * Create a compatible WritableRaster with the specified size, a new
- * SampleModel, and a new initialized DataBuffer.
- */
- public WritableRaster createCompatibleWritableRaster(int w,
- int h) {
- if (w <= 0 || h <=0) {
- throw new RasterFormatException("negative "+
- ((w <= 0) ? "width" : "height"));
- }
-
- SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);
-
- return new WritableRaster(sm, new Point(0,0));
- }
-
- /**
- * Create a compatible WritableRaster with the specified size, a
- * new SampleModel, and a new initialized DataBuffer. At the
- * specified location.
- */
- public WritableRaster createCompatibleWritableRaster(Rectangle rect) {
- return createCompatibleWritableRaster(rect.x, rect.y,
- rect.width, rect.height);
- }
-
- /**
- * Create a compatible WritableRaster with the specified size, a
- * new SampleModel, and a new initialized DataBuffer. At the
- * specified location.
- */
- public WritableRaster createCompatibleWritableRaster(int x, int y,
- int w, int h) {
- WritableRaster ret = createCompatibleWritableRaster(w, h);
- return ret.createWritableSubRaster(0,0,w,h,x,y,null);
- }
-
- /**
- * Create a Raster with the same size, SampleModel and DataBuffer
- * as this one, but with a different location.
- * @param location The upper left corner of the new returned Raster.
- */
- public Raster createTranslatedRaster(Point location) {
- return createSubRaster(minX,minY,width,height,
- location.x,location.y,null);
- }
-
-
- /**
- * Returns a Raster which references this Raster's DataBuffer
- * @param rect is a rectangle in this Raster's coordinate space. An
- * error is thrown if rect is not fully contained by this Raster.
- */
- public Raster createSubRaster(Rectangle rect) {
- return createSubRaster(rect.x, rect.y,
- rect.width, rect.height,
- rect.x, rect.y,
- null);
- }
-
- /**
- * Returns a Raster which references this Raster's DataBuffer.
- * x,y, width and height form a Rectangle in this Raster's
- * coordinate space. An error is thrown if this rectangle
- * is not fully contained by this Raster.
- * @param x The X coordinate of the upper left hand corner.
- * @param y The Y coordinate of the upper left hand corner.
- * @param width Width of the region starting at (x,y).
- * @param height Height of the region starting at (x,y).
- */
- public Raster createSubRaster(int x, int y, int width, int height) {
- return createSubRaster(x, y, width, height, x, y, null);
- }
-
- /**
- * Returns a translated SubRaster which references this Raster's
- * DataBuffer. x,y, width and height form a Rectangle in this Raster's
- * coordinate space. The new Raster's coordinate system has an upper
- * left corner of x0, y0. An error is thrown if rectangle is not
- * fully contained by this Raster.
- * @param x X of the upper left corner in this Raster's coordinates.
- * @param y Y of the upper left corner in this Raster's coordinates.
- * @param width Width of the region starting at (x,y).
- * @param height Height of the region starting at (x,y).
- * @param x0 X of the upper left corner of returned Raster.
- * @param y0 Y of the upper left corner of returned Raster.
- * @param bandList Array of band indices.
- */
- public Raster createSubRaster(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 > this.width + this.minX) {
- throw new RasterFormatException("(x + width) is outside raster");
- }
- if (y+height > this.height + this.minY) {
- throw new RasterFormatException("(y + height) is outside raster");
- }
-
- SampleModel subSampleModel;
- if (bandList == null) {
- subSampleModel = sampleModel;
- } else {
- subSampleModel =
- sampleModel.createSubsetSampleModel(width, height, bandList);
- }
-
- int deltaX = x0 - x;
- int deltaY = y0 - y;
-
- return new Raster(subSampleModel, dataBuffer,
- new Rectangle(x0, y0, width, height),
- new Point(baseRasterOriginX+deltaX,
- baseRasterOriginY+deltaY), this);
- }
-
- /**
- * Returns the bounds Rectangle of this Raster. This function returns
- * the same information as getMinX/MinY/Width/Height.
- */
- public Rectangle getBounds(){
- return new Rectangle(minX, minY, width, height);
- }
-
- /** Returns the width in pixels of the Raster. */
- final public int getWidth(){
- return width;
- }
-
- /** Returns the height in pixels of the Raster. */
- final public int getHeight(){
- return height;
- }
-
- /** Returns the minimum X coordinate (in the Raster's coordinate system). */
- final public int getMinX() {
- return minX;
- }
-
- /** Returns the minimum Y coordinate (in the Raster's coordinate system). */
- final public int getMinY() {
- return minY;
- }
-
- /** Returns the number of bands in this raster. */
- final public int getNumBands() {
- return numBands;
- }
-
- /** Returns the number of data elements needed to store one pixel. */
- final public int getNumDataElements() {
- return sampleModel.getNumDataElements();
- }
-
- final public int getTransferType() {
- return sampleModel.getTransferType();
- }
-
- /**
- * Returns the data elements containing the pixel at x,y in packed
- * format.
- * There will be no explicit bounds checking on the parameters.
- * An ArrayOutOfBounds exception will be thrown at runtime
- * if data outside of the array is accessed.
- * 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
- * allocated.
- * @return An object reference to an array of type defined by
- * getTransferType() with the request pixel data.
- */
- public Object getPixelData(int x, int y, Object obj) {
- return sampleModel.getPixelData(x-baseRasterOriginX,
- y-baseRasterOriginY, obj, dataBuffer);
- }
-
- /**
- * Returns the data elements containing the pixel data for the pixels
- * in the specified region.
- * There will be no explicit bounds checking on the parameters.
- * An ArrayOutOfBounds exception will be thrown at runtime
- * if data outside of the array is accessed.
- * 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 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
- * allocated.
- * @return An object reference to an array of type defined by
- * getTransferType() with the request pixel data.
- */
- public Object getPixelData(int x, int y, int w, int h, Object obj) {
- return sampleModel.getPixelData(x-baseRasterOriginX,
- y-baseRasterOriginY,
- w, h, obj, dataBuffer);
- }
-
- /**
- * Returns the samples in an array of int for the specified pixel.
- * @param x The X coordinate of the pixel location.
- * @param y The Y coordinate of the pixel location.
- * @param iarray An optionally preallocated int array.
- */
- public int [] getPixel(int x, int y, int iarray[]) {
- return sampleModel.getPixel(x-baseRasterOriginX,
- y-baseRasterOriginY, iarray,
- dataBuffer);
- }
-
- /**
- * Returns the samples in an array of Float for the
- * specified pixel.
- * @param x The X coordinate of the pixel location.
- * @param y The Y coordinate of the pixel location.
- * @param farray An optionally preallocated float array.
- */
- public float [] getPixel(int x, int y, float farray[]) {
- return sampleModel.getPixel(x-baseRasterOriginX,
- y-baseRasterOriginY,
- farray, dataBuffer);
- }
-
- /**
- * Returns the samples in an array of double for the specified pixel
- * @param x The X coordinate of the pixel location.
- * @param y The Y coordinate of the pixel location.
- * @param darray An optionally preallocated double array.
- */
- public double [] getPixel(int x, int y, double darray[]) {
- return sampleModel.getPixel(x-baseRasterOriginX,
- y-baseRasterOriginY,
- darray, dataBuffer);
- }
-
- /**
- * Returns a integer array of pixels representing a region of pixels
- * @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 iarray An optionally pre-allocated int array.
- */
- public int [] getPixel(int x, int y, int w, int h, int iarray[]) {
- return sampleModel.getPixel(x-baseRasterOriginX,
- y-baseRasterOriginY, w, h,
- iarray, dataBuffer);
- }
-
- /**
- * Return a float array of pixels representing a region of pixels
- * @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 farray An optionally pre-allocated float array.
- */
- public float [] getPixel(int x, int y, int w, int h,
- float farray[]){
- return sampleModel.getPixel(x-baseRasterOriginX,
- y-baseRasterOriginY, w, h,
- farray, dataBuffer);
- }
-
- /**
- * Return a double array of pixels representing a region of pixels
- * @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 darray An optionally pre-allocated double array.
- */
- public double [] getPixel(int x, int y, int w, int h,
- double darray[]){
- return sampleModel.getPixel(x-baseRasterOriginX,
- y-baseRasterOriginY,
- w, h, darray, dataBuffer);
- }
-
-
- /**
- * Returns the requested sample in a specified band for a pixel.
- * @param x The X coordinate of the pixel location.
- * @param y The Y coordinate of the pixel location.
- * @param b The band to return.
- */
- public int getSample(int x, int y, int b) {
- return sampleModel.getSample(x-baseRasterOriginX,
- y-baseRasterOriginY, b,
- dataBuffer);
- }
-
- /**
- * Returns the requested sample in a specified band for a pixel.
- * @param x The X coordinate of the pixel location.
- * @param y The Y coordinate of the pixel location.
- * @param b The band to return.
- */
- public float getSampleFloat(int x, int y, int b) {
- return sampleModel.getSampleFloat(x-baseRasterOriginX,
- y-baseRasterOriginY, b,
- dataBuffer);
- }
-
- /**
- * Returns the requested sample in a specified band for a pixel.
- * @param x The X coordinate of the pixel location.
- * @param y The Y coordinate of the pixel location.
- * @param b The band to return.
- */
- public double getSampleDouble(int x, int y, int b) {
- return sampleModel.getSampleDouble(x-baseRasterOriginX,
- y-baseRasterOriginY,
- b, dataBuffer);
- }
-
- /**
- * Returns an array of ints representing a region of samples.
- * @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 b The band to return.
- * @param iarray An optionally pre-allocated int array.
- */
- public int [] getSample(int x, int y, int w, int h, int b,
- int iarray[]) {
- return sampleModel.getSample(x-baseRasterOriginX,
- y-baseRasterOriginY,
- w, h, b, iarray,
- dataBuffer);
- }
-
- /**
- * Returns an array of floats representing a region of samples.
- * @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 b The band to return.
- * @param farray An optionally pre-allocated float array.
- */
- public float [] getSample(int x, int y, int w, int h, int b,
- float farray[]) {
- return sampleModel.getSample(x-baseRasterOriginX,
- y-baseRasterOriginY,
- w, h, b, farray, dataBuffer);
- }
-
- /**
- * Return an array of ints representing a region of samples
- * @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 b The band to return.
- * @param darray An optionally pre-allocated double array.
- */
- public double [] getSample(int x, int y, int w, int h, int b,
- double darray[]) {
- return sampleModel.getSample(x-baseRasterOriginX,
- y-baseRasterOriginY,
- w, h, b, darray, dataBuffer);
- }
-
- /** Returns the DataBuffer associated with this Raster. */
- public DataBuffer getDataBuffer(){
- return dataBuffer;
- }
-
- /** Returns the SampleModel that describes that layout of the image data. */
- public SampleModel getSampleModel(){
- return sampleModel;
- }
- }
-
-
-
-