38 |
|
|
39 |
package javax.imageio; |
package javax.imageio; |
40 |
|
|
41 |
|
import java.awt.Dimension; |
42 |
|
import java.util.Locale; |
43 |
|
|
44 |
public class ImageWriteParam extends IIOParam |
public class ImageWriteParam extends IIOParam |
45 |
{ |
{ |
46 |
// FIXME: Incomplete. This class is merely present in order to allow |
public static final int MODE_DISABLED = 0; |
47 |
// compilation of the javax.imageio package. |
public static final int MODE_DEFAULT = 1; |
48 |
|
public static final int MODE_EXPLICIT = 2; |
49 |
|
public static final int MODE_COPY_FROM_METADATA = 3; |
50 |
|
|
51 |
|
protected boolean canOffsetTiles; |
52 |
|
protected boolean canWriteCompressed; |
53 |
|
protected boolean canWriteProgressive; |
54 |
|
protected boolean canWriteTiles; |
55 |
|
protected int compressionMode = MODE_COPY_FROM_METADATA; |
56 |
|
protected float compressionQuality; |
57 |
|
protected String compressionType; |
58 |
|
protected String[] compressionTypes; |
59 |
|
protected Locale locale; |
60 |
|
protected Dimension[] preferredTileSizes; |
61 |
|
protected int progressiveMode = MODE_COPY_FROM_METADATA; |
62 |
|
protected int tileGridXOffset; |
63 |
|
protected int tileGridYOffset; |
64 |
|
protected int tileHeight; |
65 |
|
protected int tileWidth; |
66 |
|
protected int tilingMode; |
67 |
|
protected boolean tilingSet; |
68 |
|
|
69 |
|
/** |
70 |
|
* Creates an empty <code>ImageWriteParam</code> object. |
71 |
|
* The subclass is responsible to initialize all fields. |
72 |
|
*/ |
73 |
|
protected ImageWriteParam() |
74 |
|
{ |
75 |
|
// Do nothing here. |
76 |
|
} |
77 |
|
|
78 |
|
/** |
79 |
|
* Creates an <code>ImageWriteParam</code> object with the given locale. |
80 |
|
* |
81 |
|
* @param locale the locale to use for user visible strings |
82 |
|
*/ |
83 |
|
public ImageWriteParam(Locale locale) |
84 |
|
{ |
85 |
|
this.locale = locale; |
86 |
|
} |
87 |
|
|
88 |
|
public float getBitRate(float quality) |
89 |
|
{ |
90 |
|
checkNotExplicitCompression(); |
91 |
|
checkCompressionTypesSet(); |
92 |
|
|
93 |
|
return -1.0f; |
94 |
|
} |
95 |
|
|
96 |
|
private void checkSupportsCompression() |
97 |
|
{ |
98 |
|
if (! canWriteCompressed()) |
99 |
|
throw new UnsupportedOperationException("compression not supported"); |
100 |
|
} |
101 |
|
|
102 |
|
private void checkNotExplicitCompression() |
103 |
|
{ |
104 |
|
if (getCompressionMode() != MODE_EXPLICIT) |
105 |
|
throw new IllegalStateException("compression mode is not MODE_EXPLICIT"); |
106 |
|
} |
107 |
|
|
108 |
|
private void checkCompressionTypesSet() |
109 |
|
{ |
110 |
|
if (getCompressionType() == null |
111 |
|
&& getCompressionTypes() != null) |
112 |
|
throw new IllegalStateException("no compression type set"); |
113 |
|
} |
114 |
|
|
115 |
|
private void checkSupportsProgressiveEncoding() |
116 |
|
{ |
117 |
|
if (! canWriteProgressive()) |
118 |
|
throw new UnsupportedOperationException |
119 |
|
("progressive output not supported"); |
120 |
|
} |
121 |
|
|
122 |
|
private void checkSupportsTiling() |
123 |
|
{ |
124 |
|
if (! canWriteTiles()) |
125 |
|
throw new UnsupportedOperationException("tiling not supported"); |
126 |
|
} |
127 |
|
|
128 |
|
private void checkNotExplicitTiling() |
129 |
|
{ |
130 |
|
if (getTilingMode() != MODE_EXPLICIT) |
131 |
|
throw new IllegalStateException("tiling mode not MODE_EXPLICIT"); |
132 |
|
} |
133 |
|
|
134 |
|
private void checkTilingInitialized() |
135 |
|
{ |
136 |
|
if (! tilingSet) |
137 |
|
throw new IllegalStateException("tiling parameters not set"); |
138 |
|
} |
139 |
|
|
140 |
|
private void checkMode(int mode) |
141 |
|
{ |
142 |
|
if (mode < MODE_DISABLED || mode > MODE_COPY_FROM_METADATA) |
143 |
|
throw new IllegalArgumentException("mode not supported"); |
144 |
|
} |
145 |
|
|
146 |
|
public boolean canOffsetTiles() |
147 |
|
{ |
148 |
|
return canOffsetTiles; |
149 |
|
} |
150 |
|
|
151 |
|
public boolean canWriteCompressed() |
152 |
|
{ |
153 |
|
return canWriteCompressed; |
154 |
|
} |
155 |
|
|
156 |
|
public boolean canWriteProgressive() |
157 |
|
{ |
158 |
|
return canWriteProgressive; |
159 |
|
} |
160 |
|
|
161 |
|
public boolean canWriteTiles() |
162 |
|
{ |
163 |
|
return canWriteTiles; |
164 |
|
} |
165 |
|
|
166 |
|
public int getCompressionMode() |
167 |
|
{ |
168 |
|
checkSupportsCompression(); |
169 |
|
|
170 |
|
return compressionMode; |
171 |
|
} |
172 |
|
|
173 |
|
public float getCompressionQuality() |
174 |
|
{ |
175 |
|
checkNotExplicitCompression(); |
176 |
|
checkCompressionTypesSet(); |
177 |
|
|
178 |
|
return compressionQuality; |
179 |
|
} |
180 |
|
|
181 |
|
public String[] getCompressionQualityDescriptions() |
182 |
|
{ |
183 |
|
checkNotExplicitCompression(); |
184 |
|
checkCompressionTypesSet();; |
185 |
|
|
186 |
|
return null; |
187 |
|
} |
188 |
|
|
189 |
|
public float[] getCompressionQualityValues() |
190 |
|
{ |
191 |
|
checkNotExplicitCompression(); |
192 |
|
checkCompressionTypesSet();; |
193 |
|
|
194 |
|
return null; |
195 |
|
} |
196 |
|
|
197 |
|
public String getCompressionType() |
198 |
|
{ |
199 |
|
checkNotExplicitCompression(); |
200 |
|
|
201 |
|
return compressionType; |
202 |
|
} |
203 |
|
|
204 |
|
public String[] getCompressionTypes() |
205 |
|
{ |
206 |
|
checkSupportsCompression(); |
207 |
|
|
208 |
|
return compressionTypes != null ? (String[]) compressionTypes.clone() : null; |
209 |
|
} |
210 |
|
|
211 |
|
public Locale getLocale() |
212 |
|
{ |
213 |
|
return locale; |
214 |
|
} |
215 |
|
|
216 |
|
public String getLocalizedCompressionTypeName() |
217 |
|
{ |
218 |
|
checkNotExplicitCompression(); |
219 |
|
checkCompressionTypesSet(); |
220 |
|
|
221 |
|
return getCompressionType(); |
222 |
|
} |
223 |
|
|
224 |
|
public Dimension[] getPreferredTileSizes() |
225 |
|
{ |
226 |
|
checkSupportsTiling(); |
227 |
|
|
228 |
|
return preferredTileSizes; |
229 |
|
} |
230 |
|
|
231 |
|
public int getProgressiveMode() |
232 |
|
{ |
233 |
|
checkSupportsProgressiveEncoding(); |
234 |
|
|
235 |
|
return progressiveMode; |
236 |
|
} |
237 |
|
|
238 |
|
public int getTileGridXOffset() |
239 |
|
{ |
240 |
|
checkNotExplicitTiling(); |
241 |
|
checkTilingInitialized(); |
242 |
|
|
243 |
|
return tileGridXOffset; |
244 |
|
} |
245 |
|
|
246 |
|
public int getTileGridYOffset() |
247 |
|
{ |
248 |
|
checkNotExplicitTiling(); |
249 |
|
checkTilingInitialized(); |
250 |
|
|
251 |
|
return tileGridYOffset; |
252 |
|
} |
253 |
|
|
254 |
|
public int getTileHeight() |
255 |
|
{ |
256 |
|
checkNotExplicitTiling(); |
257 |
|
checkTilingInitialized(); |
258 |
|
|
259 |
|
return tileHeight; |
260 |
|
} |
261 |
|
|
262 |
|
public int getTileWidth() |
263 |
|
{ |
264 |
|
checkNotExplicitTiling(); |
265 |
|
checkTilingInitialized(); |
266 |
|
|
267 |
|
return tileWidth; |
268 |
|
} |
269 |
|
|
270 |
|
public int getTilingMode() |
271 |
|
{ |
272 |
|
checkSupportsTiling(); |
273 |
|
|
274 |
|
return tilingMode; |
275 |
|
} |
276 |
|
|
277 |
|
public boolean isCompressionLossless() |
278 |
|
{ |
279 |
|
checkNotExplicitCompression(); |
280 |
|
checkCompressionTypesSet(); |
281 |
|
|
282 |
|
return true; |
283 |
|
} |
284 |
|
|
285 |
|
public void setCompressionMode(int mode) |
286 |
|
{ |
287 |
|
checkSupportsCompression(); |
288 |
|
checkMode(mode); |
289 |
|
|
290 |
|
compressionMode = mode; |
291 |
|
|
292 |
|
if (mode == MODE_EXPLICIT) |
293 |
|
unsetCompression(); |
294 |
|
} |
295 |
|
|
296 |
|
public void setCompressionQuality(float quality) |
297 |
|
{ |
298 |
|
checkNotExplicitCompression(); |
299 |
|
checkCompressionTypesSet(); |
300 |
|
|
301 |
|
if (quality < 0.0f || quality > 1.0f) |
302 |
|
throw new IllegalArgumentException("quality out of range"); |
303 |
|
|
304 |
|
compressionQuality = quality; |
305 |
|
} |
306 |
|
|
307 |
|
public void setCompressionType(String compressionType) |
308 |
|
{ |
309 |
|
checkNotExplicitCompression(); |
310 |
|
|
311 |
|
String[] types = getCompressionTypes(); |
312 |
|
|
313 |
|
if (types == null) |
314 |
|
throw new UnsupportedOperationException("no settable compression types"); |
315 |
|
|
316 |
|
if (compressionType == null) |
317 |
|
this.compressionType = null; |
318 |
|
|
319 |
|
for (int i = types.length - 1; i >= 0; --i) |
320 |
|
if (types[i].equals(compressionType)) |
321 |
|
{ |
322 |
|
this.compressionType = compressionType; |
323 |
|
return; |
324 |
|
} |
325 |
|
|
326 |
|
throw new IllegalArgumentException("unknown compression type"); |
327 |
|
} |
328 |
|
|
329 |
|
public void setProgressiveMode(int mode) |
330 |
|
{ |
331 |
|
checkSupportsProgressiveEncoding(); |
332 |
|
checkMode(mode); |
333 |
|
|
334 |
|
progressiveMode = mode; |
335 |
|
} |
336 |
|
|
337 |
|
public void setTiling(int tileWidth, int tileHeight, |
338 |
|
int tileGridXOffset, int tileGridYOffset) |
339 |
|
{ |
340 |
|
checkNotExplicitTiling(); |
341 |
|
|
342 |
|
if (! canOffsetTiles |
343 |
|
&& tileGridXOffset != 0 |
344 |
|
&& tileGridYOffset != 0) |
345 |
|
throw new UnsupportedOperationException("tile offsets not supported"); |
346 |
|
|
347 |
|
if (tileWidth < 0 || tileHeight < 0) |
348 |
|
throw new IllegalArgumentException("negative tile dimension"); |
349 |
|
|
350 |
|
if (preferredTileSizes != null) |
351 |
|
{ |
352 |
|
boolean found = false; |
353 |
|
|
354 |
|
for (int i = 0; i < preferredTileSizes.length; i += 2) |
355 |
|
{ |
356 |
|
if (tileWidth >= preferredTileSizes[i].width |
357 |
|
&& tileWidth <= preferredTileSizes[i + 1].width |
358 |
|
&& tileHeight >= preferredTileSizes[i].height |
359 |
|
&& tileHeight <= preferredTileSizes[i + 1].height) |
360 |
|
found = true; |
361 |
|
} |
362 |
|
|
363 |
|
if (! found) |
364 |
|
throw new IllegalArgumentException("illegal tile size"); |
365 |
|
} |
366 |
|
|
367 |
|
this.tilingSet = true; |
368 |
|
this.tileWidth = tileWidth; |
369 |
|
this.tileHeight = tileHeight; |
370 |
|
this.tileGridXOffset = tileGridXOffset; |
371 |
|
this.tileGridYOffset = tileGridYOffset; |
372 |
|
} |
373 |
|
|
374 |
|
public void setTilingMode(int mode) |
375 |
|
{ |
376 |
|
checkSupportsTiling(); |
377 |
|
checkMode(mode); |
378 |
|
tilingMode = mode; |
379 |
|
} |
380 |
|
|
381 |
|
public void unsetCompression() |
382 |
|
{ |
383 |
|
checkNotExplicitCompression(); |
384 |
|
|
385 |
|
compressionType = null; |
386 |
|
compressionQuality = 1.0F; |
387 |
|
} |
388 |
|
|
389 |
|
public void unsetTiling() |
390 |
|
{ |
391 |
|
checkNotExplicitTiling(); |
392 |
|
|
393 |
|
tileWidth = 0; |
394 |
|
tileHeight = 0; |
395 |
|
tileGridXOffset = 0; |
396 |
|
tileGridYOffset = 0; |
397 |
|
} |
398 |
} |
} |