blob: 2ccc9450f5b4a5ade2802e5fd87202d98de0990f [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 Rustem V. Rafikov
19 * @version $Revision: 1.3 $
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.*;
25
26/**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080027 * The IIOParam abstract class is superclass for ImageReadParam and
28 * ImageWriteParam classes and provides methods and variables which they share.
29 *
30 * @since Android 1.0
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070031 */
32public abstract class IIOParam {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080033
34 /**
35 * The source region.
36 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070037 protected Rectangle sourceRegion;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080038
39 /**
40 * The source x subsampling.
41 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070042 protected int sourceXSubsampling = 1;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080043
44 /**
45 * The source y subsampling.
46 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070047 protected int sourceYSubsampling = 1;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080048
49 /**
50 * The subsampling x offset.
51 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070052 protected int subsamplingXOffset;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080053
54 /**
55 * The subsampling y offset.
56 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070057 protected int subsamplingYOffset;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080058
59 /**
60 * The source bands.
61 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070062 protected int[] sourceBands;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080063
64 /**
65 * The destination type.
66 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070067 protected ImageTypeSpecifier destinationType;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080068
69 /**
70 * The destination offset.
71 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070072 protected Point destinationOffset = new Point(0, 0);
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080073
74 /**
75 * The default controller.
76 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070077 protected IIOParamController defaultController;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080078
79 /**
80 * The controller.
81 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070082 protected IIOParamController controller;
83
84 /**
85 * Instantiates a new IIOParam.
86 */
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080087 protected IIOParam() {
88 }
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070089
90 /**
91 * Sets the source region as a Rectangle object.
92 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080093 * @param sourceRegion
94 * the Rectangle which specifies the source region.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070095 */
96 public void setSourceRegion(Rectangle sourceRegion) {
97 if (sourceRegion != null) {
98 if (sourceRegion.x < 0) {
99 throw new IllegalArgumentException("x < 0");
100 }
101 if (sourceRegion.y < 0) {
102 throw new IllegalArgumentException("y < 0");
103 }
104 if (sourceRegion.width <= 0) {
105 throw new IllegalArgumentException("width <= 0");
106 }
107 if (sourceRegion.height <= 0) {
108 throw new IllegalArgumentException("height <= 0");
109 }
110
111 if (sourceRegion.width <= subsamplingXOffset) {
112 throw new IllegalArgumentException("width <= subsamplingXOffset");
113 }
114
115 if (sourceRegion.height <= subsamplingYOffset) {
116 throw new IllegalArgumentException("height <= subsamplingXOffset");
117 }
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800118 // -- clone it to avoid unexpected modifications
119 this.sourceRegion = (Rectangle)sourceRegion.clone();
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700120 } else {
121 this.sourceRegion = null;
122 }
123 }
124
125 /**
126 * Gets the source region.
127 *
128 * @return the source region as Rectangle.
129 */
130 public Rectangle getSourceRegion() {
131 if (sourceRegion == null) {
132 return null;
133 }
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800134 // -- clone it to avoid unexpected modifications
135 return (Rectangle)sourceRegion.clone();
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700136 }
137
138 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800139 * Sets the source subsampling. The sourceXSubsampling and
140 * sourceYSubsampling parameters specify the number of rows and columns to
141 * advance after every source pixel.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700142 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800143 * @param sourceXSubsampling
144 * the source X subsampling.
145 * @param sourceYSubsampling
146 * the source Y subsampling.
147 * @param subsamplingXOffset
148 * the subsampling X offset.
149 * @param subsamplingYOffset
150 * the subsampling Y offset.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700151 */
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800152 public void setSourceSubsampling(int sourceXSubsampling, int sourceYSubsampling,
153 int subsamplingXOffset, int subsamplingYOffset) {
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700154
155 if (sourceXSubsampling <= 0) {
156 throw new IllegalArgumentException("sourceXSubsampling <= 0");
157 }
158 if (sourceYSubsampling <= 0) {
159 throw new IllegalArgumentException("sourceYSubsampling <= 0");
160 }
161
162 if (subsamplingXOffset <= 0 || subsamplingXOffset >= sourceXSubsampling) {
163 throw new IllegalArgumentException("subsamplingXOffset is wrong");
164 }
165
166 if (subsamplingYOffset <= 0 || subsamplingYOffset >= sourceYSubsampling) {
167 throw new IllegalArgumentException("subsamplingYOffset is wrong");
168 }
169
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800170 // -- does region contain pixels
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700171 if (sourceRegion != null) {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800172 if (sourceRegion.width <= subsamplingXOffset
173 || sourceRegion.height <= subsamplingYOffset) {
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700174 throw new IllegalArgumentException("there are no pixels in region");
175 }
176 }
177
178 this.sourceXSubsampling = sourceXSubsampling;
179 this.sourceYSubsampling = sourceYSubsampling;
180 this.subsamplingXOffset = subsamplingXOffset;
181 this.subsamplingYOffset = subsamplingYOffset;
182 }
183
184 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800185 * Gets the source X subsampling - the number of source columns to advance
186 * for each pixel.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700187 *
188 * @return the source X subsampling.
189 */
190 public int getSourceXSubsampling() {
191 return sourceXSubsampling;
192 }
193
194 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800195 * Gets the source Y subsampling - the number of source rows to advance for
196 * each pixel.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700197 *
198 * @return the source Y subsampling.
199 */
200 public int getSourceYSubsampling() {
201 return sourceYSubsampling;
202 }
203
204 /**
205 * Gets the horizontal offset of the subsampling grid.
206 *
207 * @return the horizontal offset of the subsampling grid.
208 */
209 public int getSubsamplingXOffset() {
210 return subsamplingXOffset;
211 }
212
213 /**
214 * Gets the vertical offset of the subsampling grid.
215 *
216 * @return the vertical offset of the subsampling grid.
217 */
218 public int getSubsamplingYOffset() {
219 return subsamplingYOffset;
220 }
221
222 /**
223 * Sets the indices of the source bands.
224 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800225 * @param sourceBands
226 * the indices of the source bands.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700227 */
228 public void setSourceBands(int[] sourceBands) {
229 // TODO implement
230 throw new UnsupportedOperationException("not implemented yet");
231 }
232
233 /**
234 * Gets the array of source bands.
235 *
236 * @return the array of source bands.
237 */
238 public int[] getSourceBands() {
239 // TODO implement
240 throw new UnsupportedOperationException("not implemented yet");
241 }
242
243 /**
244 * Sets the specified ImageTypeSpecifier for the destination image.
245 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800246 * @param destinationType
247 * the ImageTypeSpecifier.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700248 */
249 public void setDestinationType(ImageTypeSpecifier destinationType) {
250 // TODO implement
251 throw new UnsupportedOperationException("not implemented yet");
252 }
253
254 /**
255 * Gets the type of the destination image as an ImageTypeSpecifier. .
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800256 *
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700257 * @return the ImageTypeSpecifier.
258 */
259 public ImageTypeSpecifier getDestinationType() {
260 // TODO implement
261 throw new UnsupportedOperationException("not implemented yet");
262 }
263
264 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800265 * Sets the offset in the destination image where the decoded pixels are
266 * placed as a result of reading, or specified an area to be written while
267 * writing operation.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700268 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800269 * @param destinationOffset
270 * the destination offset.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700271 */
272 public void setDestinationOffset(Point destinationOffset) {
273 if (destinationOffset == null) {
274 throw new IllegalArgumentException("destinationOffset == null!");
275 }
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800276
277 this.destinationOffset = (Point)destinationOffset.clone();
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700278 }
279
280 /**
281 * Gets the offset in the destination image for placing pixels.
282 *
283 * @return the offset in the destination image.
284 */
285 public Point getDestinationOffset() {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800286 return (Point)destinationOffset.clone();
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700287 }
288
289 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800290 * Sets the IIOParamController to this IIOParam object for providing
291 * settings to this IIOParam.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700292 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800293 * @param controller
294 * the new IIOParamController.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700295 */
296 public void setController(IIOParamController controller) {
297 // TODO implement
298 throw new UnsupportedOperationException("not implemented yet");
299 }
300
301 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800302 * Gets the current IIOParamController controller for this IIOParam.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700303 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800304 * @return the current IIOParamController controller for this IIOParam.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700305 */
306 public IIOParamController getController() {
307 // TODO implement
308 throw new UnsupportedOperationException("not implemented yet");
309 }
310
311 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800312 * Gets the default IIOParamController controller for this IIOParam.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700313 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800314 * @return the default IIOParamController controller for this IIOParam, or
315 * null.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700316 */
317 public IIOParamController getDefaultController() {
318 // TODO implement
319 throw new UnsupportedOperationException("not implemented yet");
320 }
321
322 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800323 * Returns true if IIOParamController is installed for this IIOParam.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700324 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800325 * @return true, if IIOParamController is installed for this IIOParam, false
326 * otherwise.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700327 */
328 public boolean hasController() {
329 // TODO implement
330 throw new UnsupportedOperationException("not implemented yet");
331 }
332
333 /**
334 * Activates the controller.
335 *
336 * @return true, if successful, false otherwise.
337 */
338 public boolean activateController() {
339 // TODO implement
340 throw new UnsupportedOperationException("not implemented yet");
341 }
342}