FileDocCategorySizeDatePackage
ImageWriteParam.javaAPI DocAndroid 1.5 API18588Wed May 06 22:41:54 BST 2009javax.imageio

ImageWriteParam

public class ImageWriteParam extends IIOParam
The ImageWriteParam class provides information to an ImageWriter about how an image is to be encoded.
since
Android 1.0

Fields Summary
public static final int
MODE_DISABLED
The Constant MODE_DISABLED indicates that stream is not tiled, progressive, or compressed.
public static final int
MODE_DEFAULT
The Constant MODE_DEFAULT indicates that the stream will be tiled, progressive, or compressed according to the plug-in's default.
public static final int
MODE_EXPLICIT
The Constant MODE_EXPLICIT indicates that the stream will be tiled, progressive, or compressed according to current settings which are defined by set methods.
public static final int
MODE_COPY_FROM_METADATA
The Constant MODE_COPY_FROM_METADATA indicates that the stream will be tiled, progressive, or compressed according to stream or image metadata.
protected boolean
canWriteTiles
Whether the ImageWriter can write tiles.
protected int
tilingMode
The tiling mode.
protected Dimension[]
preferredTileSizes
The preferred tile sizes.
protected boolean
tilingSet
The tiling set.
protected int
tileWidth
The tile width.
protected int
tileHeight
The tile height.
protected boolean
canOffsetTiles
Whether the ImageWriter can offset tiles.
protected int
tileGridXOffset
The tile grid x offset.
protected int
tileGridYOffset
The tile grid y offset.
protected boolean
canWriteProgressive
Whether the ImageWriter can write in progressive mode.
protected int
progressiveMode
The progressive mode.
protected boolean
canWriteCompressed
Whether the ImageWriter can write in compressed mode.
protected int
compressionMode
The compression mode.
protected String[]
compressionTypes
The compression types.
protected String
compressionType
The compression type.
protected float
compressionQuality
The compression quality.
protected Locale
locale
The locale.
Constructors Summary
protected ImageWriteParam()
Instantiates a new ImageWriteParam.


             
      
    
public ImageWriteParam(Locale locale)
Instantiates a new ImageWriteParam with the specified Locale.

param
locale the Locale.

        this.locale = locale;

    
Methods Summary
public booleancanOffsetTiles()
Returns true if the writer can use tiles with non zero grid offsets while writing.

return
true, if the writer can use tiles with non zero grid offsets while writing, false otherwise.

        return canOffsetTiles;
    
public booleancanWriteCompressed()
Returns true if this writer can write images with compression.

return
true, if this writer can write images with compression, false otherwise.

        return canWriteCompressed;
    
public booleancanWriteProgressive()
Returns true if images can be written using increasing quality passes by progressive.

return
true if images can be written using increasing quality passes by progressive, false otherwise.

        return canWriteProgressive;
    
public booleancanWriteTiles()
Returns true if the writer can write tiles.

return
true, if the writer can write tiles, false otherwise.

        return canWriteTiles;
    
private final voidcheckCompressionMode()
Check compression mode.

        if (getCompressionMode() != MODE_EXPLICIT) {
            throw new IllegalStateException("Compression mode not MODE_EXPLICIT!");
        }
    
private final voidcheckCompressionType()
Check compression type.

        if (getCompressionTypes() != null && getCompressionType() == null) {
            throw new IllegalStateException("No compression type set!");
        }
    
private final voidcheckTiling()
Check tiling.

        if (!canWriteTiles()) {
            throw new UnsupportedOperationException("Tiling not supported!");
        }
    
private final voidcheckTilingMode()
Check tiling mode.

        if (getTilingMode() != MODE_EXPLICIT) {
            throw new IllegalStateException("Tiling mode not MODE_EXPLICIT!");
        }
    
private final voidcheckTilingParams()
Check tiling params.

        if (!tilingSet) {
            throw new IllegalStateException("Tiling parameters not set!");
        }
    
private final voidcheckWriteCompressed()
Check write compressed.

        if (!canWriteCompressed()) {
            throw new UnsupportedOperationException("Compression not supported.");
        }
    
public floatgetBitRate(float quality)
Gets a bit rate which represents an estimate of the number of bits of output data for each bit of input image data with the specified quality.

param
quality the quality.
return
an estimate of the bit rate, or -1.0F if there is no estimate.

        checkWriteCompressed();
        checkCompressionMode();
        checkCompressionType();
        if (quality < 0 || quality > 1) {
            throw new IllegalArgumentException("Quality out-of-bounds!");
        }
        return -1.0f;
    
