📄 writableraster.java
字号:
/* * @(#)WritableRaster.java 1.46 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* **************************************************************** ****************************************************************** ****************************************************************** *** 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;/** * This class extends Raster to provide pixel writing capabilities. * Refer to the class comment for Raster for descriptions of how * a Raster stores pixels. * * <p> The constructors of this class are protected. To instantiate * a WritableRaster, use one of the createWritableRaster factory methods * in the Raster class. */public class WritableRaster extends Raster { /** * Constructs a WritableRaster with the given SampleModel. The * WritableRaster's upper left corner is origin and it is the * same size as the SampleModel. A DataBuffer large enough to * describe the WritableRaster is automatically created. * @param sampleModel The SampleModel that specifies the layout. * @param origin The Point that specifies the origin. * @throws RasterFormatException if computing either * <code>origin.x + sampleModel.getWidth()</code> or * <code>origin.y + sampleModel.getHeight()</code> results * in integer overflow */ protected WritableRaster(SampleModel sampleModel, Point origin) { this(sampleModel, sampleModel.createDataBuffer(), new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null); } /** * Constructs a WritableRaster with the given SampleModel and DataBuffer. * The WritableRaster'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 DataBuffer that contains the image data. * @param origin The Point that specifies the origin. * @throws RasterFormatException if computing either * <code>origin.x + sampleModel.getWidth()</code> or * <code>origin.y + sampleModel.getHeight()</code> results * in integer overflow */ protected WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin) { this(sampleModel, dataBuffer, new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null); } /** * Constructs a WritableRaster with the given SampleModel, DataBuffer, * and parent. aRegion specifies the bounding rectangle of the new * Raster. When translated into the base Raster's coordinate * system, aRegion must be contained by the base Raster. * (The base Raster is the Raster's ancestor which has no parent.) * sampleModelTranslate specifies the sampleModelTranslateX and * sampleModelTranslateY values of the new Raster. * * 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 DataBuffer that contains the image data. * @param aRegion The Rectangle that specifies the image area. * @param sampleModelTranslate The Point that specifies the translation * from SampleModel to Raster coordinates. * @param parent The parent (if any) of this raster. * @throws RasterFormatException if <code>aRegion</code> has width * or height less than or equal to zero, or computing either * <code>aRegion.x + aRegion.width</code> or * <code>aRegion.y + aRegion.height</code> results in integer * overflow */ protected WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point sampleModelTranslate, WritableRaster parent){ super(sampleModel,dataBuffer,aRegion,sampleModelTranslate,parent); } /** Returns the parent WritableRaster (if any) of this WritableRaster, * or else null. * @return the parent of this <code>WritableRaster</code>, or * <code>null</code>. */ public WritableRaster getWritableParent() { return (WritableRaster)parent; } /** * Create a WritableRaster with the same size, SampleModel and DataBuffer * as this one, but with a different location. The new WritableRaster * will possess a reference to the current WritableRaster, accessible * through its getParent() and getWritableParent() methods. * * @param childMinX X coord of the upper left corner of the new Raster. * @param childMinY Y coord of the upper left corner of the new Raster. * @return a <code>WritableRaster</code> the same as this one except * for the specified location. * @throws RasterFormatException if computing either * <code>childMinX + this.getWidth()</code> or * <code>childMinY + this.getHeight()</code> results in integer * overflow */ public WritableRaster createWritableTranslatedChild(int childMinX, int childMinY) { return createWritableChild(minX,minY,width,height, childMinX,childMinY,null); } /** * Returns a new WritableRaster which shares all or part of this * WritableRaster's DataBuffer. The new WritableRaster will * possess a reference to the current WritableRaster, accessible * through its getParent() and getWritableParent() methods. * * <p> The parentX, parentY, width and height parameters form a * Rectangle in this WritableRaster's coordinate space, indicating * the area of pixels to be shared. An error will be thrown if * this Rectangle is not contained with the bounds of the current * WritableRaster. * * <p> The new WritableRaster may additionally be translated to a * different coordinate system for the plane than that used by the current * WritableRaster. The childMinX and childMinY parameters give * the new (x, y) coordinate of the upper-left pixel of the * returned WritableRaster; the coordinate (childMinX, childMinY) * in the new WritableRaster will map to the same pixel as the * coordinate (parentX, parentY) in the current WritableRaster. * * <p> The new WritableRaster may be defined to contain only a * subset of the bands of the current WritableRaster, possibly * reordered, by means of the bandList parameter. If bandList is * null, it is taken to include all of the bands of the current * WritableRaster in their current order. * * <p> To create a new WritableRaster that contains a subregion of * the current WritableRaster, but shares its coordinate system * and bands, this method should be called with childMinX equal to * parentX, childMinY equal to parentY, and bandList equal to * null. * * @param parentX X coordinate of the upper left corner in this * WritableRaster's coordinates. * @param parentY Y coordinate of the upper left corner in this * WritableRaster's coordinates. * @param w Width of the region starting at (parentX, parentY). * @param h Height of the region starting at (parentX, parentY). * @param childMinX X coordinate of the upper left corner of * the returned WritableRaster. * @param childMinY Y coordinate of the upper left corner of * the returned WritableRaster. * @param bandList Array of band indices, or null to use all bands. * @return a <code>WritableRaster</code> sharing all or part of the * <code>DataBuffer</code> of this <code>WritableRaster</code>. * @exception RasterFormatException if the subregion is outside of the * raster bounds. * @throws RasterFormatException if <code>w</code> or * <code>h</code> * is less than or equal to zero, or computing any of * <code>parentX + w</code>, <code>parentY + h</code>, * <code>childMinX + w</code>, or * <code>childMinY + h</code> results in integer * overflow */ public WritableRaster createWritableChild(int parentX, int parentY, int w, int h, int childMinX, int childMinY, int bandList[]) { if (parentX < this.minX) { throw new RasterFormatException("parentX lies outside raster"); } if (parentY < this.minY) { throw new RasterFormatException("parentY lies outside raster"); } if ((parentX+w < parentX) || (parentX+w > this.width + this.minX)) { throw new RasterFormatException("(parentX + width) is outside raster"); } if ((parentY+h < parentY) || (parentY+h > this.height + this.minY)) { throw new RasterFormatException("(parentY + height) is outside raster"); } SampleModel sm; // Note: the SampleModel for the child Raster should have the same // width and height as that for the parent, since it represents // the physical layout of the pixel data. The child Raster's width // and height represent a "virtual" view of the pixel data, so // they may be different than those of the SampleModel. if (bandList != null) { sm = sampleModel.createSubsetSampleModel(bandList); } else { sm = sampleModel; } int deltaX = childMinX - parentX; int deltaY = childMinY - parentY; return new WritableRaster(sm, dataBuffer, new Rectangle(childMinX,childMinY, w, h), new Point(sampleModelTranslateX+deltaX, sampleModelTranslateY+deltaY), this); } /** * Sets the data for a single pixel from a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -