Imported GNU Classpath 0.19 + gcj-import-20051115.
[official-gcc.git] / libjava / classpath / javax / imageio / ImageWriteParam.java
blob84b257e04eb04fd7d9083b9c0bc612af1d4b1c8a
1 /* ImageWriteParam.java --
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.imageio;
41 import java.awt.Dimension;
42 import java.util.Locale;
44 /**
45 * DOCUMENT ME
47 public class ImageWriteParam extends IIOParam
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;
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;
72 /**
73 * Creates an empty <code>ImageWriteParam</code> object.
74 * The subclass is responsible to initialize all fields.
76 protected ImageWriteParam()
78 // Do nothing here.
81 /**
82 * Creates an <code>ImageWriteParam</code> object with the given locale.
84 * @param locale the locale to use for user visible strings
86 public ImageWriteParam(Locale locale)
88 this.locale = locale;
91 public float getBitRate(float quality)
93 checkNotExplicitCompression();
94 checkCompressionTypesSet();
96 return -1.0f;
99 private void checkSupportsCompression()
101 if (! canWriteCompressed())
102 throw new UnsupportedOperationException("compression not supported");
105 private void checkNotExplicitCompression()
107 if (getCompressionMode() != MODE_EXPLICIT)
108 throw new IllegalStateException("compression mode is not MODE_EXPLICIT");
111 private void checkCompressionTypesSet()
113 if (getCompressionType() == null
114 && getCompressionTypes() != null)
115 throw new IllegalStateException("no compression type set");
118 private void checkSupportsProgressiveEncoding()
120 if (! canWriteProgressive())
121 throw new UnsupportedOperationException
122 ("progressive output not supported");
125 private void checkSupportsTiling()
127 if (! canWriteTiles())
128 throw new UnsupportedOperationException("tiling not supported");
131 private void checkNotExplicitTiling()
133 if (getTilingMode() != MODE_EXPLICIT)
134 throw new IllegalStateException("tiling mode not MODE_EXPLICIT");
137 private void checkTilingInitialized()
139 if (! tilingSet)
140 throw new IllegalStateException("tiling parameters not set");
143 private void checkMode(int mode)
145 if (mode < MODE_DISABLED || mode > MODE_COPY_FROM_METADATA)
146 throw new IllegalArgumentException("mode not supported");
149 public boolean canOffsetTiles()
151 return canOffsetTiles;
154 public boolean canWriteCompressed()
156 return canWriteCompressed;
159 public boolean canWriteProgressive()
161 return canWriteProgressive;
164 public boolean canWriteTiles()
166 return canWriteTiles;
169 public int getCompressionMode()
171 checkSupportsCompression();
173 return compressionMode;
176 public float getCompressionQuality()
178 checkNotExplicitCompression();
179 checkCompressionTypesSet();
181 return compressionQuality;
184 public String[] getCompressionQualityDescriptions()
186 checkNotExplicitCompression();
187 checkCompressionTypesSet();;
189 return null;
192 public float[] getCompressionQualityValues()
194 checkNotExplicitCompression();
195 checkCompressionTypesSet();;
197 return null;
200 public String getCompressionType()
202 checkNotExplicitCompression();
204 return compressionType;
207 public String[] getCompressionTypes()
209 checkSupportsCompression();
211 return compressionTypes != null ? (String[]) compressionTypes.clone() : null;
214 public Locale getLocale()
216 return locale;
219 public String getLocalizedCompressionTypeName()
221 checkNotExplicitCompression();
222 checkCompressionTypesSet();
224 return getCompressionType();
227 public Dimension[] getPreferredTileSizes()
229 checkSupportsTiling();
231 return preferredTileSizes;
234 public int getProgressiveMode()
236 checkSupportsProgressiveEncoding();
238 return progressiveMode;
241 public int getTileGridXOffset()
243 checkNotExplicitTiling();
244 checkTilingInitialized();
246 return tileGridXOffset;
249 public int getTileGridYOffset()
251 checkNotExplicitTiling();
252 checkTilingInitialized();
254 return tileGridYOffset;
257 public int getTileHeight()
259 checkNotExplicitTiling();
260 checkTilingInitialized();
262 return tileHeight;
265 public int getTileWidth()
267 checkNotExplicitTiling();
268 checkTilingInitialized();
270 return tileWidth;
273 public int getTilingMode()
275 checkSupportsTiling();
277 return tilingMode;
280 public boolean isCompressionLossless()
282 checkNotExplicitCompression();
283 checkCompressionTypesSet();
285 return true;
288 public void setCompressionMode(int mode)
290 checkSupportsCompression();
291 checkMode(mode);
293 compressionMode = mode;
295 if (mode == MODE_EXPLICIT)
296 unsetCompression();
299 public void setCompressionQuality(float quality)
301 checkNotExplicitCompression();
302 checkCompressionTypesSet();
304 if (quality < 0.0f || quality > 1.0f)
305 throw new IllegalArgumentException("quality out of range");
307 compressionQuality = quality;
310 public void setCompressionType(String compressionType)
312 checkNotExplicitCompression();
314 String[] types = getCompressionTypes();
316 if (types == null)
317 throw new UnsupportedOperationException("no settable compression types");
319 if (compressionType == null)
320 this.compressionType = null;
322 for (int i = types.length - 1; i >= 0; --i)
323 if (types[i].equals(compressionType))
325 this.compressionType = compressionType;
326 return;
329 throw new IllegalArgumentException("unknown compression type");
332 public void setProgressiveMode(int mode)
334 checkSupportsProgressiveEncoding();
335 checkMode(mode);
337 progressiveMode = mode;
340 public void setTiling(int tileWidth, int tileHeight,
341 int tileGridXOffset, int tileGridYOffset)
343 checkNotExplicitTiling();
345 if (! canOffsetTiles
346 && tileGridXOffset != 0
347 && tileGridYOffset != 0)
348 throw new UnsupportedOperationException("tile offsets not supported");
350 if (tileWidth < 0 || tileHeight < 0)
351 throw new IllegalArgumentException("negative tile dimension");
353 if (preferredTileSizes != null)
355 boolean found = false;
357 for (int i = 0; i < preferredTileSizes.length; i += 2)
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;
366 if (! found)
367 throw new IllegalArgumentException("illegal tile size");
370 this.tilingSet = true;
371 this.tileWidth = tileWidth;
372 this.tileHeight = tileHeight;
373 this.tileGridXOffset = tileGridXOffset;
374 this.tileGridYOffset = tileGridYOffset;
377 public void setTilingMode(int mode)
379 checkSupportsTiling();
380 checkMode(mode);
381 tilingMode = mode;
384 public void unsetCompression()
386 checkNotExplicitCompression();
388 compressionType = null;
389 compressionQuality = 1.0F;
392 public void unsetTiling()
394 checkNotExplicitTiling();
396 tileWidth = 0;
397 tileHeight = 0;
398 tileGridXOffset = 0;
399 tileGridYOffset = 0;