1 7 8 package javax.imageio.plugins.jpeg; 9 10 import java.util.Locale ; 11 import javax.imageio.ImageWriteParam ; 12 13 import com.sun.imageio.plugins.jpeg.JPEG; 14 15 75 public class JPEGImageWriteParam extends ImageWriteParam { 76 77 private JPEGQTable [] qTables = null; 78 private JPEGHuffmanTable [] DCHuffmanTables = null; 79 private JPEGHuffmanTable [] ACHuffmanTables = null; 80 private boolean optimizeHuffman = false; 81 private String [] compressionNames = {"JPEG"}; 82 private float[] qualityVals = { 0.05F, 0.75F, 0.95F }; 83 private String [] qualityDescs = { "Minimum useful", "Visually lossless", "Maximum useful" }; 87 88 99 public JPEGImageWriteParam(Locale locale) { 100 super(locale); 101 this.canWriteProgressive = true; 102 this.progressiveMode = MODE_DISABLED; 103 this.canWriteCompressed = true; 104 this.compressionTypes = compressionNames; 105 this.compressionType = compressionTypes[0]; 106 this.compressionQuality = JPEG.DEFAULT_QUALITY; 107 } 108 109 118 public void unsetCompression() { 119 if (getCompressionMode() != MODE_EXPLICIT) { 120 throw new IllegalStateException 121 ("Compression mode not MODE_EXPLICIT!"); 122 } 123 this.compressionQuality = JPEG.DEFAULT_QUALITY; 124 } 125 126 135 public boolean isCompressionLossless() { 136 if (getCompressionMode() != MODE_EXPLICIT) { 137 throw new IllegalStateException 138 ("Compression mode not MODE_EXPLICIT!"); 139 } 140 return false; 141 } 142 143 public String [] getCompressionQualityDescriptions() { 144 if (getCompressionMode() != MODE_EXPLICIT) { 145 throw new IllegalStateException 146 ("Compression mode not MODE_EXPLICIT!"); 147 } 148 if ((getCompressionTypes() != null) && 149 (getCompressionType() == null)) { 150 throw new IllegalStateException ("No compression type set!"); 151 } 152 return (String [])qualityDescs.clone(); 153 } 154 155 public float[] getCompressionQualityValues() { 156 if (getCompressionMode() != MODE_EXPLICIT) { 157 throw new IllegalStateException 158 ("Compression mode not MODE_EXPLICIT!"); 159 } 160 if ((getCompressionTypes() != null) && 161 (getCompressionType() == null)) { 162 throw new IllegalStateException ("No compression type set!"); 163 } 164 return (float[])qualityVals.clone(); 165 } 166 171 public boolean areTablesSet() { 172 return (qTables != null); 173 } 174 175 195 public void setEncodeTables(JPEGQTable [] qTables, 196 JPEGHuffmanTable [] DCHuffmanTables, 197 JPEGHuffmanTable [] ACHuffmanTables) { 198 if ((qTables == null) || 199 (DCHuffmanTables == null) || 200 (ACHuffmanTables == null) || 201 (qTables.length > 4) || 202 (DCHuffmanTables.length > 4) || 203 (ACHuffmanTables.length > 4) || 204 (DCHuffmanTables.length != ACHuffmanTables.length)) { 205 throw new IllegalArgumentException ("Invalid JPEG table arrays"); 206 } 207 this.qTables = (JPEGQTable [])qTables.clone(); 208 this.DCHuffmanTables = (JPEGHuffmanTable [])DCHuffmanTables.clone(); 209 this.ACHuffmanTables = (JPEGHuffmanTable [])ACHuffmanTables.clone(); 210 } 211 212 218 public void unsetEncodeTables() { 219 this.qTables = null; 220 this.DCHuffmanTables = null; 221 this.ACHuffmanTables = null; 222 } 223 224 234 public JPEGQTable [] getQTables() { 235 return (qTables != null) ? (JPEGQTable [])qTables.clone() : null; 236 } 237 238 248 public JPEGHuffmanTable [] getDCHuffmanTables() { 249 return (DCHuffmanTables != null) 250 ? (JPEGHuffmanTable [])DCHuffmanTables.clone() 251 : null; 252 } 253 254 264 public JPEGHuffmanTable [] getACHuffmanTables() { 265 return (ACHuffmanTables != null) 266 ? (JPEGHuffmanTable [])ACHuffmanTables.clone() 267 : null; 268 } 269 270 284 public void setOptimizeHuffmanTables(boolean optimize) { 285 optimizeHuffman = optimize; 286 } 287 288 299 public boolean getOptimizeHuffmanTables() { 300 return optimizeHuffman; 301 } 302 } 303 | Popular Tags |