summaryrefslogtreecommitdiffstats
path: root/awt/javax/imageio/ImageReadParam.java
blob: 9cc5c5f1b11dde411de750168526221f2782a583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * @author Sergey I. Salishev
 * @version $Revision: 1.2 $
 */

package javax.imageio;

import java.awt.Dimension;
import java.awt.image.BufferedImage;

/*
 * @author Sergey I. Salishev
 * @version $Revision: 1.2 $
 */

/**
 * The ImageReadParam class provides information to the ImageReader about how an
 * image is to be decoded.
 * 
 * @since Android 1.0
 */
public class ImageReadParam extends IIOParam {

    /**
     * This flag indicates if this ImageReadParam supports setting the source
     * rendering size.
     */
    protected boolean canSetSourceRenderSize;

    /**
     * The destination BufferedImage.
     */
    protected BufferedImage destination;

    /**
     * The destination bands.
     */
    protected int[] destinationBands;

    /**
     * The minimum progressive pass.
     */
    protected int minProgressivePass;

    /**
     * The number of progressive passes.
     */
    protected int numProgressivePasses;

    /**
     * The source render size.
     */
    protected Dimension sourceRenderSize;

    /**
     * Returns true if this ImageReaderParam supports rendering a source image
     * at an arbitrary size.
     * 
     * @return true, if this ImageReaderParam supports rendering a source image
     *         at an arbitrary size, false otherwise.
     */
    public boolean canSetSourceRenderSize() {
        return canSetSourceRenderSize;
    }

    /**
     * Gets the current destination image as BufferedImage.
     * 
     * @return the BufferedImage which represents the destination.
     */
    public BufferedImage getDestination() {
        return destination;
    }

    /**
     * Gets the indices of destination bands.
     * 
     * @return the array of destination bands.
     */
    public int[] getDestinationBands() {
        return destinationBands;
    }

    /**
     * Gets the index of the maximum pass to be decoded. This method returns
     * Integer.MAX_VALUE, if getSourceNumProgressivePasses() method returns
     * value that is equal to Integer.MAX_VALUE. Otherwise this method returns
     * getSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1.
     * 
     * @return the index of the maximum pass to be decoded.
     */
    public int getSourceMaxProgressivePass() {
        if (getSourceNumProgressivePasses() == Integer.MAX_VALUE) {
            return Integer.MAX_VALUE;
        }
        return getSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1;
    }

    /**
     * Gets the index of the minimum progressive pass that is decoded, default
     * is 0.
     * 
     * @return the index of the minimum progressive pass that is decoded,
     *         default is 0.
     */
    public int getSourceMinProgressivePass() {
        return minProgressivePass;
    }

    /**
     * Gets the number of progressive passes. The default value is
     * Integer.MAX_VALUE.
     * 
     * @return the number of progressive passes.
     */
    public int getSourceNumProgressivePasses() {
        return numProgressivePasses;
    }

    /**
     * Gets the dimension of source image which will be rendered during decoding
     * process.
     * 
     * @return the source render size.
     */
    public Dimension getSourceRenderSize() {
        return sourceRenderSize;
    }

    /**
     * Sets the specified destination image. This image will be used by read,
     * readAll, and readRaster methods, and a reference to it will be returned
     * by those methods.
     * 
     * @param destination
     *            the destination image.
     */
    public void setDestination(BufferedImage destination) {
        this.destination = destination;
    }

    /**
     * Sets the indices of the destination bands.
     * 
     * @param destinationBands
     *            the indices of the destination bands.
     */
    public void setDestinationBands(int[] destinationBands) {
        this.destinationBands = destinationBands;
    }

    @Override
    public void setDestinationType(ImageTypeSpecifier destinationType) {
        this.destinationType = destinationType;
    }

    /**
     * Sets the source progressive passes.
     * 
     * @param minPass
     *            the index of the minimum pass to be decoded.
     * @param numPasses
     *            the number of passes to be decoded.
     */
    public void setSourceProgressivePasses(int minPass, int numPasses) {
        minProgressivePass = minPass;
        numProgressivePasses = numPasses;
    }

    /**
     * Sets the dimension size of source image if an image can be rendered at an
     * arbitrary size.
     * 
     * @param size
     *            the size of rendered image.
     * @throws UnsupportedOperationException
     *             the unsupported operation exception.
     */
    public void setSourceRenderSize(Dimension size) throws UnsupportedOperationException {
        if (!canSetSourceRenderSize) {
            throw new UnsupportedOperationException("can't set source renderer size");
        }
        sourceRenderSize = size;
    }
}