The Android Open Source Project | 54b6cfa | 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 | */ |
| 21 | package javax.imageio; |
| 22 | |
| 23 | import java.awt.*; |
| 24 | |
| 25 | /** |
| 26 | * The IIOParam abstract class is superclass for |
| 27 | * ImageReadParam and ImageWriteParam classes and provides |
| 28 | * methods and variables which they share. |
| 29 | */ |
| 30 | public abstract class IIOParam { |
| 31 | |
| 32 | /** The source region. */ |
| 33 | protected Rectangle sourceRegion; |
| 34 | |
| 35 | /** The source x subsampling. */ |
| 36 | protected int sourceXSubsampling = 1; |
| 37 | |
| 38 | /** The source y subsampling. */ |
| 39 | protected int sourceYSubsampling = 1; |
| 40 | |
| 41 | /** The subsampling x offset. */ |
| 42 | protected int subsamplingXOffset; |
| 43 | |
| 44 | /** The subsampling y offset. */ |
| 45 | protected int subsamplingYOffset; |
| 46 | |
| 47 | /** The source bands. */ |
| 48 | protected int[] sourceBands; |
| 49 | |
| 50 | /** The destination type. */ |
| 51 | protected ImageTypeSpecifier destinationType; |
| 52 | |
| 53 | /** The destination offset. */ |
| 54 | protected Point destinationOffset = new Point(0, 0); |
| 55 | |
| 56 | /** The default controller. */ |
| 57 | protected IIOParamController defaultController; |
| 58 | |
| 59 | /** The controller. */ |
| 60 | protected IIOParamController controller; |
| 61 | |
| 62 | /** |
| 63 | * Instantiates a new IIOParam. |
| 64 | */ |
| 65 | protected IIOParam() {} |
| 66 | |
| 67 | /** |
| 68 | * Sets the source region as a Rectangle object. |
| 69 | * |
| 70 | * @param sourceRegion the Rectangle which specifies the source region. |
| 71 | */ |
| 72 | public void setSourceRegion(Rectangle sourceRegion) { |
| 73 | if (sourceRegion != null) { |
| 74 | if (sourceRegion.x < 0) { |
| 75 | throw new IllegalArgumentException("x < 0"); |
| 76 | } |
| 77 | if (sourceRegion.y < 0) { |
| 78 | throw new IllegalArgumentException("y < 0"); |
| 79 | } |
| 80 | if (sourceRegion.width <= 0) { |
| 81 | throw new IllegalArgumentException("width <= 0"); |
| 82 | } |
| 83 | if (sourceRegion.height <= 0) { |
| 84 | throw new IllegalArgumentException("height <= 0"); |
| 85 | } |
| 86 | |
| 87 | if (sourceRegion.width <= subsamplingXOffset) { |
| 88 | throw new IllegalArgumentException("width <= subsamplingXOffset"); |
| 89 | } |
| 90 | |
| 91 | if (sourceRegion.height <= subsamplingYOffset) { |
| 92 | throw new IllegalArgumentException("height <= subsamplingXOffset"); |
| 93 | } |
| 94 | //-- clone it to avoid unexpected modifications |
| 95 | this.sourceRegion = (Rectangle) sourceRegion.clone(); |
| 96 | } else { |
| 97 | this.sourceRegion = null; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Gets the source region. |
| 103 | * |
| 104 | * @return the source region as Rectangle. |
| 105 | */ |
| 106 | public Rectangle getSourceRegion() { |
| 107 | if (sourceRegion == null) { |
| 108 | return null; |
| 109 | } |
| 110 | //-- clone it to avoid unexpected modifications |
| 111 | return (Rectangle) sourceRegion.clone(); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Sets the source subsampling. The sourceXSubsampling and |
| 116 | * sourceYSubsampling parameters specify the number of rows |
| 117 | * and columns to advance after every source pixel. |
| 118 | * |
| 119 | * @param sourceXSubsampling the source X subsampling. |
| 120 | * @param sourceYSubsampling the source Y subsampling. |
| 121 | * @param subsamplingXOffset the subsampling X offset. |
| 122 | * @param subsamplingYOffset the subsampling Y offset. |
| 123 | */ |
| 124 | public void setSourceSubsampling(int sourceXSubsampling, |
| 125 | int sourceYSubsampling, |
| 126 | int subsamplingXOffset, |
| 127 | int subsamplingYOffset) { |
| 128 | |
| 129 | if (sourceXSubsampling <= 0) { |
| 130 | throw new IllegalArgumentException("sourceXSubsampling <= 0"); |
| 131 | } |
| 132 | if (sourceYSubsampling <= 0) { |
| 133 | throw new IllegalArgumentException("sourceYSubsampling <= 0"); |
| 134 | } |
| 135 | |
| 136 | if (subsamplingXOffset <= 0 || subsamplingXOffset >= sourceXSubsampling) { |
| 137 | throw new IllegalArgumentException("subsamplingXOffset is wrong"); |
| 138 | } |
| 139 | |
| 140 | if (subsamplingYOffset <= 0 || subsamplingYOffset >= sourceYSubsampling) { |
| 141 | throw new IllegalArgumentException("subsamplingYOffset is wrong"); |
| 142 | } |
| 143 | |
| 144 | //-- does region contain pixels |
| 145 | if (sourceRegion != null) { |
| 146 | if (sourceRegion.width <= subsamplingXOffset || |
| 147 | sourceRegion.height <= subsamplingYOffset) { |
| 148 | throw new IllegalArgumentException("there are no pixels in region"); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | this.sourceXSubsampling = sourceXSubsampling; |
| 153 | this.sourceYSubsampling = sourceYSubsampling; |
| 154 | this.subsamplingXOffset = subsamplingXOffset; |
| 155 | this.subsamplingYOffset = subsamplingYOffset; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Gets the source X subsampling - the number of source |
| 160 | * columns to advance for each pixel. |
| 161 | * |
| 162 | * @return the source X subsampling. |
| 163 | */ |
| 164 | public int getSourceXSubsampling() { |
| 165 | return sourceXSubsampling; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Gets the source Y subsampling - the number of source |
| 170 | * rows to advance for each pixel. |
| 171 | * |
| 172 | * @return the source Y subsampling. |
| 173 | */ |
| 174 | public int getSourceYSubsampling() { |
| 175 | return sourceYSubsampling; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Gets the horizontal offset of the subsampling grid. |
| 180 | * |
| 181 | * @return the horizontal offset of the subsampling grid. |
| 182 | */ |
| 183 | public int getSubsamplingXOffset() { |
| 184 | return subsamplingXOffset; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Gets the vertical offset of the subsampling grid. |
| 189 | * |
| 190 | * @return the vertical offset of the subsampling grid. |
| 191 | */ |
| 192 | public int getSubsamplingYOffset() { |
| 193 | return subsamplingYOffset; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Sets the indices of the source bands. |
| 198 | * |
| 199 | * @param sourceBands the indices of the source bands. |
| 200 | */ |
| 201 | public void setSourceBands(int[] sourceBands) { |
| 202 | // TODO implement |
| 203 | throw new UnsupportedOperationException("not implemented yet"); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Gets the array of source bands. |
| 208 | * |
| 209 | * @return the array of source bands. |
| 210 | */ |
| 211 | public int[] getSourceBands() { |
| 212 | // TODO implement |
| 213 | throw new UnsupportedOperationException("not implemented yet"); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Sets the specified ImageTypeSpecifier for the destination image. |
| 218 | * |
| 219 | * @param destinationType the ImageTypeSpecifier. |
| 220 | */ |
| 221 | public void setDestinationType(ImageTypeSpecifier destinationType) { |
| 222 | // TODO implement |
| 223 | throw new UnsupportedOperationException("not implemented yet"); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Gets the type of the destination image as an ImageTypeSpecifier. . |
| 228 | * |
| 229 | * @return the ImageTypeSpecifier. |
| 230 | */ |
| 231 | public ImageTypeSpecifier getDestinationType() { |
| 232 | // TODO implement |
| 233 | throw new UnsupportedOperationException("not implemented yet"); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Sets the offset in the destination image where |
| 238 | * the decoded pixels are placed as a result of reading, |
| 239 | * or specified an area to be written while writing operation. |
| 240 | * |
| 241 | * @param destinationOffset the destination offset. |
| 242 | */ |
| 243 | public void setDestinationOffset(Point destinationOffset) { |
| 244 | if (destinationOffset == null) { |
| 245 | throw new IllegalArgumentException("destinationOffset == null!"); |
| 246 | } |
| 247 | |
| 248 | this.destinationOffset = (Point) destinationOffset.clone(); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Gets the offset in the destination image for placing pixels. |
| 253 | * |
| 254 | * @return the offset in the destination image. |
| 255 | */ |
| 256 | public Point getDestinationOffset() { |
| 257 | return (Point) destinationOffset.clone(); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Sets the IIOParamController to this IIOParam object for |
| 262 | * providing settings to this IIOParam. |
| 263 | * |
| 264 | * @param controller the new IIOParamController. |
| 265 | */ |
| 266 | public void setController(IIOParamController controller) { |
| 267 | // TODO implement |
| 268 | throw new UnsupportedOperationException("not implemented yet"); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Gets the current IIOParamController controller |
| 273 | * for this IIOParam. |
| 274 | * |
| 275 | * @return the current IIOParamController controller |
| 276 | * for this IIOParam. |
| 277 | */ |
| 278 | public IIOParamController getController() { |
| 279 | // TODO implement |
| 280 | throw new UnsupportedOperationException("not implemented yet"); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Gets the default IIOParamController controller |
| 285 | * for this IIOParam. |
| 286 | * |
| 287 | * @return the default IIOParamController controller |
| 288 | * for this IIOParam, or null. |
| 289 | */ |
| 290 | public IIOParamController getDefaultController() { |
| 291 | // TODO implement |
| 292 | throw new UnsupportedOperationException("not implemented yet"); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Returns true if IIOParamController is installed for |
| 297 | * this IIOParam. |
| 298 | * |
| 299 | * @return true if IIOParamController is installed for |
| 300 | * this IIOParam, false otherwise. |
| 301 | */ |
| 302 | public boolean hasController() { |
| 303 | // TODO implement |
| 304 | throw new UnsupportedOperationException("not implemented yet"); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Activates the controller. |
| 309 | * |
| 310 | * @return true, if successful, false otherwise. |
| 311 | */ |
| 312 | public boolean activateController() { |
| 313 | // TODO implement |
| 314 | throw new UnsupportedOperationException("not implemented yet"); |
| 315 | } |
| 316 | } |