blob: e67ed7d91edde6ef5c7436d4fba79b8c658232b2 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @author Sergey I. Salishev
19 * @version $Revision: 1.2 $
20 */
21package javax.imageio;
22
23import java.awt.Dimension;
24import java.awt.image.BufferedImage;
25
26/*
27 * @author Sergey I. Salishev
28 * @version $Revision: 1.2 $
29 */
30
31/**
32 * The ImageReadParam class provides information to the ImageReader about
33 * how an image is to be decoded.
34 */
35
36public class ImageReadParam extends IIOParam {
37
38 /**
39 * This flag indicates if this ImageReadParam supports setting the source
40 * rendering size.
41 */
42 protected boolean canSetSourceRenderSize;
43
44 /**
45 * The destination BufferedImage.
46 */
47 protected BufferedImage destination;
48
49 /** The destination bands. */
50 protected int[] destinationBands;
51
52 /**
53 * The minimum progressive pass.
54 */
55 protected int minProgressivePass;
56
57 /**
58 * The number of progressive passes.
59 */
60 protected int numProgressivePasses;
61
62 /** The source render size. */
63 protected Dimension sourceRenderSize;
64
65 /**
66 * Returns true if this ImageReaderParam supports rendering a
67 * source image at an arbitrary size.
68 *
69 * @return true if this ImageReaderParam supports rendering a
70 * source image at an arbitrary size, false otherwise.
71 */
72 public boolean canSetSourceRenderSize() {
73 return canSetSourceRenderSize;
74 }
75
76 /**
77 * Gets the current destination image as BufferedImage.
78 *
79 * @return the BufferedImage which represents the destination.
80 */
81 public BufferedImage getDestination() {
82 return destination;
83 }
84
85 /**
86 * Gets the indices of destination bands.
87 *
88 * @return the array of destination bands.
89 */
90 public int[] getDestinationBands() {
91 return destinationBands;
92 }
93
94 /**
95 * Gets the index of the maximum pass to be decoded.
96 * This method returns Integer.MAX_VALUE, if
97 * getSourceNumProgressivePasses() method returns value
98 * that is equal to Integer.MAX_VALUE. Otherwise
99 * this method returns
100 * getSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1.
101 *
102 * @return the index of the maximum pass to be decoded.
103 */
104 public int getSourceMaxProgressivePass() {
105 if (getSourceNumProgressivePasses() == Integer.MAX_VALUE) {
106 return Integer.MAX_VALUE;
107 }
108 return getSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1;
109 }
110
111 /**
112 * Gets the index of the minimum progressive pass that is decoded,
113 * default is 0.
114 *
115 * @return the index of the minimum progressive pass that is decoded,
116 * default is 0.
117 */
118 public int getSourceMinProgressivePass() {
119 return minProgressivePass;
120 }
121
122 /**
123 * Gets the number of progressive passes.
124 * The default value is Integer.MAX_VALUE.
125 *
126 * @return the number of progressive passes.
127 */
128 public int getSourceNumProgressivePasses() {
129 return numProgressivePasses;
130 }
131
132 /**
133 * Gets the dimension of source image which will be rendered
134 * during decoding process.
135 *
136 * @return the source render size.
137 */
138 public Dimension getSourceRenderSize() {
139 return sourceRenderSize;
140 }
141
142 /**
143 * Sets the specified destination image.
144 * This image will be used by read, readAll, and readRaster methods,
145 * and a reference to it will be returned by those methods.
146 *
147 * @param destination the destination image.
148 */
149 public void setDestination(BufferedImage destination) {
150 this.destination = destination;
151 }
152
153 /**
154 * Sets the indices of the destination bands.
155 *
156 * @param destinationBands the indices of the destination bands.
157 */
158 public void setDestinationBands(int[] destinationBands) {
159 this.destinationBands = destinationBands;
160 }
161
162 @Override
163 public void setDestinationType(ImageTypeSpecifier destinationType) {
164 this.destinationType = destinationType;
165 }
166
167 /**
168 * Sets the source progressive passes.
169 *
170 * @param minPass the index of the minimum pass to be decoded.
171 * @param numPasses the number of passes to be decoded.
172 */
173 public void setSourceProgressivePasses(int minPass, int numPasses) {
174 minProgressivePass = minPass;
175 numProgressivePasses = numPasses;
176 }
177
178 /**
179 * Sets the dimension size of source image if an
180 * image can be rendered at an arbitrary size.
181 *
182 * @param size the size of rendered image.
183 *
184 * @throws UnsupportedOperationException the unsupported operation exception
185 */
186 public void setSourceRenderSize(Dimension size) throws UnsupportedOperationException {
187 if (!canSetSourceRenderSize) {
188 throw new UnsupportedOperationException("can't set source renderer size");
189 }
190 sourceRenderSize = size;
191 }
192}
193