public intgetCompressionMode()
Gets the compression mode.

return
the compression mode if it's supported.

        checkWriteCompressed();
        return compressionMode;
    
public floatgetCompressionQuality()
Gets the compression quality.

return
the compression quality.

        checkWriteCompressed();
        checkCompressionMode();
        checkCompressionType();
        return compressionQuality;
    
public java.lang.String[]getCompressionQualityDescriptions()
Gets the array of compression quality descriptions.

return
the string array of compression quality descriptions.

        checkWriteCompressed();
        checkCompressionMode();
        checkCompressionType();
        return null;
    
public float[]getCompressionQualityValues()
Gets an array of floats which describes compression quality levels.

return
the array of compression quality values.

        checkWriteCompressed();
        checkCompressionMode();
        checkCompressionType();
        return null;
    
public java.lang.StringgetCompressionType()
Gets the current compression type, or returns null.

return
the current compression type, or returns null if it is not set.

        checkWriteCompressed();
        checkCompressionMode();
        return compressionType;
    
public java.lang.String[]getCompressionTypes()
Gets the an array of supported compression types.

return
the an array of supported compression types.

        checkWriteCompressed();
        if (compressionTypes != null) {
            return compressionTypes.clone();
        }
        return null;
    
public java.util.LocalegetLocale()
Gets the locale of this ImageWriteParam.

return
the locale of this ImageWriteParam.

        return locale;
    
public java.lang.StringgetLocalizedCompressionTypeName()
Gets the current compression type using the current Locale.

return
the current compression type using the current Locale.

        checkWriteCompressed();
        checkCompressionMode();

        String compressionType = getCompressionType();
        if (compressionType == null) {
            throw new IllegalStateException("No compression type set!");
        }
        return compressionType;

    
public java.awt.Dimension[]getPreferredTileSizes()
Gets an array of Dimensions giving the sizes of the tiles as they are encoded in the output file or stream.

return
the preferred tile sizes.

        checkTiling();
        if (preferredTileSizes == null) {
            return null;
        }

        Dimension[] retval = new Dimension[preferredTileSizes.length];
        for (int i = 0; i < preferredTileSizes.length; i++) {
            retval[i] = new Dimension(retval[i]);
        }
        return retval;
    
public intgetProgressiveMode()
Gets the mode for writing the stream in a progressive sequence.

return
the current progressive mode.

        if (canWriteProgressive()) {
            return progressiveMode;
        }
        throw new UnsupportedOperationException("progressive mode is not supported");
    
public intgetTileGridXOffset()
Gets the tile grid X offset for encoding.

return
the tile grid X offset for encoding.

        checkTiling();
        checkTilingMode();
        checkTilingParams();
        return tileGridXOffset;
    
public intgetTileGridYOffset()
Gets the tile grid Y offset for encoding.

return
the tile grid Y offset for encoding.

        checkTiling();
        checkTilingMode();
        checkTilingParams();
        return tileGridYOffset;
    
public intgetTileHeight()
Gets the tile height in an image as it is written to the output stream.

return
the tile height in an image as it is written to the output stream.

        checkTiling();
        checkTilingMode();
        checkTilingParams();
        return tileHeight;
    
public intgetTileWidth()
Gets the tile width in an image as it is written to the output stream.

return
the tile width in an image as it is written to the output stream.

        checkTiling();
        checkTilingMode();
        checkTilingParams();
        return tileWidth;
    
public intgetTilingMode()
Gets the tiling mode if tiling is supported.

return
the tiling mode if tiling is supported.

        checkTiling();
        return tilingMode;
    
public booleanisCompressionLossless()
Checks if the current compression type has lossless compression or not.

return
true, if the current compression type has lossless compression, false otherwise.

        checkWriteCompressed();
        checkCompressionMode();
        checkCompressionType();
        return true;
    
public voidsetCompressionMode(int mode)
Sets the compression mode to the specified value. The specified mode can be one of the predefined constants: MODE_DEFAULT, MODE_DISABLED, MODE_EXPLICIT, or MODE_COPY_FROM_METADATA.

param
mode the new compression mode to be set.

        checkWriteCompressed();
        switch (mode) {
            case MODE_EXPLICIT: {
                compressionMode = mode;
                unsetCompression();
                break;
            }
            case MODE_COPY_FROM_METADATA:
            case MODE_DISABLED:
            case MODE_DEFAULT: {
                compressionMode = mode;
                break;
            }
            default: {
                throw new IllegalArgumentException("Illegal value for mode!");
            }
        }
    
