blob: 9cc5c5f1b11dde411de750168526221f2782a583 [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 */
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080021
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070022package javax.imageio;
23
24import java.awt.Dimension;
25import java.awt.image.BufferedImage;
26
27/*
28 * @author Sergey I. Salishev
29 * @version $Revision: 1.2 $
30 */
31
32/**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080033 * The ImageReadParam class provides information to the ImageReader about how an
34 * image is to be decoded.
35 *
36 * @since Android 1.0
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070037 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070038public class ImageReadParam extends IIOParam {
39
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080040 /**
41 * This flag indicates if this ImageReadParam supports setting the source
42 * rendering size.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070043 */
44 protected boolean canSetSourceRenderSize;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080045
46 /**
47 * The destination BufferedImage.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070048 */
49 protected BufferedImage destination;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080050
51 /**
52 * The destination bands.
53 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070054 protected int[] destinationBands;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080055
56 /**
57 * The minimum progressive pass.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070058 */
59 protected int minProgressivePass;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080060
61 /**
62 * The number of progressive passes.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070063 */
64 protected int numProgressivePasses;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080065
66 /**
67 * The source render size.
68 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070069 protected Dimension sourceRenderSize;
70
71 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080072 * Returns true if this ImageReaderParam supports rendering a source image
73 * at an arbitrary size.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070074 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080075 * @return true, if this ImageReaderParam supports rendering a source image
76 * at an arbitrary size, false otherwise.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070077 */
78 public boolean canSetSourceRenderSize() {
79 return canSetSourceRenderSize;
80 }
81
82 /**
83 * Gets the current destination image as BufferedImage.
84 *
85 * @return the BufferedImage which represents the destination.
86 */
87 public BufferedImage getDestination() {
88 return destination;
89 }
90
91 /**
92 * Gets the indices of destination bands.
93 *
94 * @return the array of destination bands.
95 */
96 public int[] getDestinationBands() {
97 return destinationBands;
98 }
99
100 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800101 * Gets the index of the maximum pass to be decoded. This method returns
102 * Integer.MAX_VALUE, if getSourceNumProgressivePasses() method returns
103 * value that is equal to Integer.MAX_VALUE. Otherwise this method returns
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700104 * getSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1.
105 *
106 * @return the index of the maximum pass to be decoded.
107 */
108 public int getSourceMaxProgressivePass() {
109 if (getSourceNumProgressivePasses() == Integer.MAX_VALUE) {
110 return Integer.MAX_VALUE;
111 }
112 return getSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1;
113 }
114
115 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800116 * Gets the index of the minimum progressive pass that is decoded, default
117 * is 0.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700118 *
119 * @return the index of the minimum progressive pass that is decoded,
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800120 * default is 0.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700121 */
122 public int getSourceMinProgressivePass() {
123 return minProgressivePass;
124 }
125
126 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800127 * Gets the number of progressive passes. The default value is
128 * Integer.MAX_VALUE.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700129 *
130 * @return the number of progressive passes.
131 */
132 public int getSourceNumProgressivePasses() {
133 return numProgressivePasses;
134 }
135
136 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800137 * Gets the dimension of source image which will be rendered during decoding
138 * process.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700139 *
140 * @return the source render size.
141 */
142 public Dimension getSourceRenderSize() {
143 return sourceRenderSize;
144 }
145
146 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800147 * Sets the specified destination image. This image will be used by read,
148 * readAll, and readRaster methods, and a reference to it will be returned
149 * by those methods.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700150 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800151 * @param destination
152 * the destination image.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700153 */
154 public void setDestination(BufferedImage destination) {
155 this.destination = destination;
156 }
157
158 /**
159 * Sets the indices of the destination bands.
160 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800161 * @param destinationBands
162 * the indices of the destination bands.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700163 */
164 public void setDestinationBands(int[] destinationBands) {
165 this.destinationBands = destinationBands;
166 }
167
168 @Override
169 public void setDestinationType(ImageTypeSpecifier destinationType) {
170 this.destinationType = destinationType;
171 }
172
173 /**
174 * Sets the source progressive passes.
175 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800176 * @param minPass
177 * the index of the minimum pass to be decoded.
178 * @param numPasses
179 * the number of passes to be decoded.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700180 */
181 public void setSourceProgressivePasses(int minPass, int numPasses) {
182 minProgressivePass = minPass;
183 numProgressivePasses = numPasses;
184 }
185
186 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800187 * Sets the dimension size of source image if an image can be rendered at an
188 * arbitrary size.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700189 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800190 * @param size
191 * the size of rendered image.
192 * @throws UnsupportedOperationException
193 * the unsupported operation exception.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700194 */
195 public void setSourceRenderSize(Dimension size) throws UnsupportedOperationException {
196 if (!canSetSourceRenderSize) {
197 throw new UnsupportedOperationException("can't set source renderer size");
198 }
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800199 sourceRenderSize = size;
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700200 }
201}