1471 lines · 55.9 KB · Java
RawDownload
     * Otherwise throws an <code>UnsupportedOperationException</code>.     *     * @return the current tiling mode.     *     * @exception UnsupportedOperationException if     * <code>canWriteTiles</code> returns <code>false</code>.     *     * @see #setTilingMode     */    public int getTilingMode() {        if (!canWriteTiles()) {            throw new UnsupportedOperationException("Tiling not supported");        }        return tilingMode;    }     /**     * Returns an array of <code>Dimension</code>s indicating the     * legal size ranges for tiles as they will be encoded in the     * output file or stream.  The returned array is a copy.     *     * <p> The information is returned as a set of pairs; the first     * element of a pair contains an (inclusive) minimum width and     * height, and the second element contains an (inclusive) maximum     * width and height.  Together, each pair defines a valid range of     * sizes.  To specify a fixed size, use the same width and height     * for both elements.  To specify an arbitrary range, a value of     * <code>null</code> is used in place of an actual array of     * <code>Dimension</code>s.     *     * <p> If no array is specified on the constructor, but tiling is     * allowed, then this method returns <code>null</code>.     *     * @exception UnsupportedOperationException if the plug-in does     * not support tiling.     *     * @return an array of <code>Dimension</code>s with an even length     * of at least two, or <code>null</code>.     */    public Dimension[] getPreferredTileSizes() {        if (!canWriteTiles()) {            throw new UnsupportedOperationException("Tiling not supported");        }        return clonePreferredTileSizes(preferredTileSizes);    }     /**     * Specifies that the image should be tiled in the output stream.     * The <code>tileWidth</code> and <code>tileHeight</code>     * parameters specify the width and height of the tiles in the     * file.  If the tile width or height is greater than the width or     * height of the image, the image is not tiled in that dimension.     *     * <p> If <code>canOffsetTiles</code> returns <code>false</code>,     * then the <code>tileGridXOffset</code> and     * <code>tileGridYOffset</code> parameters must be zero.     *     * @param tileWidth the width of each tile.     * @param tileHeight the height of each tile.     * @param tileGridXOffset the horizontal offset of the tile grid.     * @param tileGridYOffset the vertical offset of the tile grid.     *     * @exception UnsupportedOperationException if the plug-in does not     * support tiling.     * @exception IllegalStateException if the tiling mode is not     * <code>MODE_EXPLICIT</code>.     * @exception UnsupportedOperationException if the plug-in does not     * support grid offsets, and the grid offsets are not both zero.     * @exception IllegalArgumentException if the tile size is not     * within one of the allowable ranges returned by     * <code>getPreferredTileSizes</code>.     * @exception IllegalArgumentException if <code>tileWidth</code>     * or <code>tileHeight</code> is less than or equal to 0.     *     * @see #canWriteTiles     * @see #canOffsetTiles     * @see #getTileWidth()     * @see #getTileHeight()     * @see #getTileGridXOffset()     * @see #getTileGridYOffset()     */    public void setTiling(int tileWidth,                          int tileHeight,                          int tileGridXOffset,                          int tileGridYOffset) {        if (!canWriteTiles()) {            throw new UnsupportedOperationException("Tiling not supported!");        }        if (getTilingMode() != MODE_EXPLICIT) {            throw new IllegalStateException("Tiling mode not MODE_EXPLICIT!");        }        if (tileWidth <= 0 || tileHeight <= 0) {            throw new IllegalArgumentException                ("tile dimensions are non-positive!");        }        boolean tilesOffset = (tileGridXOffset != 0) || (tileGridYOffset != 0);        if (!canOffsetTiles() && tilesOffset) {            throw new UnsupportedOperationException("Can't offset tiles!");        }        if (preferredTileSizes != null) {            boolean ok = true;            for (int i = 0; i < preferredTileSizes.length; i += 2) {                Dimension min = preferredTileSizes[i];                Dimension max = preferredTileSizes[i+1];                if ((tileWidth < min.width) ||                    (tileWidth > max.width) ||                    (tileHeight < min.height) ||                    (tileHeight > max.height)) {                    ok = false;                    break;                }            }            if (!ok) {                throw new IllegalArgumentException("Illegal tile size!");            }        }         this.tilingSet = true;        this.tileWidth = tileWidth;        this.tileHeight = tileHeight;        this.tileGridXOffset = tileGridXOffset;        this.tileGridYOffset = tileGridYOffset;    }     /**     * Removes any previous tile grid parameters specified by calls to     * <code>setTiling</code>.     *     * <p> The default implementation sets the instance variables     * <code>tileWidth</code>, <code>tileHeight</code>,     * <code>tileGridXOffset</code>, and     * <code>tileGridYOffset</code> to <code>0</code>.     *     * @exception UnsupportedOperationException if the plug-in does not     * support tiling.     * @exception IllegalStateException if the tiling mode is not     * <code>MODE_EXPLICIT</code>.     *     * @see #setTiling(int, int, int, int)     */    public void unsetTiling() {        if (!canWriteTiles()) {            throw new UnsupportedOperationException("Tiling not supported!");        }        if (getTilingMode() != MODE_EXPLICIT) {            throw new IllegalStateException("Tiling mode not MODE_EXPLICIT!");        }        this.tilingSet = false;        this.tileWidth = 0;        this.tileHeight = 0;        this.tileGridXOffset = 0;        this.tileGridYOffset = 0;    }     /**     * Returns the width of each tile in an image as it will be     * written to the output stream.  If tiling parameters have not     * been set, an <code>IllegalStateException</code> is thrown.     *     * @return the tile width to be used for encoding.     *     * @exception UnsupportedOperationException if the plug-in does not     * support tiling.     * @exception IllegalStateException if the tiling mode is not     * <code>MODE_EXPLICIT</code>.     * @exception IllegalStateException if the tiling parameters have     * not been set.     *     * @see #setTiling(int, int, int, int)     * @see #getTileHeight()     */    public int getTileWidth() {        if (!canWriteTiles()) {            throw new UnsupportedOperationException("Tiling not supported!");        }        if (getTilingMode() != MODE_EXPLICIT) {            throw new IllegalStateException("Tiling mode not MODE_EXPLICIT!");        }        if (!tilingSet) {            throw new IllegalStateException("Tiling parameters not set!");        }        return tileWidth;    }     /**     * Returns the height of each tile in an image as it will be written to     * the output stream.  If tiling parameters have not     * been set, an <code>IllegalStateException</code> is thrown.     *     * @return the tile height to be used for encoding.     *     * @exception UnsupportedOperationException if the plug-in does not     * support tiling.     * @exception IllegalStateException if the tiling mode is not     * <code>MODE_EXPLICIT</code>.     * @exception IllegalStateException if the tiling parameters have     * not been set.     *     * @see #setTiling(int, int, int, int)     * @see #getTileWidth()     */    public int getTileHeight() {        if (!canWriteTiles()) {            throw new UnsupportedOperationException("Tiling not supported!");        }        if (getTilingMode() != MODE_EXPLICIT) {            throw new IllegalStateException("Tiling mode not MODE_EXPLICIT!");        }        if (!tilingSet) {            throw new IllegalStateException("Tiling parameters not set!");        }        return tileHeight;    }     /**     * Returns the horizontal tile grid offset of an image as it will     * be written to the output stream.  If tiling parameters have not     * been set, an <code>IllegalStateException</code> is thrown.     *     * @return the tile grid X offset to be used for encoding.     *     * @exception UnsupportedOperationException if the plug-in does not     * support tiling.     * @exception IllegalStateException if the tiling mode is not     * <code>MODE_EXPLICIT</code>.     * @exception IllegalStateException if the tiling parameters have     * not been set.     *     * @see #setTiling(int, int, int, int)     * @see #getTileGridYOffset()     */    public int getTileGridXOffset() {        if (!canWriteTiles()) {            throw new UnsupportedOperationException("Tiling not supported!");        }        if (getTilingMode() != MODE_EXPLICIT) {            throw new IllegalStateException("Tiling mode not MODE_EXPLICIT!");        }        if (!tilingSet) {            throw new IllegalStateException("Tiling parameters not set!");        }        return tileGridXOffset;    }     /**     * Returns the vertical tile grid offset of an image as it will     * be written to the output stream.  If tiling parameters have not     * been set, an <code>IllegalStateException</code> is thrown.     *     * @return the tile grid Y offset to be used for encoding.     *     * @exception UnsupportedOperationException if the plug-in does not     * support tiling.     * @exception IllegalStateException if the tiling mode is not     * <code>MODE_EXPLICIT</code>.     * @exception IllegalStateException if the tiling parameters have     * not been set.     *     * @see #setTiling(int, int, int, int)     * @see #getTileGridXOffset()     */    public int getTileGridYOffset() {        if (!canWriteTiles()) {            throw new UnsupportedOperationException("Tiling not supported!");        }        if (getTilingMode() != MODE_EXPLICIT) {            throw new IllegalStateException("Tiling mode not MODE_EXPLICIT!");        }        if (!tilingSet) {            throw new IllegalStateException("Tiling parameters not set!");        }        return tileGridYOffset;    }     /**     * Returns <code>true</code> if the writer can write out images     * as a series of passes of progressively increasing quality.     *     * @return <code>true</code> if the writer supports progressive     * encoding.     *     * @see #setProgressiveMode     * @see #getProgressiveMode     */    public boolean canWriteProgressive() {        return canWriteProgressive;    }     /**     * Specifies that the writer is to write the image out in a     * progressive mode such that the stream will contain a series of     * scans of increasing quality.  If progressive encoding is not     * supported, an <code>UnsupportedOperationException</code> will     * be thrown.     *     * <p>  The mode argument determines how     * the progression parameters are chosen, and must be either     * <code>MODE_DISABLED</code>,     * <code>MODE_COPY_FROM_METADATA</code>, or     * <code>MODE_DEFAULT</code>.  Otherwise an     * <code>IllegalArgumentException</code> is thrown.     *     * <p> The modes are interpreted as follows:     *     * <ul>     *   <li><code>MODE_DISABLED</code> - No progression.  Use this to     *   turn off progession.     *     *   <li><code>MODE_COPY_FROM_METADATA</code> - The output image     *   will use whatever progression parameters are found in the     *   metadata objects passed into the writer.     *     *   <li><code>MODE_DEFAULT</code> - The image will be written     *   progressively, with parameters chosen by the writer.     * </ul>     *     * <p> The default is <code>MODE_COPY_FROM_METADATA</code>.     *     * @param mode The mode for setting progression in the output     * stream.     *     * @exception UnsupportedOperationException if the writer does not     * support progressive encoding.     * @exception IllegalArgumentException if <code>mode</code> is not     * one of the modes listed above.     *     * @see #getProgressiveMode     */    public void setProgressiveMode(int mode) {        if (!canWriteProgressive()) {            throw new UnsupportedOperationException(                "Progressive output not supported");        }        if (mode < MODE_DISABLED || mode > MAX_MODE) {            throw new IllegalArgumentException("Illegal value for mode!");        }        if (mode == MODE_EXPLICIT) {            throw new IllegalArgumentException(                "MODE_EXPLICIT not supported for progressive output");        }        this.progressiveMode = mode;    }     /**     * Returns the current mode for writing the stream in a     * progressive manner.     *     * @return the current mode for progressive encoding.     *     * @exception UnsupportedOperationException if the writer does not     * support progressive encoding.     *     * @see #setProgressiveMode     */    public int getProgressiveMode() {        if (!canWriteProgressive()) {            throw new UnsupportedOperationException                ("Progressive output not supported");        }        return progressiveMode;    }     /**     * Returns <code>true</code> if this writer supports compression.     *     * @return <code>true</code> if the writer supports compression.     */    public boolean canWriteCompressed() {        return canWriteCompressed;    }     /**     * Specifies whether compression is to be performed, and if so how     * compression parameters are to be determined.  The <code>mode</code>     * argument must be one of the four modes, interpreted as follows:     *     * <ul>     *   <li><code>MODE_DISABLED</code> - If the mode is set to     *   <code>MODE_DISABLED</code>, methods that query or modify the     *   compression type or parameters will throw an     *   <code>IllegalStateException</code> (if compression is     *   normally supported by the plug-in). Some writers, such as JPEG,     *   do not normally offer uncompressed output. In this case, attempting     *   to set the mode to <code>MODE_DISABLED</code> will throw an     *   <code>UnsupportedOperationException</code> and the mode will not be     *   changed.     *     *   <li><code>MODE_EXPLICIT</code> - Compress using the     *   compression type and quality settings specified in this     *   <code>ImageWriteParam</code>.  Any previously set compression     *   parameters are discarded.     *     *   <li><code>MODE_COPY_FROM_METADATA</code> - Use whatever     *   compression parameters are specified in metadata objects     *   passed in to the writer.     *     *   <li><code>MODE_DEFAULT</code> - Use default compression     *   parameters.     * </ul>     *     * <p> The default is <code>MODE_COPY_FROM_METADATA</code>.     *     * @param mode The mode for setting compression in the output     * stream.     *     * @exception UnsupportedOperationException if the writer does not     * support compression, or does not support the requested mode.     * @exception IllegalArgumentException if <code>mode</code> is not     * one of the modes listed above.     *     * @see #getCompressionMode     */    public void setCompressionMode(int mode) {        if (!canWriteCompressed()) {            throw new UnsupportedOperationException(                "Compression not supported.");        }        if (mode < MODE_DISABLED || mode > MAX_MODE) {            throw new IllegalArgumentException("Illegal value for mode!");        }        this.compressionMode = mode;        if (mode == MODE_EXPLICIT) {            unsetCompression();        }    }     /**     * Returns the current compression mode, if compression is     * supported.     *     * @return the current compression mode.     *     * @exception UnsupportedOperationException if the writer does not     * support compression.     *     * @see #setCompressionMode     */    public int getCompressionMode() {        if (!canWriteCompressed()) {            throw new UnsupportedOperationException(                "Compression not supported.");        }        return compressionMode;    }     /**     * Returns a list of available compression types, as an array or     * <code>String</code>s, or <code>null</code> if a compression     * type may not be chosen using these interfaces.  The array     * returned is a copy.     *     * <p> If the writer only offers a single, mandatory form of     * compression, it is not necessary to provide any named     * compression types.  Named compression types should only be     * used where the user is able to make a meaningful choice     * between different schemes.     *     * <p> The default implementation checks if compression is     * supported and throws an     * <code>UnsupportedOperationException</code> if not.  Otherwise,     * it returns a clone of the <code>compressionTypes</code>     * instance variable if it is non-<code>null</code>, or else     * returns <code>null</code>.     *     * @return an array of <code>String</code>s containing the     * (non-localized) names of available compression types, or     * <code>null</code>.     *     * @exception UnsupportedOperationException if the writer does not     * support compression.     */    public String[] getCompressionTypes() {        if (!canWriteCompressed()) {            throw new UnsupportedOperationException(                "Compression not supported");        }        if (compressionTypes == null) {            return null;        }        return (String[])compressionTypes.clone();    }     /**     * Sets the compression type to one of the values indicated by     * <code>getCompressionTypes</code>.  If a value of     * <code>null</code> is passed in, any previous setting is     * removed.     *     * <p> The default implementation checks whether compression is     * supported and the compression mode is     * <code>MODE_EXPLICIT</code>.  If so, it calls     * <code>getCompressionTypes</code> and checks if     * <code>compressionType</code> is one of the legal values.  If it     * is, the <code>compressionType</code> instance variable is set.     * If <code>compressionType</code> is <code>null</code>, the     * instance variable is set without performing any checking.     *     * @param compressionType one of the <code>String</code>s returned     * by <code>getCompressionTypes</code>, or <code>null</code> to     * remove any previous setting.

Lines 501–1000 of 1471. Previous lines