| 1 7 8 package javax.imageio; 9 10 import java.awt.color.ICC_Profile ; 11 import java.awt.image.LookupTable ; 12 import java.awt.image.RenderedImage ; 13 import java.awt.Dimension ; 14 import java.util.Locale ; 15 16 72 public class ImageWriteParam extends IIOParam { 73 74 93 public static final int MODE_DISABLED = 0; 94 95 116 public static final int MODE_DEFAULT = 1; 117 118 138 public static final int MODE_EXPLICIT = 2; 139 140 164 public static final int MODE_COPY_FROM_METADATA = 3; 165 166 private static final int MAX_MODE = MODE_COPY_FROM_METADATA; 168 169 178 protected boolean canWriteTiles = false; 179 180 194 protected int tilingMode = MODE_COPY_FROM_METADATA; 195 196 207 protected Dimension [] preferredTileSizes = null; 208 209 216 protected boolean tilingSet = false; 217 218 224 protected int tileWidth = 0; 225 226 233 protected int tileHeight = 0; 234 235 245 protected boolean canOffsetTiles = false; 246 247 255 protected int tileGridXOffset = 0; 256 257 265 protected int tileGridYOffset = 0; 266 267 277 protected boolean canWriteProgressive = false; 278 279 295 protected int progressiveMode = MODE_COPY_FROM_METADATA; 296 297 305 protected boolean canWriteCompressed = false; 306 307 322 protected int compressionMode = MODE_COPY_FROM_METADATA; 323 324 332 protected String [] compressionTypes = null; 333 334 341 protected String compressionType = null; 342 343 350 protected float compressionQuality = 1.0F; 351 352 358 protected Locale locale = null; 359 360 364 protected ImageWriteParam() {} 365 366 374 public ImageWriteParam(Locale locale) { 375 this.locale = locale; 376 } 377 378 private static Dimension [] clonePreferredTileSizes(Dimension [] sizes) { 380 if (sizes == null) { 381 return null; 382 } 383 Dimension [] temp = new Dimension [sizes.length]; 384 for (int i = 0; i < sizes.length; i++) { 385 temp[i] = new Dimension (sizes[i]); 386 } 387 return temp; 388 } 389 390 397 public Locale getLocale() { 398 return locale; 399 } 400 401 412 public boolean canWriteTiles() { 413 return canWriteTiles; 414 } 415 416 431 public boolean canOffsetTiles() { 432 return canOffsetTiles; 433 } 434 435 472 public void setTilingMode(int mode) { 473 if (canWriteTiles() == false) { 474 throw new UnsupportedOperationException ("Tiling not supported!"); 475 } 476 if (mode < MODE_DISABLED || mode > MAX_MODE) { 477 throw new IllegalArgumentException ("Illegal value for mode!"); 478 } 479 this.tilingMode = mode; 480 if (mode == MODE_EXPLICIT) { 481 unsetTiling(); 482 } 483 } 484 485 496 public int getTilingMode() { 497 if (!canWriteTiles()) { 498 throw new UnsupportedOperationException ("Tiling not supported"); 499 } 500 return tilingMode; 501 } 502 503 526 public Dimension [] getPreferredTileSizes() { 527 if (!canWriteTiles()) { 528 throw new UnsupportedOperationException ("Tiling not supported"); 529 } 530 return clonePreferredTileSizes(preferredTileSizes); 531 } 532 533 568 public void setTiling(int tileWidth, 569 int tileHeight, 570 int tileGridXOffset, 571 int tileGridYOffset) { 572 if (!canWriteTiles()) { 573 throw new UnsupportedOperationException ("Tiling not supported!"); 574 } 575 if (getTilingMode() != MODE_EXPLICIT) { 576 throw new IllegalStateException ("Tiling mode not MODE_EXPLICIT!"); 577 } 578 if (tileWidth <= 0 || tileHeight <= 0) { 579 throw new IllegalArgumentException  580 ("tile dimensions are non-positive!"); 581 } 582 boolean tilesOffset = (tileGridXOffset != 0) || (tileGridYOffset != 0); 583 if (!canOffsetTiles() && tilesOffset) { 584 throw new UnsupportedOperationException ("Can't offset tiles!"); 585 } 586 if (preferredTileSizes != null) { 587 boolean ok = true; 588 for (int i = 0; i < preferredTileSizes.length; i += 2) { 589 Dimension min = preferredTileSizes[i]; 590 Dimension max = preferredTileSizes[i+1]; 591 if ((tileWidth < min.width) || 592 (tileWidth > max.width) || 593 (tileHeight < min.height) || 594 (tileHeight > max.height)) { 595 ok = false; 596 break; 597 } 598 } 599 if (!ok) { 600 throw new IllegalArgumentException ("Illegal tile size!"); 601 } 602 } 603 604 this.tilingSet = true; 605 this.tileWidth = tileWidth; 606 this.tileHeight = tileHeight; 607 this.tileGridXOffset = tileGridXOffset; 608 this.tileGridYOffset = tileGridYOffset; 609 } 610 611 627 public void unsetTiling() { 628 if (!canWriteTiles()) { 629 throw new UnsupportedOperationException ("Tiling not supported!"); 630 } 631 if (getTilingMode() != MODE_EXPLICIT) { 632 throw new IllegalStateException ("Tiling mode not MODE_EXPLICIT!"); 633 } 634 this.tilingSet = false; 635 this.tileWidth = 0; 636 this.tileHeight = 0; 637 this.tileGridXOffset = 0; 638 this.tileGridYOffset = 0; 639 } 640 641 658 public int getTileWidth() { 659 if (!canWriteTiles()) { 660 throw new UnsupportedOperationException ("Tiling not supported!"); 661 } 662 if (getTilingMode() != MODE_EXPLICIT) { 663 throw new IllegalStateException ("Tiling mode not MODE_EXPLICIT!"); 664 } 665 if (!tilingSet) { 666 throw new IllegalStateException ("Tiling parameters not set!"); 667 } 668 return tileWidth; 669 } 670 671 688 public int getTileHeight() { 689 if (!canWriteTiles()) { 690 throw new UnsupportedOperationException ("Tiling not supported!"); 691 } 692 if (getTilingMode() != MODE_EXPLICIT) { 693 throw new IllegalStateException ("Tiling mode not MODE_EXPLICIT!"); 694 } 695 if (!tilingSet) { 696 throw new IllegalStateException ("Tiling parameters not set!"); 697 } 698 return tileHeight; 699 } 700 701 718 public int getTileGridXOffset() { 719 if (!canWriteTiles()) { 720 throw new UnsupportedOperationException ("Tiling not supported!"); 721 } 722 if (getTilingMode() != MODE_EXPLICIT) { 723 throw new IllegalStateException ("Tiling mode not MODE_EXPLICIT!"); 724 } 725 if (!tilingSet) { 726 throw new IllegalStateException ("Tiling parameters not set!"); 727 } 728 return tileGridXOffset; 729 } 730 731 748 public int getTileGridYOffset() { 749 if (!canWriteTiles()) { 750 throw new UnsupportedOperationException ("Tiling not supported!"); 751 } 752 if (getTilingMode() != MODE_EXPLICIT) { 753 throw new IllegalStateException ("Tiling mode not MODE_EXPLICIT!"); 754 } 755 if (!tilingSet) { 756 throw new IllegalStateException ("Tiling parameters not set!"); 757 } 758 return tileGridYOffset; 759 } 760 761 771 public boolean canWriteProgressive() { 772 return canWriteProgressive; 773 } 774 775 815 public void setProgressiveMode(int mode) { 816 if (!canWriteProgressive()) { 817 throw new UnsupportedOperationException ( 818 "Progressive output not supported"); 819 } 820 if (mode < MODE_DISABLED || mode > MAX_MODE) { 821 throw new IllegalArgumentException ("Illegal value for mode!"); 822 } 823 if (mode == MODE_EXPLICIT) { 824 throw new IllegalArgumentException ( 825 "MODE_EXPLICIT not supported for progressive output"); 826 } 827 this.progressiveMode = mode; 828 } 829 830 841 public int getProgressiveMode() { 842 if (!canWriteProgressive()) { 843 throw new UnsupportedOperationException  844 ("Progressive output not supported"); 845 } 846 return progressiveMode; 847 } 848 849 854 public boolean canWriteCompressed() { 855 return canWriteCompressed; 856 } 857 858 895 public void setCompressionMode(int mode) { 896 if (!canWriteCompressed()) { 897 throw new UnsupportedOperationException ( 898 "Compression not supported."); 899 } 900 if (mode < MODE_DISABLED || mode > MAX_MODE) { 901 throw new IllegalArgumentException ("Illegal value for mode!"); 902 } 903 this.compressionMode = mode; 904 if (mode == MODE_EXPLICIT) { 905 unsetCompression(); 906 } 907 } 908 909 920 public int getCompressionMode() { 921 if (!canWriteCompressed()) { 922 throw new UnsupportedOperationException ( 923 "Compression not supported."); 924 } 925 return compressionMode; 926 } 927 928 954 public String [] getCompressionTypes() { 955 if (!canWriteCompressed()) { 956 throw new UnsupportedOperationException ( 957 "Compression not supported"); 958 } 959 if (compressionTypes == null) { 960 return null; 961 } 962 return (String [])compressionTypes.clone(); 963 } 964 965 |