jdk/src/share/classes/javax/imageio/IIOParam.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 5506 202f599c92aa
child 22584 eed64ee05369
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.imageio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * A superclass of all classes describing how streams should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * decoded or encoded.  This class contains all the variables and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * methods that are shared by <code>ImageReadParam</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>ImageWriteParam</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p> This class provides mechanisms to specify a source region and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * destination region.  When reading, the source is the stream and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the in-memory image is the destination.  When writing, these are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * reversed.  In the case of writing, destination regions may be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * only with a writer that supports pixel replacement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Decimation subsampling may be specified for both readers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * and writers, using a movable subsampling grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Subsets of the source and destination bands may be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public abstract class IIOParam {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * The source region, on <code>null</code> if none is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected Rectangle sourceRegion = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * The decimation subsampling to be applied in the horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * direction.  By default, the value is <code>1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * The value must not be negative or 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected int sourceXSubsampling = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * The decimation subsampling to be applied in the vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * direction.  By default, the value is <code>1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The value must not be negative or 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected int sourceYSubsampling = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * A horizontal offset to be applied to the subsampling grid before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * subsampling.  The first pixel to be used will be offset this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * amount from the origin of the region, or of the image if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * region is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected int subsamplingXOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * A vertical offset to be applied to the subsampling grid before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * subsampling.  The first pixel to be used will be offset this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * amount from the origin of the region, or of the image if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * region is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected int subsamplingYOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * An array of <code>int</code>s indicating which source bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * will be used, or <code>null</code>.  If <code>null</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * set of source bands to be used is as described in the comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * for the <code>setSourceBands</code> method.  No value should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * be allowed to be negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected int[] sourceBands = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * An <code>ImageTypeSpecifier</code> to be used to generate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * destination image when reading, or to set the output color type
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
    98
     * when writing.  If non has been set the value will be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <code>null</code>.  By default, the value is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected ImageTypeSpecifier destinationType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * The offset in the destination where the upper-left decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * pixel should be placed.  By default, the value is (0, 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected Point destinationOffset = new Point(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * The default <code>IIOParamController</code> that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * used to provide settings for this <code>IIOParam</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * object when the <code>activateController</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * is called.  This default should be set by subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * that choose to provide their own default controller,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * usually a GUI, for setting parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @see IIOParamController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @see #activateController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    protected IIOParamController defaultController = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * The <code>IIOParamController</code> that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * used to provide settings for this <code>IIOParam</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * object when the <code>activateController</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * is called.  This value overrides any default controller,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * even when null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see IIOParamController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see #setController(IIOParamController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see #hasController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    protected IIOParamController controller = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Protected constructor may be called only by subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected IIOParam() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        controller = defaultController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Sets the source region of interest.  The region of interest is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * described as a rectangle, with the upper-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * source image as pixel (0, 0) and increasing values down and to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * the right.  The actual number of pixels used will depend on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * the subsampling factors set by <code>setSourceSubsampling</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * If subsampling has been set such that this number is zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * an <code>IllegalStateException</code> will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <p> The source region of interest specified by this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * be clipped as needed to fit within the source bounds, as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * as the destination offsets, width, and height at the time of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * actual I/O.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <p> A value of <code>null</code> for <code>sourceRegion</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * will remove any region specification, causing the entire image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * to be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param sourceRegion a <code>Rectangle</code> specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * source region of interest, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <code>sourceRegion</code> is non-<code>null</code> and either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <code>sourceRegion.x</code> or <code>sourceRegion.y</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <code>sourceRegion</code> is non-<code>null</code> and either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <code>sourceRegion.width</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <code>sourceRegion.height</code> is negative or 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @exception IllegalStateException if subsampling is such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * this region will have a subsampled width or height of zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see #getSourceRegion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @see #setSourceSubsampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see ImageReadParam#setDestinationOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see ImageReadParam#getDestinationOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public void setSourceRegion(Rectangle sourceRegion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (sourceRegion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            this.sourceRegion = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (sourceRegion.x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            throw new IllegalArgumentException("sourceRegion.x < 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (sourceRegion.y < 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            throw new IllegalArgumentException("sourceRegion.y < 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (sourceRegion.width <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new IllegalArgumentException("sourceRegion.width <= 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (sourceRegion.height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            throw new IllegalArgumentException("sourceRegion.height <= 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // Throw an IllegalStateException if region falls between subsamples
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (sourceRegion.width <= subsamplingXOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throw new IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                ("sourceRegion.width <= subsamplingXOffset!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (sourceRegion.height <= subsamplingYOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            throw new IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                ("sourceRegion.height <= subsamplingYOffset!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        this.sourceRegion = (Rectangle)sourceRegion.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Returns the source region to be used.  The returned value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * that set by the most recent call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <code>setSourceRegion</code>, and will be <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * there is no region set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @return the source region of interest as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <code>Rectangle</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see #setSourceRegion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public Rectangle getSourceRegion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (sourceRegion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return (Rectangle)sourceRegion.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Specifies a decimation subsampling to apply on I/O.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <code>sourceXSubsampling</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <code>sourceYSubsampling</code> parameters specify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * subsampling period (<i>i.e.</i>, the number of rows and columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * to advance after every source pixel).  Specifically, a period of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * 1 will use every row or column; a period of 2 will use every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * other row or column.  The <code>subsamplingXOffset</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <code>subsamplingYOffset</code> parameters specify an offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * from the region (or image) origin for the first subsampled pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Adjusting the origin of the subsample grid is useful for avoiding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * seams when subsampling a very large source image into destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * regions that will be assembled into a complete subsampled image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Most users will want to simply leave these parameters at 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <p> The number of pixels and scanlines to be used are calculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * The number of subsampled pixels in a scanline is given by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <code>truncate[(width - subsamplingXOffset + sourceXSubsampling - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * / sourceXSubsampling]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * If the region is such that this width is zero, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <code>IllegalStateException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * The number of scanlines to be used can be computed similarly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * <p>The ability to set the subsampling grid to start somewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * other than the source region origin is useful if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * region is being used to create subsampled tiles of a large image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * where the tile width and height are not multiples of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * subsampling periods.  If the subsampling grid does not remain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * consistent from tile to tile, there will be artifacts at the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * boundaries.  By adjusting the subsampling grid offset for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * tile to compensate, these artifacts can be avoided.  The tradeoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * is that in order to avoid these artifacts, the tiles are not all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the same size.  The grid offset to use in this case is given by:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * grid offset = [period - (region offset modulo period)] modulo period)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <p> If either <code>sourceXSubsampling</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <code>sourceYSubsampling</code> is 0 or negative, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <code>IllegalArgumentException</code> will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <p> If either <code>subsamplingXOffset</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * <code>subsamplingYOffset</code> is negative or greater than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * equal to the corresponding period, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <code>IllegalArgumentException</code> will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <p> There is no <code>unsetSourceSubsampling</code> method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * simply call <code>setSourceSubsampling(1, 1, 0, 0)</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * restore default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @param sourceXSubsampling the number of columns to advance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * between pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @param sourceYSubsampling the number of rows to advance between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param subsamplingXOffset the horizontal offset of the first subsample
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * within the region, or within the image if no region is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param subsamplingYOffset the horizontal offset of the first subsample
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * within the region, or within the image if no region is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @exception IllegalArgumentException if either period is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * negative or 0, or if either grid offset is negative or greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * the corresponding period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @exception IllegalStateException if the source region is such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * the subsampled output would contain no pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public void setSourceSubsampling(int sourceXSubsampling,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                     int sourceYSubsampling,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                     int subsamplingXOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                     int subsamplingYOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (sourceXSubsampling <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            throw new IllegalArgumentException("sourceXSubsampling <= 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (sourceYSubsampling <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            throw new IllegalArgumentException("sourceYSubsampling <= 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (subsamplingXOffset < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            subsamplingXOffset >= sourceXSubsampling) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                ("subsamplingXOffset out of range!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (subsamplingYOffset < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            subsamplingYOffset >= sourceYSubsampling) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                ("subsamplingYOffset out of range!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // Throw an IllegalStateException if region falls between subsamples
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (sourceRegion != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (subsamplingXOffset >= sourceRegion.width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                subsamplingYOffset >= sourceRegion.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                throw new IllegalStateException("region contains no pixels!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        this.sourceXSubsampling = sourceXSubsampling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        this.sourceYSubsampling = sourceYSubsampling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        this.subsamplingXOffset = subsamplingXOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        this.subsamplingYOffset = subsamplingYOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Returns the number of source columns to advance for each pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <p>If <code>setSourceSubsampling</code> has not been called, 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * is returned (which is the correct value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @return the source subsampling X period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see #setSourceSubsampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see #getSourceYSubsampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public int getSourceXSubsampling() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return sourceXSubsampling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Returns the number of rows to advance for each pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <p>If <code>setSourceSubsampling</code> has not been called, 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * is returned (which is the correct value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @return the source subsampling Y period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @see #setSourceSubsampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @see #getSourceXSubsampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public int getSourceYSubsampling() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return sourceYSubsampling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Returns the horizontal offset of the subsampling grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>If <code>setSourceSubsampling</code> has not been called, 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * is returned (which is the correct value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @return the source subsampling grid X offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see #setSourceSubsampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see #getSubsamplingYOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public int getSubsamplingXOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        return subsamplingXOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Returns the vertical offset of the subsampling grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <p>If <code>setSourceSubsampling</code> has not been called, 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * is returned (which is the correct value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @return the source subsampling grid Y offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @see #setSourceSubsampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see #getSubsamplingXOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public int getSubsamplingYOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return subsamplingYOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Sets the indices of the source bands to be used.  Duplicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * indices are not allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * <p> A <code>null</code> value indicates that all source bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <p> At the time of reading, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <code>IllegalArgumentException</code> will be thrown by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * reader or writer if a value larger than the largest available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * source band index has been specified or if the number of source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * bands and destination bands to be used differ.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * <code>ImageReader.checkReadParamBandSettings</code> method may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * be used to automate this test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <p> Semantically, a copy is made of the array; changes to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * array contents subsequent to this call have no effect on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * this <code>IIOParam</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param sourceBands an array of integer band indices to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @exception IllegalArgumentException if <code>sourceBands</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * contains a negative or duplicate value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see #getSourceBands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see ImageReadParam#setDestinationBands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see ImageReader#checkReadParamBandSettings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public void setSourceBands(int[] sourceBands) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (sourceBands == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            this.sourceBands = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            int numBands = sourceBands.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            for (int i = 0; i < numBands; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                int band = sourceBands[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                if (band < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    throw new IllegalArgumentException("Band value < 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                for (int j = i + 1; j < numBands; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    if (band == sourceBands[j]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        throw new IllegalArgumentException("Duplicate band value!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            this.sourceBands = (int[])(sourceBands.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Returns the set of of source bands to be used. The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * value is that set by the most recent call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * <code>setSourceBands</code>, or <code>null</code> if there have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * been no calls to <code>setSourceBands</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * <p> Semantically, the array returned is a copy; changes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * array contents subsequent to this call have no effect on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * <code>IIOParam</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @return the set of source bands to be used, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @see #setSourceBands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public int[] getSourceBands() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (sourceBands == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        return (int[])(sourceBands.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * Sets the desired image type for the destination image, using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * <code>ImageTypeSpecifier</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * <p> When reading, if the layout of the destination has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * using this method, each call to an <code>ImageReader</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * <code>read</code> method will return a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * <code>BufferedImage</code> using the format specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * supplied type specifier.  As a side effect, any destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <code>BufferedImage</code> set by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * <code>ImageReadParam.setDestination(BufferedImage)</code> will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * no longer be set as the destination.  In other words, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * method may be thought of as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * <code>setDestination((BufferedImage)null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * <p> When writing, the destination type maybe used to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * the color type of the image.  The <code>SampleModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * information will be ignored, and may be <code>null</code>.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * example, a 4-banded image could represent either CMYK or RGBA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * data.  If a destination type is set, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <code>ColorModel</code> will override any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <code>ColorModel</code> on the image itself.  This is crucial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * when <code>setSourceBands</code> is used since the image's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * <code>ColorModel</code> will refer to the entire image rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * than to the subset of bands being written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @param destinationType the <code>ImageTypeSpecifier</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * be used to determine the destination layout and color type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @see #getDestinationType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public void setDestinationType(ImageTypeSpecifier destinationType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        this.destinationType = destinationType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Returns the type of image to be returned by the read, if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * was set by a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * <code>setDestination(ImageTypeSpecifier)</code>, as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * <code>ImageTypeSpecifier</code>.  If none was set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * <code>null</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @return an <code>ImageTypeSpecifier</code> describing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * destination type, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @see #setDestinationType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public ImageTypeSpecifier getDestinationType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return destinationType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Specifies the offset in the destination image at which future
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * decoded pixels are to be placed, when reading, or where a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * region will be written, when writing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <p> When reading, the region to be written within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * destination <code>BufferedImage</code> will start at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * offset and have a width and height determined by the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * region of interest, the subsampling parameters, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * destination bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <p> Normal writes are not affected by this method, only writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * performed using <code>ImageWriter.replacePixels</code>.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * such writes, the offset specified is within the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * image whose pixels are being modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <p> There is no <code>unsetDestinationOffset</code> method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * simply call <code>setDestinationOffset(new Point(0, 0))</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * restore default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @param destinationOffset the offset in the destination, as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * <code>destinationOffset</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @see #getDestinationOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @see ImageWriter#replacePixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public void setDestinationOffset(Point destinationOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (destinationOffset == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            throw new IllegalArgumentException("destinationOffset == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        this.destinationOffset = (Point)destinationOffset.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Returns the offset in the destination image at which pixels are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * to be placed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * <p> If <code>setDestinationOffsets</code> has not been called,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * a <code>Point</code> with zero X and Y values is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * (which is the correct value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @return the destination offset as a <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @see #setDestinationOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    public Point getDestinationOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return (Point)destinationOffset.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Sets the <code>IIOParamController</code> to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * to provide settings for this <code>IIOParam</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * object when the <code>activateController</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * is called, overriding any default controller.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * argument is <code>null</code>, no controller will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * used, including any default.  To restore the default, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * <code>setController(getDefaultController())</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @param controller An appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <code>IIOParamController</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @see IIOParamController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @see #getController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see #hasController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public void setController(IIOParamController controller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        this.controller = controller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Returns whatever <code>IIOParamController</code> is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * installed.  This could be the default if there is one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <code>null</code>, or the argument of the most recent call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * to <code>setController</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @return the currently installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <code>IIOParamController</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @see IIOParamController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @see #setController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @see #hasController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    public IIOParamController getController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        return controller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * Returns the default <code>IIOParamController</code>, if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * is one, regardless of the currently installed controller.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * there is no default controller, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @return the default <code>IIOParamController</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @see IIOParamController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @see #setController(IIOParamController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @see #getController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @see #hasController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public IIOParamController getDefaultController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        return defaultController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * Returns <code>true</code> if there is a controller installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * for this <code>IIOParam</code> object.  This will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * <code>true</code> if <code>getController</code> would not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @return <code>true</code> if a controller is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @see IIOParamController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @see #setController(IIOParamController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @see #getController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public boolean hasController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        return (controller != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * Activates the installed <code>IIOParamController</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * this <code>IIOParam</code> object and returns the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * value.  When this method returns <code>true</code>, all values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * for this <code>IIOParam</code> object will be ready for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * next read or write operation.  If <code>false</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * returned, no settings in this object will have been disturbed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * (<i>i.e.</i>, the user canceled the operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * <p> Ordinarily, the controller will be a GUI providing a user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * interface for a subclass of <code>IIOParam</code> for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * particular plug-in.  Controllers need not be GUIs, however.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @return <code>true</code> if the controller completed normally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @exception IllegalStateException if there is no controller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * currently installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @see IIOParamController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @see #setController(IIOParamController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @see #getController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @see #hasController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public boolean activateController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        if (!hasController()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            throw new IllegalStateException("hasController() == false!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        return getController().activate(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
}