IIOParam.java revision 2362
2362N/A * Copyright (c) 2000, 2001, 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 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 * 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. 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 0N/A * A superclass of all classes describing how streams should be 0N/A * decoded or encoded. This class contains all the variables and 0N/A * methods that are shared by <code>ImageReadParam</code> and 0N/A * <code>ImageWriteParam</code>. 0N/A * <p> This class provides mechanisms to specify a source region and a 0N/A * destination region. When reading, the source is the stream and 0N/A * the in-memory image is the destination. When writing, these are 0N/A * reversed. In the case of writing, destination regions may be used 0N/A * only with a writer that supports pixel replacement. 0N/A * Decimation subsampling may be specified for both readers 0N/A * and writers, using a movable subsampling grid. 0N/A * Subsets of the source and destination bands may be selected. 0N/A * The source region, on <code>null</code> if none is set. 0N/A * The decimation subsampling to be applied in the horizontal 0N/A * direction. By default, the value is <code>1</code>. 0N/A * The value must not be negative or 0. 0N/A * The decimation subsampling to be applied in the vertical 0N/A * direction. By default, the value is <code>1</code>. 0N/A * The value must not be negative or 0. 0N/A * A horizontal offset to be applied to the subsampling grid before 0N/A * subsampling. The first pixel to be used will be offset this 0N/A * amount from the origin of the region, or of the image if no 0N/A * region is specified. 0N/A * A vertical offset to be applied to the subsampling grid before 0N/A * subsampling. The first pixel to be used will be offset this 0N/A * amount from the origin of the region, or of the image if no 0N/A * region is specified. 0N/A * An array of <code>int</code>s indicating which source bands 0N/A * will be used, or <code>null</code>. If <code>null</code>, the 0N/A * set of source bands to be used is as described in the comment 0N/A * for the <code>setSourceBands</code> method. No value should 0N/A * be allowed to be negative. 0N/A * An <code>ImageTypeSpecifier</code> to be used to generate a 0N/A * destination image when reading, or to set the output color type 0N/A * when writing. If non has been setm the value will be 0N/A * <code>null</code>. By default, the value is <code>null</code>. 0N/A * The offset in the destination where the upper-left decoded 0N/A * pixel should be placed. By default, the value is (0, 0). 0N/A * The default <code>IIOParamController</code> that will be 0N/A * used to provide settings for this <code>IIOParam</code> 0N/A * object when the <code>activateController</code> method 0N/A * is called. This default should be set by subclasses 0N/A * that choose to provide their own default controller, 0N/A * usually a GUI, for setting parameters. 0N/A * @see IIOParamController 0N/A * @see #getDefaultController 0N/A * @see #activateController 0N/A * The <code>IIOParamController</code> that will be 0N/A * used to provide settings for this <code>IIOParam</code> 0N/A * object when the <code>activateController</code> method 0N/A * is called. This value overrides any default controller, 0N/A * @see IIOParamController 0N/A * @see #setController(IIOParamController) 0N/A * @see #hasController() 0N/A * @see #activateController() 0N/A * Protected constructor may be called only by subclasses. 0N/A * Sets the source region of interest. The region of interest is 0N/A * described as a rectangle, with the upper-left corner of the 0N/A * source image as pixel (0, 0) and increasing values down and to 0N/A * the right. The actual number of pixels used will depend on 0N/A * the subsampling factors set by <code>setSourceSubsampling</code>. 0N/A * If subsampling has been set such that this number is zero, 0N/A * an <code>IllegalStateException</code> will be thrown. 0N/A * <p> The source region of interest specified by this method will 0N/A * be clipped as needed to fit within the source bounds, as well 0N/A * as the destination offsets, width, and height at the time of 0N/A * <p> A value of <code>null</code> for <code>sourceRegion</code> 0N/A * will remove any region specification, causing the entire image 0N/A * @param sourceRegion a <code>Rectangle</code> specifying the 0N/A * source region of interest, or <code>null</code>. 0N/A * @exception IllegalArgumentException if 0N/A * <code>sourceRegion</code> is non-<code>null</code> and either 0N/A * <code>sourceRegion.x</code> or <code>sourceRegion.y</code> is 0N/A * @exception IllegalArgumentException if 0N/A * <code>sourceRegion</code> is non-<code>null</code> and either 0N/A * <code>sourceRegion.width</code> or 0N/A * <code>sourceRegion.height</code> is negative or 0. 0N/A * @exception IllegalStateException if subsampling is such that 0N/A * this region will have a subsampled width or height of zero. 0N/A * @see #getSourceRegion 0N/A * @see #setSourceSubsampling 0N/A * @see ImageReadParam#setDestinationOffset 0N/A * @see ImageReadParam#getDestinationOffset 0N/A // Throw an IllegalStateException if region falls between subsamples 0N/A (
"sourceRegion.width <= subsamplingXOffset!");
0N/A (
"sourceRegion.height <= subsamplingYOffset!");
0N/A * Returns the source region to be used. The returned value is 0N/A * that set by the most recent call to 0N/A * <code>setSourceRegion</code>, and will be <code>null</code> if 0N/A * there is no region set. 0N/A * @return the source region of interest as a 0N/A * <code>Rectangle</code>, or <code>null</code>. 0N/A * @see #setSourceRegion 0N/A * Specifies a decimation subsampling to apply on I/O. The 0N/A * <code>sourceXSubsampling</code> and 0N/A * <code>sourceYSubsampling</code> parameters specify the 0N/A * subsampling period (<i>i.e.</i>, the number of rows and columns 0N/A * to advance after every source pixel). Specifically, a period of 0N/A * 1 will use every row or column; a period of 2 will use every 0N/A * other row or column. The <code>subsamplingXOffset</code> and 0N/A * <code>subsamplingYOffset</code> parameters specify an offset 0N/A * from the region (or image) origin for the first subsampled pixel. 0N/A * Adjusting the origin of the subsample grid is useful for avoiding 0N/A * seams when subsampling a very large source image into destination 0N/A * regions that will be assembled into a complete subsampled image. 0N/A * Most users will want to simply leave these parameters at 0. 0N/A * <p> The number of pixels and scanlines to be used are calculated 0N/A * The number of subsampled pixels in a scanline is given by 0N/A * <code>truncate[(width - subsamplingXOffset + sourceXSubsampling - 1) 0N/A * / sourceXSubsampling]</code>. 0N/A * If the region is such that this width is zero, an 0N/A * <code>IllegalStateException</code> is thrown. 0N/A * The number of scanlines to be used can be computed similarly. 0N/A * <p>The ability to set the subsampling grid to start somewhere 0N/A * other than the source region origin is useful if the 0N/A * region is being used to create subsampled tiles of a large image, 0N/A * where the tile width and height are not multiples of the 0N/A * subsampling periods. If the subsampling grid does not remain 0N/A * consistent from tile to tile, there will be artifacts at the tile 0N/A * boundaries. By adjusting the subsampling grid offset for each 0N/A * tile to compensate, these artifacts can be avoided. The tradeoff 0N/A * is that in order to avoid these artifacts, the tiles are not all 0N/A * the same size. The grid offset to use in this case is given by: 0N/A * grid offset = [period - (region offset modulo period)] modulo period) 0N/A * <p> If either <code>sourceXSubsampling</code> or 0N/A * <code>sourceYSubsampling</code> is 0 or negative, an 0N/A * <code>IllegalArgumentException</code> will be thrown. 0N/A * <p> If either <code>subsamplingXOffset</code> or 0N/A * <code>subsamplingYOffset</code> is negative or greater than or 0N/A * equal to the corresponding period, an 0N/A * <code>IllegalArgumentException</code> will be thrown. 0N/A * <p> There is no <code>unsetSourceSubsampling</code> method; 0N/A * simply call <code>setSourceSubsampling(1, 1, 0, 0)</code> to 0N/A * restore default values. 0N/A * @param sourceXSubsampling the number of columns to advance 0N/A * @param sourceYSubsampling the number of rows to advance between 0N/A * @param subsamplingXOffset the horizontal offset of the first subsample 0N/A * within the region, or within the image if no region is set. 0N/A * @param subsamplingYOffset the horizontal offset of the first subsample 0N/A * within the region, or within the image if no region is set. 0N/A * @exception IllegalArgumentException if either period is 0N/A * negative or 0, or if either grid offset is negative or greater than 0N/A * the corresponding period. 0N/A * @exception IllegalStateException if the source region is such that 0N/A * the subsampled output would contain no pixels. 0N/A (
"subsamplingXOffset out of range!");
0N/A (
"subsamplingYOffset out of range!");
0N/A // Throw an IllegalStateException if region falls between subsamples 0N/A * Returns the number of source columns to advance for each pixel. 0N/A * <p>If <code>setSourceSubsampling</code> has not been called, 1 0N/A * is returned (which is the correct value). 0N/A * @return the source subsampling X period. 0N/A * @see #setSourceSubsampling 0N/A * @see #getSourceYSubsampling 0N/A * Returns the number of rows to advance for each pixel. 0N/A * <p>If <code>setSourceSubsampling</code> has not been called, 1 0N/A * is returned (which is the correct value). 0N/A * @return the source subsampling Y period. 0N/A * @see #setSourceSubsampling 0N/A * @see #getSourceXSubsampling 0N/A * Returns the horizontal offset of the subsampling grid. 0N/A * <p>If <code>setSourceSubsampling</code> has not been called, 0 0N/A * is returned (which is the correct value). 0N/A * @return the source subsampling grid X offset. 0N/A * @see #setSourceSubsampling 0N/A * @see #getSubsamplingYOffset 0N/A * Returns the vertical offset of the subsampling grid. 0N/A * <p>If <code>setSourceSubsampling</code> has not been called, 0 0N/A * is returned (which is the correct value). 0N/A * @return the source subsampling grid Y offset. 0N/A * @see #setSourceSubsampling 0N/A * @see #getSubsamplingXOffset 0N/A * Sets the indices of the source bands to be used. Duplicate 0N/A * indices are not allowed. 0N/A * <p> A <code>null</code> value indicates that all source bands 0N/A * <p> At the time of reading, an 0N/A * <code>IllegalArgumentException</code> will be thrown by the 0N/A * reader or writer if a value larger than the largest available 0N/A * source band index has been specified or if the number of source 0N/A * bands and destination bands to be used differ. The 0N/A * <code>ImageReader.checkReadParamBandSettings</code> method may 0N/A * be used to automate this test. 0N/A * <p> Semantically, a copy is made of the array; changes to the 0N/A * array contents subsequent to this call have no effect on 0N/A * this <code>IIOParam</code>. 0N/A * @param sourceBands an array of integer band indices to be 0N/A * @exception IllegalArgumentException if <code>sourceBands</code> 0N/A * contains a negative or duplicate value. 0N/A * @see #getSourceBands 0N/A * @see ImageReadParam#setDestinationBands 0N/A * @see ImageReader#checkReadParamBandSettings 0N/A * Returns the set of of source bands to be used. The returned 0N/A * value is that set by the most recent call to 0N/A * <code>setSourceBands</code>, or <code>null</code> if there have 0N/A * been no calls to <code>setSourceBands</code>. 0N/A * <p> Semantically, the array returned is a copy; changes to 0N/A * array contents subsequent to this call have no effect on this 0N/A * <code>IIOParam</code>. 0N/A * @return the set of source bands to be used, or 0N/A * <code>null</code>. 0N/A * @see #setSourceBands 0N/A * Sets the desired image type for the destination image, using an 0N/A * <code>ImageTypeSpecifier</code>. 0N/A * <p> When reading, if the layout of the destination has been set 0N/A * using this method, each call to an <code>ImageReader</code> 0N/A * <code>read</code> method will return a new 0N/A * <code>BufferedImage</code> using the format specified by the 0N/A * supplied type specifier. As a side effect, any destination 0N/A * <code>BufferedImage</code> set by 0N/A * <code>ImageReadParam.setDestination(BufferedImage)</code> will 0N/A * no longer be set as the destination. In other words, this 0N/A * method may be thought of as calling 0N/A * <code>setDestination((BufferedImage)null)</code>. 0N/A * <p> When writing, the destination type maybe used to determine 0N/A * the color type of the image. The <code>SampleModel</code> 0N/A * information will be ignored, and may be <code>null</code>. For 0N/A * example, a 4-banded image could represent either CMYK or RGBA 0N/A * data. If a destination type is set, its 0N/A * <code>ColorModel</code> will override any 0N/A * <code>ColorModel</code> on the image itself. This is crucial 0N/A * when <code>setSourceBands</code> is used since the image's 0N/A * <code>ColorModel</code> will refer to the entire image rather 0N/A * than to the subset of bands being written. 0N/A * @param destinationType the <code>ImageTypeSpecifier</code> to 0N/A * be used to determine the destination layout and color type. 0N/A * @see #getDestinationType 0N/A * Returns the type of image to be returned by the read, if one 0N/A * was set by a call to 0N/A * <code>setDestination(ImageTypeSpecifier)</code>, as an 0N/A * <code>ImageTypeSpecifier</code>. If none was set, 0N/A * <code>null</code> is returned. 0N/A * @return an <code>ImageTypeSpecifier</code> describing the 0N/A * destination type, or <code>null</code>. 0N/A * @see #setDestinationType 0N/A * Specifies the offset in the destination image at which future 0N/A * decoded pixels are to be placed, when reading, or where a 0N/A * region will be written, when writing. 0N/A * <p> When reading, the region to be written within the 0N/A * destination <code>BufferedImage</code> will start at this 0N/A * offset and have a width and height determined by the source 0N/A * region of interest, the subsampling parameters, and the 0N/A * destination bounds. 0N/A * <p> Normal writes are not affected by this method, only writes 0N/A * performed using <code>ImageWriter.replacePixels</code>. For 0N/A * such writes, the offset specified is within the output stream 0N/A * image whose pixels are being modified. 0N/A * <p> There is no <code>unsetDestinationOffset</code> method; 0N/A * simply call <code>setDestinationOffset(new Point(0, 0))</code> to 0N/A * restore default values. 0N/A * @param destinationOffset the offset in the destination, as a 0N/A * <code>Point</code>. 0N/A * @exception IllegalArgumentException if 0N/A * <code>destinationOffset</code> is <code>null</code>. 0N/A * @see #getDestinationOffset 0N/A * @see ImageWriter#replacePixels 0N/A * Returns the offset in the destination image at which pixels are 0N/A * <p> If <code>setDestinationOffsets</code> has not been called, 0N/A * a <code>Point</code> with zero X and Y values is returned 0N/A * (which is the correct value). 0N/A * @return the destination offset as a <code>Point</code>. 0N/A * @see #setDestinationOffset 0N/A * Sets the <code>IIOParamController</code> to be used 0N/A * to provide settings for this <code>IIOParam</code> 0N/A * object when the <code>activateController</code> method 0N/A * is called, overriding any default controller. If the 0N/A * argument is <code>null</code>, no controller will be 0N/A * used, including any default. To restore the default, use 0N/A * <code>setController(getDefaultController())</code>. 0N/A * @param controller An appropriate 0N/A * <code>IIOParamController</code>, or <code>null</code>. 0N/A * @see IIOParamController 0N/A * @see #getController 0N/A * @see #getDefaultController 0N/A * @see #hasController 0N/A * @see #activateController() 0N/A * Returns whatever <code>IIOParamController</code> is currently 0N/A * installed. This could be the default if there is one, 0N/A * <code>null</code>, or the argument of the most recent call 0N/A * to <code>setController</code>. 0N/A * @return the currently installed 0N/A * <code>IIOParamController</code>, or <code>null</code>. 0N/A * @see IIOParamController 0N/A * @see #setController 0N/A * @see #getDefaultController 0N/A * @see #hasController 0N/A * @see #activateController() 0N/A * Returns the default <code>IIOParamController</code>, if there 0N/A * is one, regardless of the currently installed controller. If 0N/A * there is no default controller, returns <code>null</code>. 0N/A * @return the default <code>IIOParamController</code>, or 0N/A * <code>null</code>. 0N/A * @see IIOParamController 0N/A * @see #setController(IIOParamController) 0N/A * @see #getController 0N/A * @see #hasController 0N/A * @see #activateController() 0N/A * Returns <code>true</code> if there is a controller installed 0N/A * for this <code>IIOParam</code> object. This will return 0N/A * <code>true</code> if <code>getController</code> would not 0N/A * return <code>null</code>. 0N/A * @return <code>true</code> if a controller is installed. 0N/A * @see IIOParamController 0N/A * @see #setController(IIOParamController) 0N/A * @see #getController 0N/A * @see #getDefaultController 0N/A * @see #activateController() 0N/A * Activates the installed <code>IIOParamController</code> for 0N/A * this <code>IIOParam</code> object and returns the resulting 0N/A * value. When this method returns <code>true</code>, all values 0N/A * for this <code>IIOParam</code> object will be ready for the 0N/A * next read or write operation. If <code>false</code> is 0N/A * returned, no settings in this object will have been disturbed 0N/A * (<i>i.e.</i>, the user canceled the operation). 0N/A * <p> Ordinarily, the controller will be a GUI providing a user 0N/A * interface for a subclass of <code>IIOParam</code> for a 0N/A * particular plug-in. Controllers need not be GUIs, however. 0N/A * @return <code>true</code> if the controller completed normally. 0N/A * @exception IllegalStateException if there is no controller 0N/A * currently installed. 0N/A * @see IIOParamController 0N/A * @see #setController(IIOParamController) 0N/A * @see #getController 0N/A * @see #getDefaultController 0N/A * @see #hasController