ImageWriter
.
A plug-in for a specific image format may define a subclass of
this class, and return objects of that class from the
getDefaultWriteParam
method of its
ImageWriter
implementation. For example, the built-in
JPEG writer plug-in will return instances of
javax.imageio.plugins.jpeg.JPEGImageWriteParam
.
The region of the image to be written is determined by first
intersecting the actual bounds of the image with the rectangle
specified by IIOParam.setSourceRegion
, if any. If the
resulting rectangle has a width or height of zero, the writer will
throw an IIOException
. 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 IIOParam.setSourceSubsampling
.
Individual features such as tiling, progressive encoding, and
compression may be set in one of four modes.
MODE_DISABLED
disables the features;
MODE_DEFAULT
enables the feature with
writer-controlled parameter values; MODE_EXPLICIT
enables the feature and allows the use of a set
method
to provide additional parameters; and
MODE_COPY_FROM_METADATA
copies relevant parameter
values from the stream and image metadata objects passed to the
writer. The default for all features is
MODE_COPY_FROM_METADATA
. Non-standard features
supplied in subclasses are encouraged, but not required to use a
similar scheme.
Plug-in writers may extend the functionality of
ImageWriteParam
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
ImageWriteParam
subclass of which they are not aware.
Also, they may ignore any optional features that they normally
disable when creating their own ImageWriteParam
instances via getDefaultWriteParam
.
Note that unless a query method exists for a capability, it must
be supported by all ImageWriter
implementations
(e.g. progressive encoding is optional, but subsampling must be
supported).
ImageWriteParam
set to use a
given Locale
.setTilingMode
, setProgressiveMode
, or
setCompressionMode
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
IllegalStateException
.
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.
setTilingMode
,
setProgressiveMode
, and
setCompressionMode
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 IllegalStateException
.setTilingMode
, setProgressiveMode
,
and setCompressionMode
to disable a feature for
future writes. That is, when this mode is set the stream will
not be tiled, progressive, or compressed, and the
relevant accessor methods will throw an
IllegalStateException
.setTilingMode
or setCompressionMode
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
set
methods in this class and retrievable from the
corresponding get
methods. Note that this mode is
not supported for progressive output.IIOParamController
for
this IIOParam
object and returns the resulting
value. When this method returns true
, all values
for this IIOParam
object will be ready for the
next read or write operation. If false
is
returned, no settings in this object will have been disturbed
(i.e., the user canceled the operation).
Ordinarily, the controller will be a GUI providing a user
interface for a subclass of IIOParam
for a
particular plug-in. Controllers need not be GUIs, however.
true
if the writer can perform tiling with
non-zero grid offsets while writing. If this method returns
false
, then setTiling
will throw an
UnsupportedOperationException
if the grid offset
arguments are not both zero. If canWriteTiles
returns false
, this method will return
false
as well.true
if this writer supports compression.true
if the writer can write out images
as a series of passes of progressively increasing quality.true
if the writer can perform tiling
while writing. If this method returns false
, then
setTiling
will throw an
UnsupportedOperationException
.
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y) consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
float
indicating an estimate of the
number of bits of output data for each bit of input image data
at the given quality level. The value will typically lie
between 0
and 1
, with smaller values
indicating more compression. A special value of
-1.0F
is used to indicate that no estimate is
available.
If there are multiple compression types but none has been set,
an IllegalStateException
is thrown.
The default implementation checks that compression is
supported and the compression mode is
MODE_EXPLICIT
. If so, if
getCompressionTypes()
is null
or
getCompressionType()
is non-null
, and
quality
is within bounds, it returns
-1.0
.
If there are multiple compression types but none has been
set, an IllegalStateException
is thrown.
The default implementation checks that compression is
supported and that the compression mode is
MODE_EXPLICIT
. If so, if
getCompressionTypes()
is null
or
getCompressionType()
is non-null
, it
returns the value of the compressionQuality
instance variable.
String
s that may be used along
with getCompressionQualityValues
as part of a user
interface for setting or displaying the compression quality
level. The String
with index i
provides a description of the range of quality levels between
getCompressionQualityValues[i]
and
getCompressionQualityValues[i + 1]
. Note that the
length of the array returned from
getCompressionQualityValues
will always be one
greater than that returned from
getCompressionQualityDescriptions
.
As an example, the strings "Good", "Better", and "Best"
could be associated with the ranges [0, .33)
,
[.33, .66)
, and [.66, 1.0]
. In this
case, getCompressionQualityDescriptions
would
return { "Good", "Better", "Best" }
and
getCompressionQualityValues
would return
{ 0.0F, .33F, .66F, 1.0F }
.
If no descriptions are available, null
is
returned. If null
is returned from
getCompressionQualityValues
, this method must also
return null
.
The descriptions should be localized for the
Locale
returned by getLocale
, if it
is non-null
.
If there are multiple compression types but none has been set,
an IllegalStateException
is thrown.
The default implementation checks that compression is
supported and that the compression mode is
MODE_EXPLICIT
. If so, if
getCompressionTypes()
is null
or
getCompressionType()
is non-null
, it
returns null
.
float
s that may be used along
with getCompressionQualityDescriptions
as part of a user
interface for setting or displaying the compression quality
level. See getCompressionQualityDescriptions
for more information.
If no descriptions are available, null
is
returned. If null
is returned from
getCompressionQualityDescriptions
, this method
must also return null
.
If there are multiple compression types but none has been set,
an IllegalStateException
is thrown.
The default implementation checks that compression is
supported and that the compression mode is
MODE_EXPLICIT
. If so, if
getCompressionTypes()
is null
or
getCompressionType()
is non-null
, it
returns null
.
null
if none has been set. The type is returned
as a String
from among those returned by
getCompressionTypes
.
If no compression type has been set, null
is
returned.
The default implementation checks whether compression is
supported and the compression mode is
MODE_EXPLICIT
. If so, it returns the value of the
compressionType
instance variable.
String
s, or null
if a compression
type may not be chosen using these interfaces. The array
returned is a copy.
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.
The default implementation checks if compression is
supported and throws an
UnsupportedOperationException
if not. Otherwise,
it returns a clone of the compressionTypes
instance variable if it is non-null
, or else
returns null
.
IIOParamController
is currently
installed. This could be the default if there is one,
null
, or the argument of the most recent call
to setController
.IIOParamController
, if there
is one, regardless of the currently installed controller. If
there is no default controller, returns null
. If setDestinationOffsets
has not been called,
a Point
with zero X and Y values is returned
(which is the correct value).
setDestination(ImageTypeSpecifier)
, as an
ImageTypeSpecifier
. If none was set,
null
is returned.Locale
, or
null
if only a default Locale
is
supported.Locale
returned by
getLocale
.
The default implementation checks whether compression is
supported and the compression mode is
MODE_EXPLICIT
. If so, if
compressionType
is non-null
the value
of getCompressionType
is returned as a
convenience.
Dimension
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.
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
null
is used in place of an actual array of
Dimension
s.
If no array is specified on the constructor, but tiling is
allowed, then this method returns null
.
setSourceBands
, or null
if there have
been no calls to setSourceBands
.
Semantically, the array returned is a copy; changes to
array contents subsequent to this call have no effect on this
IIOParam
.
setSourceRegion
, and will be null
if
there is no region set.If setSourceSubsampling
has not been called, 1
is returned (which is the correct value).
If setSourceSubsampling
has not been called, 1
is returned (which is the correct value).
If setSourceSubsampling
has not been called, 0
is returned (which is the correct value).
If setSourceSubsampling
has not been called, 0
is returned (which is the correct value).
IllegalStateException
is thrown.IllegalStateException
is thrown.IllegalStateException
is thrown.IllegalStateException
is thrown.UnsupportedOperationException
.true
if there is a controller installed
for this IIOParam
object. This will return
true
if getController
would not
return null
.java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method on each of
the two objects must produce the same integer result.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
true
if the current compression type
provides lossless compression. If a plug-in provides only
one mandatory compression type, then this method may be
called without calling setCompressionType
first.
If there are multiple compression types but none has
been set, an IllegalStateException
is thrown.
The default implementation checks whether compression is
supported and the compression mode is
MODE_EXPLICIT
. If so, if
getCompressionTypes()
is null
or
getCompressionType()
is non-null
true
is returned as a convenience.
wait
methods.
The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
synchronized
statement
that synchronizes on the object.
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
wait
methods.
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
mode
argument must be one of the four modes, interpreted as follows:
MODE_DISABLED
- Do not compress. This may
not be permitted by some writers, such as JPEG, which do not
normally offer uncompressed output. The corresponding
set
and get
methods will throw an
IllegalStateException
.
MODE_EXPLICIT
- Compress using the
compression type and quality settings specified in this
ImageWriteParam
. Any previously set compression
parameters are discarded.
MODE_COPY_FROM_METADATA
- Use whatever
compression parameters are specified in metadata objects
passed in to the writer.
MODE_DEFAULT
- Use default compression
parameters.
The default is MODE_COPY_FROM_METADATA
.
0
and 1
. Only a single compression quality setting
is supported by default; writers can provide extended versions
of ImageWriteParam
that offer more control. For
lossy compression schemes, the compression quality should
control the tradeoff between file size and image quality (for
example, by choosing quantization tables when writing JPEG
images). For lossless schemes, the compression quality may be
used to control the tradeoff between file size and time taken
to perform the compression (for example, by optimizing row
filters and setting the ZLIB compression level when writing
PNG images).
A compression quality setting of 0.0 is most generically interpreted as "high compression is important," while a setting of 1.0 is most generically interpreted as "high image quality is important."
If there are multiple compression types but none has been
set, an IllegalStateException
is thrown.
The default implementation checks that compression is
supported, and that the compression mode is
MODE_EXPLICIT
. If so, if
getCompressionTypes()
returns null
or
compressionType
is non-null
it sets
the compressionQuality
instance variable.
getCompressionTypes
. If a value of
null
is passed in, any previous setting is
removed.
The default implementation checks whether compression is
supported and the compression mode is
MODE_EXPLICIT
. If so, it calls
getCompressionTypes
and checks if
compressionType
is one of the legal values. If it
is, the compressionType
instance variable is set.
If compressionType
is null
, the
instance variable is set without performing any checking.
IIOParamController
to be used
to provide settings for this IIOParam
object when the activateController
method
is called, overriding any default controller. If the
argument is null
, no controller will be
used, including any default. To restore the default, use
setController(getDefaultController())
. When reading, the region to be written within the
destination BufferedImage
will start at this
offset and have a width and height determined by the source
region of interest, the subsampling parameters, and the
destination bounds.
Normal writes are not affected by this method, only writes
performed using ImageWriter.replacePixels
. For
such writes, the offset specified is within the output stream
image whose pixels are being modified.
There is no unsetDestinationOffset
method;
simply call setDestinationOffset(new Point(0, 0))
to
restore default values.
ImageTypeSpecifier
.
When reading, if the layout of the destination has been set
using this method, each call to an ImageReader
read
method will return a new
BufferedImage
using the format specified by the
supplied type specifier. As a side effect, any destination
BufferedImage
set by
ImageReadParam.setDestination(BufferedImage)
will
no longer be set as the destination. In other words, this
method may be thought of as calling
setDestination((BufferedImage)null)
.
When writing, the destination type maybe used to determine
the color type of the image. The SampleModel
information will be ignored, and may be null
. For
example, a 4-banded image could represent either CMYK or RGBA
data. If a destination type is set, its
ColorModel
will override any
ColorModel
on the image itself. This is crucial
when setSourceBands
is used since the image's
ColorModel
will refer to the entire image rather
than to the subset of bands being written.
UnsupportedOperationException
will
be thrown.
The mode argument determines how
the progression parameters are chosen, and must be either
MODE_DISABLED
,
MODE_COPY_FROM_METADATA
, or
MODE_DEFAULT
. Otherwise an
IllegalArgumentException
is thrown.
The modes are interpreted as follows:
MODE_DISABLED
- No progression. Use this to
turn off progession.
MODE_COPY_FROM_METADATA
- The output image
will use whatever progression parameters are found in the
metadata objects passed into the writer.
MODE_DEFAULT
- The image will be written
progressively, with parameters chosen by the writer.
The default is MODE_COPY_FROM_METADATA
.
A null
value indicates that all source bands
will be used.
At the time of reading, an
IllegalArgumentException
will be thrown by the
reader or writer if a value larger than the largest available
source band index has been specified or if the number of source
bands and destination bands to be used differ. The
ImageReader.checkReadParamBandSettings
method may
be used to automate this test.
Semantically, a copy is made of the array; changes to the
array contents subsequent to this call have no effect on
this IIOParam
.
setSourceSubsampling
.
If subsampling has been set such that this number is zero,
an IllegalStateException
will be thrown.
The source region of interest specified by this method will be clipped as needed to fit within the source bounds, as well as the destination offsets, width, and height at the time of actual I/O.
A value of null
for sourceRegion
will remove any region specification, causing the entire image
to be used.
sourceXSubsampling
and
sourceYSubsampling
parameters specify the
subsampling period (i.e., the number of rows and columns
to advance after every source pixel). Specifically, a period of
1 will use every row or column; a period of 2 will use every
other row or column. The subsamplingXOffset
and
subsamplingYOffset
parameters specify an offset
from the region (or image) origin for the first subsampled pixel.
Adjusting the origin of the subsample grid is useful for avoiding
seams when subsampling a very large source image into destination
regions that will be assembled into a complete subsampled image.
Most users will want to simply leave these parameters at 0.
The number of pixels and scanlines to be used are calculated as follows.
The number of subsampled pixels in a scanline is given by
truncate[(width - subsamplingXOffset + sourceXSubsampling - 1)
/ sourceXSubsampling]
.
If the region is such that this width is zero, an
IllegalStateException
is thrown.
The number of scanlines to be used can be computed similarly.
The ability to set the subsampling grid to start somewhere
other than the source region origin is useful if the
region is being used to create subsampled tiles of a large image,
where the tile width and height are not multiples of the
subsampling periods. If the subsampling grid does not remain
consistent from tile to tile, there will be artifacts at the tile
boundaries. By adjusting the subsampling grid offset for each
tile to compensate, these artifacts can be avoided. The tradeoff
is that in order to avoid these artifacts, the tiles are not all
the same size. The grid offset to use in this case is given by:
grid offset = [period - (region offset modulo period)] modulo period)
If either sourceXSubsampling
or
sourceYSubsampling
is 0 or negative, an
IllegalArgumentException
will be thrown.
If either subsamplingXOffset
or
subsamplingYOffset
is negative or greater than or
equal to the corresponding period, an
IllegalArgumentException
will be thrown.
There is no unsetSourceSubsampling
method;
simply call setSourceSubsampling(1, 1, 0, 0)
to
restore default values.
tileWidth
and tileHeight
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.
If canOffsetTiles
returns false
,
then the tileGridXOffset
and
tileGridYOffset
parameters must be zero.
MODE_DISABLED
- The image will not be tiled.
setTiling
will throw an
IllegalStateException
.
MODE_DEFAULT
- The image will be tiled using
default parameters. setTiling
will throw an
IllegalStateException
.
MODE_EXPLICIT
- The image will be tiled
according to parameters given in the setTiling
method. Any previously set tiling
parameters are discarded.
MODE_COPY_FROM_METADATA
- The image will
conform to the metadata object passed in to a write.
setTiling
will throw an
IllegalStateException
.
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
The default implementation sets the instance variable
compressionType
to null
, and the
instance variable compressionQuality
to
1.0F
.
setTiling
.
The default implementation sets the instance variables
tileWidth
, tileHeight
,
tileGridXOffset
, and
tileGridYOffset
to 0
.
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.The current thread must own this object's monitor.
This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout); ... // Perform action appropriate to condition }(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).
If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:
notify
method
or the notifyAll
method.
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout, nanos); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.