Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / javax / imageio / ImageWriteParam.java
blob0eb9073dcb6535fc161bf1f920fcb70fc19a6dab
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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 public class ImageWriteParam extends IIOParam
46 public static final int MODE_DISABLED = 0;
47 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;
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;
69 /**
70 * Creates an empty <code>ImageWriteParam</code> object.
71 * The subclass is responsible to initialize all fields.
73 protected ImageWriteParam()
75 // Do nothing here.
78 /**
79 * Creates an <code>ImageWriteParam</code> object with the given locale.
81 * @param locale the locale to use for user visible strings
83 public ImageWriteParam(Locale locale)
85 this.locale = locale;
88 public float getBitRate(float quality)
90 checkNotExplicitCompression();
91 checkCompressionTypesSet();
93 return -1.0f;
96 private void checkSupportsCompression()
98 if (! canWriteCompressed())
99 throw new UnsupportedOperationException("compression not supported");
102 private void checkNotExplicitCompression()
104 if (getCompressionMode() != MODE_EXPLICIT)
105 throw new IllegalStateException("compression mode is not MODE_EXPLICIT");
108 private void checkCompressionTypesSet()
110 if (getCompressionType() == null
111 && getCompressionTypes() != null)
112 throw new IllegalStateException("no compression type set");
115 private void checkSupportsProgressiveEncoding()
117 if (! canWriteProgressive())
118 throw new UnsupportedOperationException
119 ("progressive output not supported");
122 private void checkSupportsTiling()
124 if (! canWriteTiles())
125 throw new UnsupportedOperationException("tiling not supported");
128 private void checkNotExplicitTiling()
130 if (getTilingMode() != MODE_EXPLICIT)
131 throw new IllegalStateException("tiling mode not MODE_EXPLICIT");
134 private void checkTilingInitialized()
136 if (! tilingSet)
137 throw new IllegalStateException("tiling parameters not set");
140 private void checkMode(int mode)
142 if (mode < MODE_DISABLED || mode > MODE_COPY_FROM_METADATA)
143 throw new IllegalArgumentException("mode not supported");
146 public boolean canOffsetTiles()
148 return canOffsetTiles;
151 public boolean canWriteCompressed()
153 return canWriteCompressed;
156 public boolean canWriteProgressive()
158 return canWriteProgressive;
161 public boolean canWriteTiles()
163 return canWriteTiles;
166 public int getCompressionMode()
168 checkSupportsCompression();
170 return compressionMode;
173 public float getCompressionQuality()
175 checkNotExplicitCompression();
176 checkCompressionTypesSet();
178 return compressionQuality;
181 public String[] getCompressionQualityDescriptions()
183 checkNotExplicitCompression();
184 checkCompressionTypesSet();;
186 return null;
189 public float[] getCompressionQualityValues()
191 checkNotExplicitCompression();
192 checkCompressionTypesSet();;
194 return null;
197 public String getCompressionType()
199 checkNotExplicitCompression();
201 return compressionType;
204 public String[] getCompressionTypes()
206 checkSupportsCompression();
208 return compressionTypes != null ? (String[]) compressionTypes.clone() : null;
211 public Locale getLocale()
213 return locale;
216 public String getLocalizedCompressionTypeName()
218 checkNotExplicitCompression();
219 checkCompressionTypesSet();
221 return getCompressionType();
224 public Dimension[] getPreferredTileSizes()
226 checkSupportsTiling();
228 return preferredTileSizes;
231 public int getProgressiveMode()
233 checkSupportsProgressiveEncoding();
235 return progressiveMode;
238 public int getTileGridXOffset()
240 checkNotExplicitTiling();
241 checkTilingInitialized();
243 return tileGridXOffset;
246 public int getTileGridYOffset()
248 checkNotExplicitTiling();
249 checkTilingInitialized();
251 return tileGridYOffset;
254 public int getTileHeight()
256 checkNotExplicitTiling();
257 checkTilingInitialized();
259 return tileHeight;
262 public int getTileWidth()
264 checkNotExplicitTiling();
265 checkTilingInitialized();
267 return tileWidth;
270 public int getTilingMode()
272 checkSupportsTiling();
274 return tilingMode;
277 public boolean isCompressionLossless()
279 checkNotExplicitCompression();
280 checkCompressionTypesSet();
282 return true;
285 public void setCompressionMode(int mode)
287 checkSupportsCompression();
288 checkMode(mode);
290 compressionMode = mode;
292 if (mode == MODE_EXPLICIT)
293 unsetCompression();
296 public void setCompressionQuality(float quality)
298 checkNotExplicitCompression();
299 checkCompressionTypesSet();
301 if (quality < 0.0f || quality > 1.0f)
302 throw new IllegalArgumentException("quality out of range");
304 compressionQuality = quality;
307 public void setCompressionType(String compressionType)
309 checkNotExplicitCompression();
311 String[] types = getCompressionTypes();
313 if (types == null)
314 throw new UnsupportedOperationException("no settable compression types");
316 if (compressionType == null)
317 this.compressionType = null;
319 for (int i = types.length - 1; i >= 0; --i)
320 if (types[i].equals(compressionType))
322 this.compressionType = compressionType;
323 return;
326 throw new IllegalArgumentException("unknown compression type");
329 public void setProgressiveMode(int mode)
331 checkSupportsProgressiveEncoding();
332 checkMode(mode);
334 progressiveMode = mode;
337 public void setTiling(int tileWidth, int tileHeight,
338 int tileGridXOffset, int tileGridYOffset)
340 checkNotExplicitTiling();
342 if (! canOffsetTiles
343 && tileGridXOffset != 0
344 && tileGridYOffset != 0)
345 throw new UnsupportedOperationException("tile offsets not supported");
347 if (tileWidth < 0 || tileHeight < 0)
348 throw new IllegalArgumentException("negative tile dimension");
350 if (preferredTileSizes != null)
352 boolean found = false;
354 for (int i = 0; i < preferredTileSizes.length; i += 2)
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;
363 if (! found)
364 throw new IllegalArgumentException("illegal tile size");
367 this.tilingSet = true;
368 this.tileWidth = tileWidth;
369 this.tileHeight = tileHeight;
370 this.tileGridXOffset = tileGridXOffset;
371 this.tileGridYOffset = tileGridYOffset;
374 public void setTilingMode(int mode)
376 checkSupportsTiling();
377 checkMode(mode);
378 tilingMode = mode;
381 public void unsetCompression()
383 checkNotExplicitCompression();
385 compressionType = null;
386 compressionQuality = 1.0F;
389 public void unsetTiling()
391 checkNotExplicitTiling();
393 tileWidth = 0;
394 tileHeight = 0;
395 tileGridXOffset = 0;
396 tileGridYOffset = 0;