1 7 8 package javax.imageio; 9 10 import java.awt.Point ; 11 import java.awt.Rectangle ; 12 13 32 public abstract class IIOParam { 33 34 37 protected Rectangle sourceRegion = null; 38 39 44 protected int sourceXSubsampling = 1; 45 46 51 protected int sourceYSubsampling = 1; 52 53 59 protected int subsamplingXOffset = 0; 60 61 67 protected int subsamplingYOffset = 0; 68 69 76 protected int[] sourceBands = null; 77 78 84 protected ImageTypeSpecifier destinationType = null; 85 86 90 protected Point destinationOffset = new Point (0, 0); 91 92 104 protected IIOParamController defaultController = null; 105 106 118 protected IIOParamController controller = null; 119 120 123 protected IIOParam() { 124 controller = defaultController; 125 } 126 127 164 public void setSourceRegion(Rectangle sourceRegion) { 165 if (sourceRegion == null) { 166 this.sourceRegion = null; 167 return; 168 } 169 170 if (sourceRegion.x < 0) { 171 throw new IllegalArgumentException ("sourceRegion.x < 0!"); 172 } 173 if (sourceRegion.y < 0){ 174 throw new IllegalArgumentException ("sourceRegion.y < 0!"); 175 } 176 if (sourceRegion.width <= 0) { 177 throw new IllegalArgumentException ("sourceRegion.width <= 0!"); 178 } 179 if (sourceRegion.height <= 0) { 180 throw new IllegalArgumentException ("sourceRegion.height <= 0!"); 181 } 182 183 if (sourceRegion.width <= subsamplingXOffset) { 185 throw new IllegalStateException 186 ("sourceRegion.width <= subsamplingXOffset!"); 187 } 188 if (sourceRegion.height <= subsamplingYOffset) { 189 throw new IllegalStateException 190 ("sourceRegion.height <= subsamplingYOffset!"); 191 } 192 193 this.sourceRegion = (Rectangle )sourceRegion.clone(); 194 } 195 196 207 public Rectangle getSourceRegion() { 208 if (sourceRegion == null) { 209 return null; 210 } 211 return (Rectangle )sourceRegion.clone(); 212 } 213 214 282 public void setSourceSubsampling(int sourceXSubsampling, 283 int sourceYSubsampling, 284 int subsamplingXOffset, 285 int subsamplingYOffset) { 286 if (sourceXSubsampling <= 0) { 287 throw new IllegalArgumentException ("sourceXSubsampling <= 0!"); 288 } 289 if (sourceYSubsampling <= 0) { 290 throw new IllegalArgumentException ("sourceYSubsampling <= 0!"); 291 } 292 if (subsamplingXOffset < 0 || 293 subsamplingXOffset >= sourceXSubsampling) { 294 throw new IllegalArgumentException 295 ("subsamplingXOffset out of range!"); 296 } 297 if (subsamplingYOffset < 0 || 298 subsamplingYOffset >= sourceYSubsampling) { 299 throw new IllegalArgumentException 300 ("subsamplingYOffset out of range!"); 301 } 302 303 if (sourceRegion != null) { 305 if (subsamplingXOffset >= sourceRegion.width || 306 subsamplingYOffset >= sourceRegion.height) { 307 throw new IllegalStateException ("region contains no pixels!"); 308 } 309 } 310 311 this.sourceXSubsampling = sourceXSubsampling; 312 this.sourceYSubsampling = sourceYSubsampling; 313 this.subsamplingXOffset = subsamplingXOffset; 314 this.subsamplingYOffset = subsamplingYOffset; 315 } 316 317 328 public int getSourceXSubsampling() { 329 return sourceXSubsampling; 330 } 331 332 343 public int getSourceYSubsampling() { 344 return sourceYSubsampling; 345 } 346 347 358 public int getSubsamplingXOffset() { 359 return subsamplingXOffset; 360 } 361 362 373 public int getSubsamplingYOffset() { 374 return subsamplingYOffset; 375 } 376 377 406 public void setSourceBands(int[] sourceBands) { 407 if (sourceBands == null) { 408 this.sourceBands = null; 409 } else { 410 int numBands = sourceBands.length; 411 for (int i = 0; i < numBands; i++) { 412 int band = sourceBands[i]; 413 if (band < 0) { 414 throw new IllegalArgumentException ("Band value < 0!"); 415 } 416 for (int j = i + 1; j < numBands; j++) { 417 if (band == sourceBands[j]) { 418 throw new IllegalArgumentException ("Duplicate band value!"); 419 } 420 } 421 422 } 423 this.sourceBands = (int[])(sourceBands.clone()); 424 } 425 } 426 427 442 public int[] getSourceBands() { 443 if (sourceBands == null) { 444 return null; 445 } 446 return (int[])(sourceBands.clone()); 447 } 448 449 480 public void setDestinationType(ImageTypeSpecifier destinationType) { 481 this.destinationType = destinationType; 482 } 483 484 496 public ImageTypeSpecifier getDestinationType() { 497 return destinationType; 498 } 499 500 529 public void setDestinationOffset(Point destinationOffset) { 530 if (destinationOffset == null) { 531 throw new IllegalArgumentException ("destinationOffset == null!"); 532 } 533 this.destinationOffset = (Point )destinationOffset.clone(); 534 } 535 536 548 public Point getDestinationOffset() { 549 return (Point )destinationOffset.clone(); 550 } 551 552 570 public void setController(IIOParamController controller) { 571 this.controller = controller; 572 } 573 574 589 public IIOParamController getController() { 590 return controller; 591 } 592 593 607 public IIOParamController getDefaultController() { 608 return defaultController; 609 } 610 611 625 public boolean hasController() { 626 return (controller != null); 627 } 628 629 653 public boolean activateController() { 654 if (!hasController()) { 655 throw new IllegalStateException ("hasController() == false!"); 656 } 657 return getController().activate(this); 658 } 659 } 660 | Popular Tags |