public voidsetCompressionQuality(float quality)
Sets the compression quality. The value should be between 0 and 1.

param
quality the new compression quality, float value between 0 and 1.

        checkWriteCompressed();
        checkCompressionMode();
        checkCompressionType();
        if (quality < 0 || quality > 1) {
            throw new IllegalArgumentException("Quality out-of-bounds!");
        }
        compressionQuality = quality;
    
public voidsetCompressionType(java.lang.String compressionType)
Sets the compression type. The specified string should be one of the values returned by getCompressionTypes method.

param
compressionType the new compression type.

        checkWriteCompressed();
        checkCompressionMode();

        if (compressionType == null) { // Don't check anything
            this.compressionType = null;
        } else {
            String[] compressionTypes = getCompressionTypes();
            if (compressionTypes == null) {
                throw new UnsupportedOperationException("No settable compression types");
            }

            for (int i = 0; i < compressionTypes.length; i++) {
                if (compressionTypes[i].equals(compressionType)) {
                    this.compressionType = compressionType;
                    return;
                }
            }

            // Compression type is not in the list.
            throw new IllegalArgumentException("Unknown compression type!");
        }
    
public voidsetProgressiveMode(int mode)
Sets the progressive mode which defines whether the stream contains a progressive sequence of increasing quality during writing. The progressive mode should be one of the following values: MODE_DISABLED, MODE_DEFAULT, or MODE_COPY_FROM_METADATA.

param
mode the new progressive mode.

        if (canWriteProgressive()) {
            if (mode < MODE_DISABLED || mode > MODE_COPY_FROM_METADATA || mode == MODE_EXPLICIT) {
                throw new IllegalArgumentException("mode is not supported");
            }
            this.progressiveMode = mode;
        }
        throw new UnsupportedOperationException("progressive mode is not supported");
    
public voidsetTiling(int tileWidth, int tileHeight, int tileGridXOffset, int tileGridYOffset)
Sets the instruction that tiling should be performed for the image in the output stream with the specified parameters.

param
tileWidth the tile's width.
param
tileHeight the tile's height.
param
tileGridXOffset the tile grid's x offset.
param
tileGridYOffset the tile grid's y offset.

        checkTiling();
        checkTilingMode();

        if (!canOffsetTiles() && (tileGridXOffset != 0 || tileGridYOffset != 0)) {
            throw new UnsupportedOperationException("Can't offset tiles!");
        }

        if (tileWidth <= 0 || tileHeight <= 0) {
            throw new IllegalArgumentException("tile dimensions are non-positive!");
        }

        Dimension preferredTileSizes[] = getPreferredTileSizes();
        if (preferredTileSizes != null) {
            for (int i = 0; i < preferredTileSizes.length; i += 2) {
                Dimension minSize = preferredTileSizes[i];
                Dimension maxSize = preferredTileSizes[i + 1];
                if (tileWidth < minSize.width || tileWidth > maxSize.width
                        || tileHeight < minSize.height || tileHeight > maxSize.height) {
                    throw new IllegalArgumentException("Illegal tile size!");
                }
            }
        }

        tilingSet = true;
        this.tileWidth = tileWidth;
        this.tileHeight = tileHeight;
        this.tileGridXOffset = tileGridXOffset;
        this.tileGridYOffset = tileGridYOffset;
    
public voidsetTilingMode(int mode)
Sets the tiling mode. The specified mode should be one of the following values: MODE_DISABLED, MODE_DEFAULT, MODE_EXPLICIT, or MODE_COPY_FROM_METADATA.

param
mode the new tiling mode.

        checkTiling();

        switch (mode) {
            case MODE_EXPLICIT: {
                tilingMode = mode;
                unsetTiling();
                break;
            }
            case MODE_COPY_FROM_METADATA:
            case MODE_DISABLED:
            case MODE_DEFAULT: {
                tilingMode = mode;
                break;
            }
            default: {
                throw new IllegalArgumentException("Illegal value for mode!");
            }
        }
    
public voidunsetCompression()
Removes current compression type.

        checkWriteCompressed();
        checkCompressionMode();
        compressionType = null;
        compressionQuality = 1;
    
public voidunsetTiling()
Clears all tiling settings.

        checkTiling();
        checkTilingMode();

        tilingSet = false;
        tileWidth = 0;
        tileHeight = 0;
        tileGridXOffset = 0;
        tileGridYOffset = 0;