The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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 Rustem V. Rafikov |
| 19 | * @version $Revision: 1.3 $ |
| 20 | */ |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 21 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | package javax.imageio; |
| 23 | |
| 24 | import java.awt.*; |
| 25 | |
| 26 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 27 | * 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 Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 31 | */ |
| 32 | public abstract class IIOParam { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 33 | |
| 34 | /** |
| 35 | * The source region. |
| 36 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | protected Rectangle sourceRegion; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 38 | |
| 39 | /** |
| 40 | * The source x subsampling. |
| 41 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 42 | protected int sourceXSubsampling = 1; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 43 | |
| 44 | /** |
| 45 | * The source y subsampling. |
| 46 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 47 | protected int sourceYSubsampling = 1; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 48 | |
| 49 | /** |
| 50 | * The subsampling x offset. |
| 51 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 52 | protected int subsamplingXOffset; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 53 | |
| 54 | /** |
| 55 | * The subsampling y offset. |
| 56 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 57 | protected int subsamplingYOffset; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 58 | |
| 59 | /** |
| 60 | * The source bands. |
| 61 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 62 | protected int[] sourceBands; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 63 | |
| 64 | /** |
| 65 | * The destination type. |
| 66 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 67 | protected ImageTypeSpecifier destinationType; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 68 | |
| 69 | /** |
| 70 | * The destination offset. |
| 71 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 72 | protected Point destinationOffset = new Point(0, 0); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 73 | |
| 74 | /** |
| 75 | * The default controller. |
| 76 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | protected IIOParamController defaultController; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 78 | |
| 79 | /** |
| 80 | * The controller. |
| 81 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 82 | protected IIOParamController controller; |
| 83 | |
| 84 | /** |
| 85 | * Instantiates a new IIOParam. |
| 86 | */ |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 87 | protected IIOParam() { |
| 88 | } |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Sets the source region as a Rectangle object. |
| 92 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 93 | * @param sourceRegion |
| 94 | * the Rectangle which specifies the source region. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 95 | */ |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 118 | // -- clone it to avoid unexpected modifications |
| 119 | this.sourceRegion = (Rectangle)sourceRegion.clone(); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 120 | } 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 134 | // -- clone it to avoid unexpected modifications |
| 135 | return (Rectangle)sourceRegion.clone(); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 139 | * 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 Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 142 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 143 | * @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 Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 151 | */ |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 152 | public void setSourceSubsampling(int sourceXSubsampling, int sourceYSubsampling, |
| 153 | int subsamplingXOffset, int subsamplingYOffset) { |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 170 | // -- does region contain pixels |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 171 | if (sourceRegion != null) { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 172 | if (sourceRegion.width <= subsamplingXOffset |
| 173 | || sourceRegion.height <= subsamplingYOffset) { |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 174 | 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 185 | * Gets the source X subsampling - the number of source columns to advance |
| 186 | * for each pixel. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 187 | * |
| 188 | * @return the source X subsampling. |
| 189 | */ |
| 190 | public int getSourceXSubsampling() { |
| 191 | return sourceXSubsampling; |
| 192 | } |
| 193 | |
| 194 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 195 | * Gets the source Y subsampling - the number of source rows to advance for |
| 196 | * each pixel. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 197 | * |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 225 | * @param sourceBands |
| 226 | * the indices of the source bands. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 227 | */ |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 246 | * @param destinationType |
| 247 | * the ImageTypeSpecifier. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 248 | */ |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 256 | * |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 257 | * @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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 265 | * 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 Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 268 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 269 | * @param destinationOffset |
| 270 | * the destination offset. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 271 | */ |
| 272 | public void setDestinationOffset(Point destinationOffset) { |
| 273 | if (destinationOffset == null) { |
| 274 | throw new IllegalArgumentException("destinationOffset == null!"); |
| 275 | } |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 276 | |
| 277 | this.destinationOffset = (Point)destinationOffset.clone(); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 278 | } |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 286 | return (Point)destinationOffset.clone(); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 290 | * Sets the IIOParamController to this IIOParam object for providing |
| 291 | * settings to this IIOParam. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 292 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 293 | * @param controller |
| 294 | * the new IIOParamController. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 295 | */ |
| 296 | public void setController(IIOParamController controller) { |
| 297 | // TODO implement |
| 298 | throw new UnsupportedOperationException("not implemented yet"); |
| 299 | } |
| 300 | |
| 301 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 302 | * Gets the current IIOParamController controller for this IIOParam. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 303 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 304 | * @return the current IIOParamController controller for this IIOParam. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 305 | */ |
| 306 | public IIOParamController getController() { |
| 307 | // TODO implement |
| 308 | throw new UnsupportedOperationException("not implemented yet"); |
| 309 | } |
| 310 | |
| 311 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 312 | * Gets the default IIOParamController controller for this IIOParam. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 313 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 314 | * @return the default IIOParamController controller for this IIOParam, or |
| 315 | * null. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 316 | */ |
| 317 | public IIOParamController getDefaultController() { |
| 318 | // TODO implement |
| 319 | throw new UnsupportedOperationException("not implemented yet"); |
| 320 | } |
| 321 | |
| 322 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 323 | * Returns true if IIOParamController is installed for this IIOParam. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 324 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 325 | * @return true, if IIOParamController is installed for this IIOParam, false |
| 326 | * otherwise. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 327 | */ |
| 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 | } |