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