getNumHeaderBytes() method, which returns 0 if
arbitrary access to the stream is required, and otherwise returns
the number of header bytes required to recognize the format.
Each subclass of ImageCodec needs to implement only
one of the two variants.
This class is not a committed part of the JAI API. It may
be removed or changed in future releases of JAI.
|
Constructor Summary |
protected |
ImageCodec()
Allow only subclasses to instantiate this class. |
|
Method Summary |
abstract boolean |
canEncodeImage(java.awt.image.RenderedImage im,
ImageEncodeParam param)
Returns true if the given image and encoder param
object are suitable for encoding by this ImageCodec. |
static java.awt.image.ColorModel |
createComponentColorModel(java.awt.image.SampleModel sm)
A convenience method to create an instance of
ComponentColorModel suitable for use with the
given SampleModel. |
static java.awt.image.ColorModel |
createGrayIndexColorModel(java.awt.image.SampleModel sm,
boolean blackIsZero)
A convenience methods to create an instance of
IndexColorModel suitable for the given 1-banded
SampleModel. |
protected ImageDecoder |
createImageDecoder(java.io.File src,
ImageDecodeParam param)
Returns an implementation of the ImageDecoder
interface appropriate for that codec. |
protected ImageDecoder |
createImageDecoder(java.io.InputStream src,
ImageDecodeParam param)
Returns an implementation of the ImageDecoder
interface appropriate for that codec. |
protected abstract ImageDecoder |
createImageDecoder(SeekableStream src,
ImageDecodeParam param)
In a concrete subclass of ImageCodec, returns an
implementation of the ImageDecoder interface
appropriate for that codec. |
static ImageDecoder |
createImageDecoder(java.lang.String name,
java.io.File src,
ImageDecodeParam param)
Returns an ImageDecoder object suitable for
decoding from the supplied File, using the
supplied ImageDecodeParam object. |
static ImageDecoder |
createImageDecoder(java.lang.String name,
java.io.InputStream src,
ImageDecodeParam param)
Returns an ImageDecoder object suitable for
decoding from the supplied InputStream, using the
supplied ImageDecodeParam object. |
static ImageDecoder |
createImageDecoder(java.lang.String name,
SeekableStream src,
ImageDecodeParam param)
Returns an ImageDecoder object suitable for
decoding from the supplied SeekableStream, using the
supplied ImageDecodeParam object. |
protected abstract ImageEncoder |
createImageEncoder(java.io.OutputStream dst,
ImageEncodeParam param)
In a concrete subclass of ImageCodec, returns an
implementation of the ImageEncoder interface
appropriate for that codec. |
static ImageEncoder |
createImageEncoder(java.lang.String name,
java.io.OutputStream dst,
ImageEncodeParam param)
Returns an ImageEncoder object suitable for
encoding to the supplied OutputStream, using the
supplied ImageEncoderParam object. |
static ImageCodec |
getCodec(java.lang.String name)
Returns the ImageCodec associated with the given
name. |
static java.util.Enumeration |
getCodecs()
Returns an Enumeration of all regstered
ImageCodec objects. |
protected abstract java.lang.Class |
getDecodeParamClass()
Returns a Class object indicating the proper
subclass of ImageDecodeParam to be used with this
ImageCodec. |
static java.lang.String[] |
getDecoderNames(SeekableStream src)
Returns an array of Strings indicating the names
of registered ImageCodecs that may be appropriate
for reading the given SeekableStream. |
protected abstract java.lang.Class |
getEncodeParamClass()
Returns a Class object indicating the proper
subclass of ImageEncodeParam to be used with this
ImageCodec. |
static java.lang.String[] |
getEncoderNames(java.awt.image.RenderedImage im,
ImageEncodeParam param)
Returns an array of Strings indicating the names
of registered ImageCodecs that may be appropriate
for writing the given RenderedImage, using the
optional ImageEncodeParam, which may be
null. |
abstract java.lang.String |
getFormatName()
Returns the name of this image format. |
int |
getNumHeaderBytes()
Returns the number of bytes of header needed to recognize the
format, or 0 if an arbitrary number of bytes may be needed. |
boolean |
isFormatRecognized(byte[] header)
Returns true if the format is recognized in the
initial portion of a stream. |
boolean |
isFormatRecognized(SeekableStream src)
Returns true if the format is recognized in the
input data stream. |
static void |
registerCodec(ImageCodec codec)
Associates an ImageCodec with its format name, as
determined by its getFormatName() method. |
static void |
unregisterCodec(java.lang.String name)
Unregisters the ImageCodec object currently
responsible for handling the named format. |
private static java.lang.String[] |
vectorToStrings(java.util.Vector nameVec)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
codecs
private static java.util.Hashtable codecs
grayIndexCmaps
private static final byte[][] grayIndexCmaps
GrayBits8
private static final int[] GrayBits8
colorModelGray8
private static final java.awt.image.ComponentColorModel colorModelGray8
GrayAlphaBits8
private static final int[] GrayAlphaBits8
colorModelGrayAlpha8
private static final java.awt.image.ComponentColorModel colorModelGrayAlpha8
GrayBits16
private static final int[] GrayBits16
colorModelGray16
private static final java.awt.image.ComponentColorModel colorModelGray16
GrayAlphaBits16
private static final int[] GrayAlphaBits16
colorModelGrayAlpha16
private static final java.awt.image.ComponentColorModel colorModelGrayAlpha16
GrayBits32
private static final int[] GrayBits32
colorModelGray32
private static final java.awt.image.ComponentColorModel colorModelGray32
GrayAlphaBits32
private static final int[] GrayAlphaBits32
colorModelGrayAlpha32
private static final java.awt.image.ComponentColorModel colorModelGrayAlpha32
RGBBits8
private static final int[] RGBBits8
colorModelRGB8
private static final java.awt.image.ComponentColorModel colorModelRGB8
RGBABits8
private static final int[] RGBABits8
colorModelRGBA8
private static final java.awt.image.ComponentColorModel colorModelRGBA8
RGBBits16
private static final int[] RGBBits16
colorModelRGB16
private static final java.awt.image.ComponentColorModel colorModelRGB16
RGBABits16
private static final int[] RGBABits16
colorModelRGBA16
private static final java.awt.image.ComponentColorModel colorModelRGBA16
RGBBits32
private static final int[] RGBBits32
colorModelRGB32
private static final java.awt.image.ComponentColorModel colorModelRGB32
RGBABits32
private static final int[] RGBABits32
colorModelRGBA32
private static final java.awt.image.ComponentColorModel colorModelRGBA32
ImageCodec
protected ImageCodec()
- Allow only subclasses to instantiate this class.
getCodec
public static ImageCodec getCodec(java.lang.String name)
- Returns the
ImageCodec associated with the given
name. null is returned if no codec is registered
with the given name. Case is not significant.
registerCodec
public static void registerCodec(ImageCodec codec)
- Associates an
ImageCodec with its format name, as
determined by its getFormatName() method. Case is
not significant. Any codec previously associated with the name
is discarded.
unregisterCodec
public static void unregisterCodec(java.lang.String name)
- Unregisters the
ImageCodec object currently
responsible for handling the named format. Case is not
significant.
getCodecs
public static java.util.Enumeration getCodecs()
- Returns an
Enumeration of all regstered
ImageCodec objects.
createImageEncoder
public static ImageEncoder createImageEncoder(java.lang.String name,
java.io.OutputStream dst,
ImageEncodeParam param)
- Returns an
ImageEncoder object suitable for
encoding to the supplied OutputStream, using the
supplied ImageEncoderParam object.
createImageDecoder
public static ImageDecoder createImageDecoder(java.lang.String name,
java.io.InputStream src,
ImageDecodeParam param)
- Returns an
ImageDecoder object suitable for
decoding from the supplied InputStream, using the
supplied ImageDecodeParam object.
createImageDecoder
public static ImageDecoder createImageDecoder(java.lang.String name,
java.io.File src,
ImageDecodeParam param)
throws java.io.IOException
- Returns an
ImageDecoder object suitable for
decoding from the supplied File, using the
supplied ImageDecodeParam object.
createImageDecoder
public static ImageDecoder createImageDecoder(java.lang.String name,
SeekableStream src,
ImageDecodeParam param)
- Returns an
ImageDecoder object suitable for
decoding from the supplied SeekableStream, using the
supplied ImageDecodeParam object.
vectorToStrings
private static java.lang.String[] vectorToStrings(java.util.Vector nameVec)
getDecoderNames
public static java.lang.String[] getDecoderNames(SeekableStream src)
- Returns an array of
Strings indicating the names
of registered ImageCodecs that may be appropriate
for reading the given SeekableStream.
If the src SeekableStream does
not support seeking backwards (that is, its
canSeekBackwards() method returns
false) then only FormatRecognizers
that require only a fixed-length header will be checked.
If the src stream does not support seeking
backwards, it must support marking, as determined by its
markSupported() method.
getEncoderNames
public static java.lang.String[] getEncoderNames(java.awt.image.RenderedImage im,
ImageEncodeParam param)
- Returns an array of
Strings indicating the names
of registered ImageCodecs that may be appropriate
for writing the given RenderedImage, using the
optional ImageEncodeParam, which may be
null.
getFormatName
public abstract java.lang.String getFormatName()
- Returns the name of this image format.
getNumHeaderBytes
public int getNumHeaderBytes()
- Returns the number of bytes of header needed to recognize the
format, or 0 if an arbitrary number of bytes may be needed.
The default implementation returns 0.
The return value must be a constant for all instances of
each particular subclass of ImageCodec.
Although it is legal to always return 0, in some cases
processing may be more efficient if the number of bytes needed
is known in advance.
isFormatRecognized
public boolean isFormatRecognized(byte[] header)
- Returns
true if the format is recognized in the
initial portion of a stream. The header will be passed in as a
byte array of length getNumHeaderBytes().
This method should be called only if getNumHeaderBytes()
returns a value greater than 0.
The default implementation throws an exception to indicate
that it should never be called.
isFormatRecognized
public boolean isFormatRecognized(SeekableStream src)
throws java.io.IOException
- Returns
true if the format is recognized in the
input data stream. This method should be called only if
getNumHeaderBytesNeeded() returns 0.
The source SeekableStream is guaranteed to
support seeking backwards, and should be seeked to 0 prior
to calling this method.
The default implementation throws an exception to indicate
that it should never be called.
getEncodeParamClass
protected abstract java.lang.Class getEncodeParamClass()
- Returns a
Class object indicating the proper
subclass of ImageEncodeParam to be used with this
ImageCodec. If encoding is not supported by this
codec, null is returned. If encoding is
supported, but a parameter object is not used during encoding,
Object.class is returned to signal this fact.
getDecodeParamClass
protected abstract java.lang.Class getDecodeParamClass()
- Returns a
Class object indicating the proper
subclass of ImageDecodeParam to be used with this
ImageCodec. If encoding is not supported by this
codec, null is returned. If decoding is
supported, but a parameter object is not used during decoding,
Object.class is returned to signal this fact.
createImageEncoder
protected abstract ImageEncoder createImageEncoder(java.io.OutputStream dst,
ImageEncodeParam param)
- In a concrete subclass of
ImageCodec, returns an
implementation of the ImageEncoder interface
appropriate for that codec.
canEncodeImage
public abstract boolean canEncodeImage(java.awt.image.RenderedImage im,
ImageEncodeParam param)
- Returns
true if the given image and encoder param
object are suitable for encoding by this ImageCodec.
For example, some codecs may only deal with images with a certain
number of bands; an attempt to encode an image with an unsupported
number of bands will fail.
createImageDecoder
protected ImageDecoder createImageDecoder(java.io.InputStream src,
ImageDecodeParam param)
- Returns an implementation of the
ImageDecoder
interface appropriate for that codec. Subclasses of
ImageCodec may override this method if they wish
to accept data directly from an InputStream;
otherwise, this method will convert the source into a
backwards-seekable SeekableStream and call the
appropriate version of createImageDecoder for that
data type.
Instances of ImageCodec that do not require
the ability to seek backwards in their source
SeekableStream should override this method in
order to avoid the default call to
SeekableStream.wrapInputStream(src, true).
createImageDecoder
protected ImageDecoder createImageDecoder(java.io.File src,
ImageDecodeParam param)
throws java.io.IOException
- Returns an implementation of the
ImageDecoder
interface appropriate for that codec. Subclasses of
ImageCodec may override this method if they wish
to accept data directly from a File;
otherwise, this method will convert the source into a
SeekableStream and call the appropriate
version of createImageDecoder for that data type.
createImageDecoder
protected abstract ImageDecoder createImageDecoder(SeekableStream src,
ImageDecodeParam param)
- In a concrete subclass of
ImageCodec, returns an
implementation of the ImageDecoder interface
appropriate for that codec.
createGrayIndexColorModel
public static java.awt.image.ColorModel createGrayIndexColorModel(java.awt.image.SampleModel sm,
boolean blackIsZero)
- A convenience methods to create an instance of
IndexColorModel suitable for the given 1-banded
SampleModel.
createComponentColorModel
public static java.awt.image.ColorModel createComponentColorModel(java.awt.image.SampleModel sm)
- A convenience method to create an instance of
ComponentColorModel suitable for use with the
given SampleModel. The SampleModel
should have a data type of DataBuffer.TYPE_BYTE,
TYPE_USHORT, or TYPE_INT and between
1 and 4 bands. Depending on the number of bands of the
SampleModel, either a gray, gray+alpha, rgb, or
rgb+alpha ColorModel is returned.