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