/* * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.imageio; import java.awt.Dimension;import java.util.Locale; /** * A class describing how a stream is to be encoded. Instances of * this class or its subclasses are used to supply prescriptive * "how-to" information to instances of <code>ImageWriter</code>. * * <p> A plug-in for a specific image format may define a subclass of * this class, and return objects of that class from the * <code>getDefaultWriteParam</code> method of its * <code>ImageWriter</code> implementation. For example, the built-in * JPEG writer plug-in will return instances of * <code>javax.imageio.plugins.jpeg.JPEGImageWriteParam</code>. * * <p> The region of the image to be written is determined by first * intersecting the actual bounds of the image with the rectangle * specified by <code>IIOParam.setSourceRegion</code>, if any. If the * resulting rectangle has a width or height of zero, the writer will * throw an <code>IIOException</code>. If the intersection is * non-empty, writing will commence with the first subsampled pixel * and include additional pixels within the intersected bounds * according to the horizontal and vertical subsampling factors * specified by {@link IIOParam#setSourceSubsampling * <code>IIOParam.setSourceSubsampling</code>}. * * <p> Individual features such as tiling, progressive encoding, and * compression may be set in one of four modes. * <code>MODE_DISABLED</code> disables the features; * <code>MODE_DEFAULT</code> enables the feature with * writer-controlled parameter values; <code>MODE_EXPLICIT</code> * enables the feature and allows the use of a <code>set</code> method * to provide additional parameters; and * <code>MODE_COPY_FROM_METADATA</code> copies relevant parameter * values from the stream and image metadata objects passed to the * writer. The default for all features is * <code>MODE_COPY_FROM_METADATA</code>. Non-standard features * supplied in subclasses are encouraged, but not required to use a * similar scheme. * * <p> Plug-in writers may extend the functionality of * <code>ImageWriteParam</code> by providing a subclass that implements * additional, plug-in specific interfaces. It is up to the plug-in * to document what interfaces are available and how they are to be * used. Writers will silently ignore any extended features of an * <code>ImageWriteParam</code> subclass of which they are not aware. * Also, they may ignore any optional features that they normally * disable when creating their own <code>ImageWriteParam</code> * instances via <code>getDefaultWriteParam</code>. * * <p> Note that unless a query method exists for a capability, it must * be supported by all <code>ImageWriter</code> implementations * (<i>e.g.</i> progressive encoding is optional, but subsampling must be * supported). * * * @see ImageReadParam */public class ImageWriteParam extends IIOParam { /** * A constant value that may be passed into methods such as * <code>setTilingMode</code>, <code>setProgressiveMode</code>, * and <code>setCompressionMode</code> to disable a feature for * future writes. That is, when this mode is set the stream will * <b>not</b> be tiled, progressive, or compressed, and the * relevant accessor methods will throw an * <code>IllegalStateException</code>. * * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setProgressiveMode * @see #getProgressiveMode * @see #setTilingMode * @see #getTilingMode * @see #setCompressionMode * @see #getCompressionMode */ public static final int MODE_DISABLED = 0; /** * A constant value that may be passed into methods such as * <code>setTilingMode</code>, * <code>setProgressiveMode</code>, and * <code>setCompressionMode</code> to enable that feature for * future writes. That is, when this mode is enabled the stream * will be tiled, progressive, or compressed according to a * sensible default chosen internally by the writer in a plug-in * dependent way, and the relevant accessor methods will * throw an <code>IllegalStateException</code>. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #setProgressiveMode * @see #getProgressiveMode * @see #setTilingMode * @see #getTilingMode * @see #setCompressionMode * @see #getCompressionMode */ public static final int MODE_DEFAULT = 1; /** * A constant value that may be passed into methods such as * <code>setTilingMode</code> or <code>setCompressionMode</code> * to enable a feature for future writes. That is, when this mode * is set the stream will be tiled or compressed according to * additional information supplied to the corresponding * <code>set</code> methods in this class and retrievable from the * corresponding <code>get</code> methods. Note that this mode is * not supported for progressive output. * * @see #MODE_DISABLED * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setProgressiveMode * @see #getProgressiveMode * @see #setTilingMode * @see #getTilingMode * @see #setCompressionMode * @see #getCompressionMode */ public static final int MODE_EXPLICIT = 2; /** * A constant value that may be passed into methods such as * <code>setTilingMode</code>, <code>setProgressiveMode</code>, or * <code>setCompressionMode</code> to enable that feature for * future writes. That is, when this mode is enabled the stream * will be tiled, progressive, or compressed based on the contents * of stream and/or image metadata passed into the write * operation, and any relevant accessor methods will throw an * <code>IllegalStateException</code>. * * <p> This is the default mode for all features, so that a read * including metadata followed by a write including metadata will * preserve as much information as possible. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_DEFAULT * @see #setProgressiveMode * @see #getProgressiveMode * @see #setTilingMode * @see #getTilingMode * @see #setCompressionMode * @see #getCompressionMode */ public static final int MODE_COPY_FROM_METADATA = 3; // If more modes are added, this should be updated. private static final int MAX_MODE = MODE_COPY_FROM_METADATA; /** * A <code>boolean</code> that is <code>true</code> if this * <code>ImageWriteParam</code> allows tile width and tile height * parameters to be set. By default, the value is * <code>false</code>. Subclasses must set the value manually. * * <p> Subclasses that do not support writing tiles should ensure * that this value is set to <code>false</code>. */ protected boolean canWriteTiles = false; /** * The mode controlling tiling settings, which Must be * set to one of the four <code>MODE_*</code> values. The default * is <code>MODE_COPY_FROM_METADATA</code>. * * <p> Subclasses that do not writing tiles may ignore this value. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setTilingMode * @see #getTilingMode */ protected int tilingMode = MODE_COPY_FROM_METADATA; /** * An array of preferred tile size range pairs. The default value * is <code>null</code>, which indicates that there are no * preferred sizes. If the value is non-<code>null</code>, it * must have an even length of at least two. * * <p> Subclasses that do not support writing tiles may ignore * this value. * * @see #getPreferredTileSizes */ protected Dimension[] preferredTileSizes = null; /** * A <code>boolean</code> that is <code>true</code> if tiling * parameters have been specified. * * <p> Subclasses that do not support writing tiles may ignore * this value. */ protected boolean tilingSet = false; /** * The width of each tile if tiling has been set, or 0 otherwise. * * <p> Subclasses that do not support tiling may ignore this * value. */ protected int tileWidth = 0; /** * The height of each tile if tiling has been set, or 0 otherwise. * The initial value is <code>0</code>. * * <p> Subclasses that do not support tiling may ignore this * value. */ protected int tileHeight = 0; /** * A <code>boolean</code> that is <code>true</code> if this * <code>ImageWriteParam</code> allows tiling grid offset * parameters to be set. By default, the value is * <code>false</code>. Subclasses must set the value manually. * * <p> Subclasses that do not support writing tiles, or that * supprt writing but not offsetting tiles must ensure that this * value is set to <code>false</code>. */ protected boolean canOffsetTiles = false; /** * The amount by which the tile grid origin should be offset * horizontally from the image origin if tiling has been set, * or 0 otherwise. The initial value is <code>0</code>. * * <p> Subclasses that do not support offsetting tiles may ignore * this value. */ protected int tileGridXOffset = 0; /** * The amount by which the tile grid origin should be offset * vertically from the image origin if tiling has been set, * or 0 otherwise. The initial value is <code>0</code>. * * <p> Subclasses that do not support offsetting tiles may ignore * this value. */ protected int tileGridYOffset = 0; /** * A <code>boolean</code> that is <code>true</code> if this * <code>ImageWriteParam</code> allows images to be written as a * progressive sequence of increasing quality passes. By default, * the value is <code>false</code>. Subclasses must set the value * manually. * * <p> Subclasses that do not support progressive encoding must * ensure that this value is set to <code>false</code>. */ protected boolean canWriteProgressive = false; /** * The mode controlling progressive encoding, which must be set to * one of the four <code>MODE_*</code> values, except * <code>MODE_EXPLICIT</code>. The default is * <code>MODE_COPY_FROM_METADATA</code>. * * <p> Subclasses that do not support progressive encoding may * ignore this value. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setProgressiveMode * @see #getProgressiveMode */ protected int progressiveMode = MODE_COPY_FROM_METADATA; /** * A <code>boolean</code> that is <code>true</code> if this writer * can write images using compression. By default, the value is * <code>false</code>. Subclasses must set the value manually. * * <p> Subclasses that do not support compression must ensure that * this value is set to <code>false</code>. */ protected boolean canWriteCompressed = false; /** * The mode controlling compression settings, which must be set to * one of the four <code>MODE_*</code> values. The default is * <code>MODE_COPY_FROM_METADATA</code>. * * <p> Subclasses that do not support compression may ignore this * value. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setCompressionMode * @see #getCompressionMode */ protected int compressionMode = MODE_COPY_FROM_METADATA; /** * An array of <code>String</code>s containing the names of the * available compression types. Subclasses must set the value * manually. * * <p> Subclasses that do not support compression may ignore this * value. */ protected String[] compressionTypes = null; /** * A <code>String</code> containing the name of the current * compression type, or <code>null</code> if none is set. * * <p> Subclasses that do not support compression may ignore this * value. */ protected String compressionType = null; /** * A <code>float</code> containing the current compression quality * setting. The initial value is <code>1.0F</code>. * * <p> Subclasses that do not support compression may ignore this * value. */ protected float compressionQuality = 1.0F; /** * A <code>Locale</code> to be used to localize compression type * names and quality descriptions, or <code>null</code> to use a * default <code>Locale</code>. Subclasses must set the value * manually. */ protected Locale locale = null; /** * Constructs an empty <code>ImageWriteParam</code>. It is up to * the subclass to set up the instance variables properly. */ protected ImageWriteParam() {} /** * Constructs an <code>ImageWriteParam</code> set to use a * given <code>Locale</code>. * * @param locale a <code>Locale</code> to be used to localize * compression type names and quality descriptions, or * <code>null</code>. */ public ImageWriteParam(Locale locale) { this.locale = locale; } // Return a deep copy of the array private static Dimension[] clonePreferredTileSizes(Dimension[] sizes) { if (sizes == null) { return null; } Dimension[] temp = new Dimension[sizes.length]; for (int i = 0; i < sizes.length; i++) { temp[i] = new Dimension(sizes[i]); } return temp; } /** * Returns the currently set <code>Locale</code>, or * <code>null</code> if only a default <code>Locale</code> is * supported. * * @return the current <code>Locale</code>, or <code>null</code>. */ public Locale getLocale() { return locale; } /** * Returns <code>true</code> if the writer can perform tiling * while writing. If this method returns <code>false</code>, then * <code>setTiling</code> will throw an * <code>UnsupportedOperationException</code>. * * @return <code>true</code> if the writer supports tiling. * * @see #canOffsetTiles() * @see #setTiling(int, int, int, int) */ public boolean canWriteTiles() { return canWriteTiles; } /** * Returns <code>true</code> if the writer can perform tiling with * non-zero grid offsets while writing. If this method returns * <code>false</code>, then <code>setTiling</code> will throw an * <code>UnsupportedOperationException</code> if the grid offset * arguments are not both zero. If <code>canWriteTiles</code> * returns <code>false</code>, this method will return * <code>false</code> as well. * * @return <code>true</code> if the writer supports non-zero tile * offsets. * * @see #canWriteTiles() * @see #setTiling(int, int, int, int) */ public boolean canOffsetTiles() { return canOffsetTiles; } /** * Determines whether the image will be tiled in the output * stream and, if it will, how the tiling parameters will be * determined. The modes are interpreted as follows: * * <ul> * * <li><code>MODE_DISABLED</code> - The image will not be tiled. * <code>setTiling</code> will throw an * <code>IllegalStateException</code>. * * <li><code>MODE_DEFAULT</code> - The image will be tiled using * default parameters. <code>setTiling</code> will throw an * <code>IllegalStateException</code>. * * <li><code>MODE_EXPLICIT</code> - The image will be tiled * according to parameters given in the {@link #setTiling * <code>setTiling</code>} method. Any previously set tiling * parameters are discarded. * * <li><code>MODE_COPY_FROM_METADATA</code> - The image will * conform to the metadata object passed in to a write. * <code>setTiling</code> will throw an * <code>IllegalStateException</code>. * * </ul> * * @param mode The mode to use for tiling. * * @exception UnsupportedOperationException if * <code>canWriteTiles</code> returns <code>false</code>. * @exception IllegalArgumentException if <code>mode</code> is not * one of the modes listed above. * * @see #setTiling * @see #getTilingMode */ public void setTilingMode(int mode) { if (canWriteTiles() == false) { throw new UnsupportedOperationException("Tiling not supported!"); } if (mode < MODE_DISABLED || mode > MAX_MODE) { throw new IllegalArgumentException("Illegal value for mode!"); } this.tilingMode = mode; if (mode == MODE_EXPLICIT) { unsetTiling(); } } /** * Returns the current tiling mode, if tiling is supported.Lines 1–500 of 1471. Load more
/* * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.imageio; import java.awt.Dimension; import java.util.Locale; /** * A class describing how a stream is to be encoded. Instances of * this class or its subclasses are used to supply prescriptive * "how-to" information to instances of <code>ImageWriter</code>. * * <p> A plug-in for a specific image format may define a subclass of * this class, and return objects of that class from the * <code>getDefaultWriteParam</code> method of its * <code>ImageWriter</code> implementation. For example, the built-in * JPEG writer plug-in will return instances of * <code>javax.imageio.plugins.jpeg.JPEGImageWriteParam</code>. * * <p> The region of the image to be written is determined by first * intersecting the actual bounds of the image with the rectangle * specified by <code>IIOParam.setSourceRegion</code>, if any. If the * resulting rectangle has a width or height of zero, the writer will * throw an <code>IIOException</code>. If the intersection is * non-empty, writing will commence with the first subsampled pixel * and include additional pixels within the intersected bounds * according to the horizontal and vertical subsampling factors * specified by {@link IIOParam#setSourceSubsampling * <code>IIOParam.setSourceSubsampling</code>}. * * <p> Individual features such as tiling, progressive encoding, and * compression may be set in one of four modes. * <code>MODE_DISABLED</code> disables the features; * <code>MODE_DEFAULT</code> enables the feature with * writer-controlled parameter values; <code>MODE_EXPLICIT</code> * enables the feature and allows the use of a <code>set</code> method * to provide additional parameters; and * <code>MODE_COPY_FROM_METADATA</code> copies relevant parameter * values from the stream and image metadata objects passed to the * writer. The default for all features is * <code>MODE_COPY_FROM_METADATA</code>. Non-standard features * supplied in subclasses are encouraged, but not required to use a * similar scheme. * * <p> Plug-in writers may extend the functionality of * <code>ImageWriteParam</code> by providing a subclass that implements * additional, plug-in specific interfaces. It is up to the plug-in * to document what interfaces are available and how they are to be * used. Writers will silently ignore any extended features of an * <code>ImageWriteParam</code> subclass of which they are not aware. * Also, they may ignore any optional features that they normally * disable when creating their own <code>ImageWriteParam</code> * instances via <code>getDefaultWriteParam</code>. * * <p> Note that unless a query method exists for a capability, it must * be supported by all <code>ImageWriter</code> implementations * (<i>e.g.</i> progressive encoding is optional, but subsampling must be * supported). * * * @see ImageReadParam */ public class ImageWriteParam extends IIOParam { /** * A constant value that may be passed into methods such as * <code>setTilingMode</code>, <code>setProgressiveMode</code>, * and <code>setCompressionMode</code> to disable a feature for * future writes. That is, when this mode is set the stream will * <b>not</b> be tiled, progressive, or compressed, and the * relevant accessor methods will throw an * <code>IllegalStateException</code>. * * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setProgressiveMode * @see #getProgressiveMode * @see #setTilingMode * @see #getTilingMode * @see #setCompressionMode * @see #getCompressionMode */ public static final int MODE_DISABLED = 0; /** * A constant value that may be passed into methods such as * <code>setTilingMode</code>, * <code>setProgressiveMode</code>, and * <code>setCompressionMode</code> to enable that feature for * future writes. That is, when this mode is enabled the stream * will be tiled, progressive, or compressed according to a * sensible default chosen internally by the writer in a plug-in * dependent way, and the relevant accessor methods will * throw an <code>IllegalStateException</code>. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #setProgressiveMode * @see #getProgressiveMode * @see #setTilingMode * @see #getTilingMode * @see #setCompressionMode * @see #getCompressionMode */ public static final int MODE_DEFAULT = 1; /** * A constant value that may be passed into methods such as * <code>setTilingMode</code> or <code>setCompressionMode</code> * to enable a feature for future writes. That is, when this mode * is set the stream will be tiled or compressed according to * additional information supplied to the corresponding * <code>set</code> methods in this class and retrievable from the * corresponding <code>get</code> methods. Note that this mode is * not supported for progressive output. * * @see #MODE_DISABLED * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setProgressiveMode * @see #getProgressiveMode * @see #setTilingMode * @see #getTilingMode * @see #setCompressionMode * @see #getCompressionMode */ public static final int MODE_EXPLICIT = 2; /** * A constant value that may be passed into methods such as * <code>setTilingMode</code>, <code>setProgressiveMode</code>, or * <code>setCompressionMode</code> to enable that feature for * future writes. That is, when this mode is enabled the stream * will be tiled, progressive, or compressed based on the contents * of stream and/or image metadata passed into the write * operation, and any relevant accessor methods will throw an * <code>IllegalStateException</code>. * * <p> This is the default mode for all features, so that a read * including metadata followed by a write including metadata will * preserve as much information as possible. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_DEFAULT * @see #setProgressiveMode * @see #getProgressiveMode * @see #setTilingMode * @see #getTilingMode * @see #setCompressionMode * @see #getCompressionMode */ public static final int MODE_COPY_FROM_METADATA = 3; // If more modes are added, this should be updated. private static final int MAX_MODE = MODE_COPY_FROM_METADATA; /** * A <code>boolean</code> that is <code>true</code> if this * <code>ImageWriteParam</code> allows tile width and tile height * parameters to be set. By default, the value is * <code>false</code>. Subclasses must set the value manually. * * <p> Subclasses that do not support writing tiles should ensure * that this value is set to <code>false</code>. */ protected boolean canWriteTiles = false; /** * The mode controlling tiling settings, which Must be * set to one of the four <code>MODE_*</code> values. The default * is <code>MODE_COPY_FROM_METADATA</code>. * * <p> Subclasses that do not writing tiles may ignore this value. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setTilingMode * @see #getTilingMode */ protected int tilingMode = MODE_COPY_FROM_METADATA; /** * An array of preferred tile size range pairs. The default value * is <code>null</code>, which indicates that there are no * preferred sizes. If the value is non-<code>null</code>, it * must have an even length of at least two. * * <p> Subclasses that do not support writing tiles may ignore * this value. * * @see #getPreferredTileSizes */ protected Dimension[] preferredTileSizes = null; /** * A <code>boolean</code> that is <code>true</code> if tiling * parameters have been specified. * * <p> Subclasses that do not support writing tiles may ignore * this value. */ protected boolean tilingSet = false; /** * The width of each tile if tiling has been set, or 0 otherwise. * * <p> Subclasses that do not support tiling may ignore this * value. */ protected int tileWidth = 0; /** * The height of each tile if tiling has been set, or 0 otherwise. * The initial value is <code>0</code>. * * <p> Subclasses that do not support tiling may ignore this * value. */ protected int tileHeight = 0; /** * A <code>boolean</code> that is <code>true</code> if this * <code>ImageWriteParam</code> allows tiling grid offset * parameters to be set. By default, the value is * <code>false</code>. Subclasses must set the value manually. * * <p> Subclasses that do not support writing tiles, or that * supprt writing but not offsetting tiles must ensure that this * value is set to <code>false</code>. */ protected boolean canOffsetTiles = false; /** * The amount by which the tile grid origin should be offset * horizontally from the image origin if tiling has been set, * or 0 otherwise. The initial value is <code>0</code>. * * <p> Subclasses that do not support offsetting tiles may ignore * this value. */ protected int tileGridXOffset = 0; /** * The amount by which the tile grid origin should be offset * vertically from the image origin if tiling has been set, * or 0 otherwise. The initial value is <code>0</code>. * * <p> Subclasses that do not support offsetting tiles may ignore * this value. */ protected int tileGridYOffset = 0; /** * A <code>boolean</code> that is <code>true</code> if this * <code>ImageWriteParam</code> allows images to be written as a * progressive sequence of increasing quality passes. By default, * the value is <code>false</code>. Subclasses must set the value * manually. * * <p> Subclasses that do not support progressive encoding must * ensure that this value is set to <code>false</code>. */ protected boolean canWriteProgressive = false; /** * The mode controlling progressive encoding, which must be set to * one of the four <code>MODE_*</code> values, except * <code>MODE_EXPLICIT</code>. The default is * <code>MODE_COPY_FROM_METADATA</code>. * * <p> Subclasses that do not support progressive encoding may * ignore this value. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setProgressiveMode * @see #getProgressiveMode */ protected int progressiveMode = MODE_COPY_FROM_METADATA; /** * A <code>boolean</code> that is <code>true</code> if this writer * can write images using compression. By default, the value is * <code>false</code>. Subclasses must set the value manually. * * <p> Subclasses that do not support compression must ensure that * this value is set to <code>false</code>. */ protected boolean canWriteCompressed = false; /** * The mode controlling compression settings, which must be set to * one of the four <code>MODE_*</code> values. The default is * <code>MODE_COPY_FROM_METADATA</code>. * * <p> Subclasses that do not support compression may ignore this * value. * * @see #MODE_DISABLED * @see #MODE_EXPLICIT * @see #MODE_COPY_FROM_METADATA * @see #MODE_DEFAULT * @see #setCompressionMode * @see #getCompressionMode */ protected int compressionMode = MODE_COPY_FROM_METADATA; /** * An array of <code>String</code>s containing the names of the * available compression types. Subclasses must set the value * manually. * * <p> Subclasses that do not support compression may ignore this * value. */ protected String[] compressionTypes = null; /** * A <code>String</code> containing the name of the current * compression type, or <code>null</code> if none is set. * * <p> Subclasses that do not support compression may ignore this * value. */ protected String compressionType = null; /** * A <code>float</code> containing the current compression quality * setting. The initial value is <code>1.0F</code>. * * <p> Subclasses that do not support compression may ignore this * value. */ protected float compressionQuality = 1.0F; /** * A <code>Locale</code> to be used to localize compression type * names and quality descriptions, or <code>null</code> to use a * default <code>Locale</code>. Subclasses must set the value * manually. */ protected Locale locale = null; /** * Constructs an empty <code>ImageWriteParam</code>. It is up to * the subclass to set up the instance variables properly. */ protected ImageWriteParam() {} /** * Constructs an <code>ImageWriteParam</code> set to use a * given <code>Locale</code>. * * @param locale a <code>Locale</code> to be used to localize * compression type names and quality descriptions, or * <code>null</code>. */ public ImageWriteParam(Locale locale) { this.locale = locale; } // Return a deep copy of the array private static Dimension[] clonePreferredTileSizes(Dimension[] sizes) { if (sizes == null) { return null; } Dimension[] temp = new Dimension[sizes.length]; for (int i = 0; i < sizes.length; i++) { temp[i] = new Dimension(sizes[i]); } return temp; } /** * Returns the currently set <code>Locale</code>, or * <code>null</code> if only a default <code>Locale</code> is * supported. * * @return the current <code>Locale</code>, or <code>null</code>. */ public Locale getLocale() { return locale; } /** * Returns <code>true</code> if the writer can perform tiling * while writing. If this method returns <code>false</code>, then * <code>setTiling</code> will throw an * <code>UnsupportedOperationException</code>. * * @return <code>true</code> if the writer supports tiling. * * @see #canOffsetTiles() * @see #setTiling(int, int, int, int) */ public boolean canWriteTiles() { return canWriteTiles; } /** * Returns <code>true</code> if the writer can perform tiling with * non-zero grid offsets while writing. If this method returns * <code>false</code>, then <code>setTiling</code> will throw an * <code>UnsupportedOperationException</code> if the grid offset * arguments are not both zero. If <code>canWriteTiles</code> * returns <code>false</code>, this method will return * <code>false</code> as well. * * @return <code>true</code> if the writer supports non-zero tile * offsets. * * @see #canWriteTiles() * @see #setTiling(int, int, int, int) */ public boolean canOffsetTiles() { return canOffsetTiles; } /** * Determines whether the image will be tiled in the output * stream and, if it will, how the tiling parameters will be * determined. The modes are interpreted as follows: * * <ul> * * <li><code>MODE_DISABLED</code> - The image will not be tiled. * <code>setTiling</code> will throw an * <code>IllegalStateException</code>. * * <li><code>MODE_DEFAULT</code> - The image will be tiled using * default parameters. <code>setTiling</code> will throw an * <code>IllegalStateException</code>. * * <li><code>MODE_EXPLICIT</code> - The image will be tiled * according to parameters given in the {@link #setTiling * <code>setTiling</code>} method. Any previously set tiling * parameters are discarded. * * <li><code>MODE_COPY_FROM_METADATA</code> - The image will * conform to the metadata object passed in to a write. * <code>setTiling</code> will throw an * <code>IllegalStateException</code>. * * </ul> * * @param mode The mode to use for tiling. * * @exception UnsupportedOperationException if * <code>canWriteTiles</code> returns <code>false</code>. * @exception IllegalArgumentException if <code>mode</code> is not * one of the modes listed above. * * @see #setTiling * @see #getTilingMode */ public void setTilingMode(int mode) { if (canWriteTiles() == false) { throw new UnsupportedOperationException("Tiling not supported!"); } if (mode < MODE_DISABLED || mode > MAX_MODE) { throw new IllegalArgumentException("Illegal value for mode!"); } this.tilingMode = mode; if (mode == MODE_EXPLICIT) { unsetTiling(); } } /** * Returns the current tiling mode, if tiling is supported.