1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43:
44:
47: public class ImageWriteParam extends IIOParam
48: {
49:
50:
54: public static final int MODE_DISABLED = 0;
55:
56:
60: public static final int MODE_DEFAULT = 1;
61:
62:
65: public static final int MODE_EXPLICIT = 2;
66:
67:
71: public static final int MODE_COPY_FROM_METADATA = 3;
72:
73:
76: protected boolean canOffsetTiles;
77:
78:
81: protected boolean canWriteCompressed;
82:
83:
87: protected boolean canWriteProgressive;
88:
89:
92: protected boolean canWriteTiles;
93:
94:
98: protected int compressionMode = MODE_COPY_FROM_METADATA;
99:
100:
103: protected float compressionQuality;
104:
105:
108: protected String compressionType;
109:
110:
113: protected String[] compressionTypes;
114:
115:
119: protected Locale locale;
120:
121:
124: protected Dimension[] preferredTileSizes;
125:
126:
131: protected int progressiveMode = MODE_COPY_FROM_METADATA;
132:
133:
137: protected int tileGridXOffset;
138:
139:
143: protected int tileGridYOffset;
144:
145:
148: protected int tileHeight;
149:
150:
153: protected int tileWidth;
154:
155:
159: protected int tilingMode;
160:
161:
164: protected boolean tilingSet;
165:
166:
170: protected ImageWriteParam()
171: {
172:
173: }
174:
175:
180: public ImageWriteParam(Locale locale)
181: {
182: this.locale = locale;
183: }
184:
185: public float getBitRate(float quality)
186: {
187: checkNotExplicitCompression();
188: checkCompressionTypesSet();
189:
190: return -1.0f;
191: }
192:
193: private void checkSupportsCompression()
194: {
195: if (! canWriteCompressed())
196: throw new UnsupportedOperationException("compression not supported");
197: }
198:
199: private void checkNotExplicitCompression()
200: {
201: if (getCompressionMode() != MODE_EXPLICIT)
202: throw new IllegalStateException("compression mode is not MODE_EXPLICIT");
203: }
204:
205: private void checkCompressionTypesSet()
206: {
207: if (getCompressionType() == null
208: && getCompressionTypes() != null)
209: throw new IllegalStateException("no compression type set");
210: }
211:
212: private void checkSupportsProgressiveEncoding()
213: {
214: if (! canWriteProgressive())
215: throw new UnsupportedOperationException
216: ("progressive output not supported");
217: }
218:
219: private void checkSupportsTiling()
220: {
221: if (! canWriteTiles())
222: throw new UnsupportedOperationException("tiling not supported");
223: }
224:
225: private void checkNotExplicitTiling()
226: {
227: if (getTilingMode() != MODE_EXPLICIT)
228: throw new IllegalStateException("tiling mode not MODE_EXPLICIT");
229: }
230:
231: private void checkTilingInitialized()
232: {
233: if (! tilingSet)
234: throw new IllegalStateException("tiling parameters not set");
235: }
236:
237: private void checkMode(int mode)
238: {
239: if (mode < MODE_DISABLED || mode > MODE_COPY_FROM_METADATA)
240: throw new IllegalArgumentException("mode not supported");
241: }
242:
243: public boolean canOffsetTiles()
244: {
245: return canOffsetTiles;
246: }
247:
248: public boolean canWriteCompressed()
249: {
250: return canWriteCompressed;
251: }
252:
253: public boolean canWriteProgressive()
254: {
255: return canWriteProgressive;
256: }
257:
258: public boolean canWriteTiles()
259: {
260: return canWriteTiles;
261: }
262:
263: public int getCompressionMode()
264: {
265: checkSupportsCompression();
266:
267: return compressionMode;
268: }
269:
270: public float getCompressionQuality()
271: {
272: checkNotExplicitCompression();
273: checkCompressionTypesSet();
274:
275: return compressionQuality;
276: }
277:
278: public String[] getCompressionQualityDescriptions()
279: {
280: checkNotExplicitCompression();
281: checkCompressionTypesSet();
282:
283: return null;
284: }
285:
286: public float[] getCompressionQualityValues()
287: {
288: checkNotExplicitCompression();
289: checkCompressionTypesSet();
290:
291: return null;
292: }
293:
294: public String getCompressionType()
295: {
296: checkNotExplicitCompression();
297:
298: return compressionType;
299: }
300:
301: public String[] getCompressionTypes()
302: {
303: checkSupportsCompression();
304:
305: return compressionTypes != null ? (String[]) compressionTypes.clone() : null;
306: }
307:
308: public Locale getLocale()
309: {
310: return locale;
311: }
312:
313: public String getLocalizedCompressionTypeName()
314: {
315: checkNotExplicitCompression();
316: checkCompressionTypesSet();
317:
318: return getCompressionType();
319: }
320:
321: public Dimension[] getPreferredTileSizes()
322: {
323: checkSupportsTiling();
324:
325: return preferredTileSizes;
326: }
327:
328: public int getProgressiveMode()
329: {
330: checkSupportsProgressiveEncoding();
331:
332: return progressiveMode;
333: }
334:
335: public int getTileGridXOffset()
336: {
337: checkNotExplicitTiling();
338: checkTilingInitialized();
339:
340: return tileGridXOffset;
341: }
342:
343: public int getTileGridYOffset()
344: {
345: checkNotExplicitTiling();
346: checkTilingInitialized();
347:
348: return tileGridYOffset;
349: }
350:
351: public int getTileHeight()
352: {
353: checkNotExplicitTiling();
354: checkTilingInitialized();
355:
356: return tileHeight;
357: }
358:
359: public int getTileWidth()
360: {
361: checkNotExplicitTiling();
362: checkTilingInitialized();
363:
364: return tileWidth;
365: }
366:
367: public int getTilingMode()
368: {
369: checkSupportsTiling();
370:
371: return tilingMode;
372: }
373:
374: public boolean isCompressionLossless()
375: {
376: checkNotExplicitCompression();
377: checkCompressionTypesSet();
378:
379: return true;
380: }
381:
382: public void setCompressionMode(int mode)
383: {
384: checkSupportsCompression();
385: checkMode(mode);
386:
387: compressionMode = mode;
388:
389: if (mode == MODE_EXPLICIT)
390: unsetCompression();
391: }
392:
393: public void setCompressionQuality(float quality)
394: {
395: checkNotExplicitCompression();
396: checkCompressionTypesSet();
397:
398: if (quality < 0.0f || quality > 1.0f)
399: throw new IllegalArgumentException("quality out of range");
400:
401: compressionQuality = quality;
402: }
403:
404: public void setCompressionType(String compressionType)
405: {
406: checkNotExplicitCompression();
407:
408: String[] types = getCompressionTypes();
409:
410: if (types == null)
411: throw new UnsupportedOperationException("no settable compression types");
412:
413: if (compressionType == null)
414: this.compressionType = null;
415:
416: for (int i = types.length - 1; i >= 0; --i)
417: if (types[i].equals(compressionType))
418: {
419: this.compressionType = compressionType;
420: return;
421: }
422:
423: throw new IllegalArgumentException("unknown compression type");
424: }
425:
426: public void setProgressiveMode(int mode)
427: {
428: checkSupportsProgressiveEncoding();
429: checkMode(mode);
430:
431: progressiveMode = mode;
432: }
433:
434: public void setTiling(int tileWidth, int tileHeight,
435: int tileGridXOffset, int tileGridYOffset)
436: {
437: checkNotExplicitTiling();
438:
439: if (! canOffsetTiles
440: && tileGridXOffset != 0
441: && tileGridYOffset != 0)
442: throw new UnsupportedOperationException("tile offsets not supported");
443:
444: if (tileWidth < 0 || tileHeight < 0)
445: throw new IllegalArgumentException("negative tile dimension");
446:
447: if (preferredTileSizes != null)
448: {
449: boolean found = false;
450:
451: for (int i = 0; i < preferredTileSizes.length; i += 2)
452: {
453: if (tileWidth >= preferredTileSizes[i].width
454: && tileWidth <= preferredTileSizes[i + 1].width
455: && tileHeight >= preferredTileSizes[i].height
456: && tileHeight <= preferredTileSizes[i + 1].height)
457: found = true;
458: }
459:
460: if (! found)
461: throw new IllegalArgumentException("illegal tile size");
462: }
463:
464: this.tilingSet = true;
465: this.tileWidth = tileWidth;
466: this.tileHeight = tileHeight;
467: this.tileGridXOffset = tileGridXOffset;
468: this.tileGridYOffset = tileGridYOffset;
469: }
470:
471: public void setTilingMode(int mode)
472: {
473: checkSupportsTiling();
474: checkMode(mode);
475: tilingMode = mode;
476: }
477:
478: public void unsetCompression()
479: {
480: checkNotExplicitCompression();
481:
482: compressionType = null;
483: compressionQuality = 1.0F;
484: }
485:
486: public void unsetTiling()
487: {
488: checkNotExplicitTiling();
489:
490: tileWidth = 0;
491: tileHeight = 0;
492: tileGridXOffset = 0;
493: tileGridYOffset = 0;
494: }
495: }