OSDN Git Service

auto import from //depot/cupcake/@135843
[android-x86/frameworks-native.git] / awt / javax / imageio / ImageReadParam.java
1 /*
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  */
21
22 package javax.imageio;
23
24 import java.awt.Dimension;
25 import java.awt.image.BufferedImage;
26
27 /*
28  * @author Sergey I. Salishev
29  * @version $Revision: 1.2 $
30  */
31
32 /**
33  * The ImageReadParam class provides information to the ImageReader about how an
34  * image is to be decoded.
35  * 
36  * @since Android 1.0
37  */
38 public class ImageReadParam extends IIOParam {
39
40     /**
41      * This flag indicates if this ImageReadParam supports setting the source
42      * rendering size.
43      */
44     protected boolean canSetSourceRenderSize;
45
46     /**
47      * The destination BufferedImage.
48      */
49     protected BufferedImage destination;
50
51     /**
52      * The destination bands.
53      */
54     protected int[] destinationBands;
55
56     /**
57      * The minimum progressive pass.
58      */
59     protected int minProgressivePass;
60
61     /**
62      * The number of progressive passes.
63      */
64     protected int numProgressivePasses;
65
66     /**
67      * The source render size.
68      */
69     protected Dimension sourceRenderSize;
70
71     /**
72      * Returns true if this ImageReaderParam supports rendering a source image
73      * at an arbitrary size.
74      * 
75      * @return true, if this ImageReaderParam supports rendering a source image
76      *         at an arbitrary size, false otherwise.
77      */
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     /**
101      * 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
104      * 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     /**
116      * Gets the index of the minimum progressive pass that is decoded, default
117      * is 0.
118      * 
119      * @return the index of the minimum progressive pass that is decoded,
120      *         default is 0.
121      */
122     public int getSourceMinProgressivePass() {
123         return minProgressivePass;
124     }
125
126     /**
127      * Gets the number of progressive passes. The default value is
128      * Integer.MAX_VALUE.
129      * 
130      * @return the number of progressive passes.
131      */
132     public int getSourceNumProgressivePasses() {
133         return numProgressivePasses;
134     }
135
136     /**
137      * Gets the dimension of source image which will be rendered during decoding
138      * process.
139      * 
140      * @return the source render size.
141      */
142     public Dimension getSourceRenderSize() {
143         return sourceRenderSize;
144     }
145
146     /**
147      * 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.
150      * 
151      * @param destination
152      *            the destination image.
153      */
154     public void setDestination(BufferedImage destination) {
155         this.destination = destination;
156     }
157
158     /**
159      * Sets the indices of the destination bands.
160      * 
161      * @param destinationBands
162      *            the indices of the destination bands.
163      */
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      * 
176      * @param minPass
177      *            the index of the minimum pass to be decoded.
178      * @param numPasses
179      *            the number of passes to be decoded.
180      */
181     public void setSourceProgressivePasses(int minPass, int numPasses) {
182         minProgressivePass = minPass;
183         numProgressivePasses = numPasses;
184     }
185
186     /**
187      * Sets the dimension size of source image if an image can be rendered at an
188      * arbitrary size.
189      * 
190      * @param size
191      *            the size of rendered image.
192      * @throws UnsupportedOperationException
193      *             the unsupported operation exception.
194      */
195     public void setSourceRenderSize(Dimension size) throws UnsupportedOperationException {
196         if (!canSetSourceRenderSize) {
197             throw new UnsupportedOperationException("can't set source renderer size");
198         }
199         sourceRenderSize = size;
200     }
201 }