| java.lang.Object com.sun.media.jai.codec.ImageCodec
All known Subclasses: com.sun.media.jai.codecimpl.TIFFCodec, com.sun.media.jai.codecimpl.PNGCodec, com.sun.media.jai.codecimpl.GIFCodec, com.sun.media.jai.codecimpl.FPXCodec, com.sun.media.jai.codecimpl.PNMCodec, com.sun.media.jai.codecimpl.WBMPCodec, com.sun.media.jai.codecimpl.JPEGCodec, com.sun.media.jai.codecimpl.BMPCodec,
ImageCodec | abstract public class ImageCodec (Code) | | An abstract class allowing the creation of image decoders and
encoders. Instances of ImageCodec may be registered.
Once a codec has been registered, the format name associated with
it may be used as the name parameter in the
createImageEncoder() and createImageDecoder()
methods.
Additionally, subclasses of ImageCodec
are able to perform recognition of their particular format,
wither by inspection of a fixed-length file header or by
arbitrary access to the source data stream.
Format recognition is performed by two variants of the
isFormatRecognized() method. Which variant should be
called is determined by the output of the codec's
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 public boolean | canEncodeImage(RenderedImage im, ImageEncodeParam param) Returns true if the given image and encoder param
object are suitable for encoding by this ImageCodec . | public static ColorModel | createComponentColorModel(SampleModel sm) A convenience method to create an instance of
ComponentColorModel suitable for use with the
given SampleModel . | public static ColorModel | createComponentColorModel(SampleModel sm, ColorSpace cp) A convenience method to create an instance of
ComponentColorModel suitable for use with the
given SampleModel and . | public static ColorModel | createGrayIndexColorModel(SampleModel sm, boolean blackIsZero) A convenience methods to create an instance of
IndexColorModel suitable for the given 1-banded
SampleModel . | public static ImageDecoder | createImageDecoder(String name, InputStream src, ImageDecodeParam param) Returns an ImageDecoder object suitable for
decoding from the supplied InputStream , using the
supplied ImageDecodeParam object.
Parameters: name - The name associated with the codec. Parameters: src - An InputStream to read from. Parameters: param - An instance of ImageDecodeParam suitablefor use with the named codec, or null . | public static ImageDecoder | createImageDecoder(String name, File src, ImageDecodeParam param) Returns an ImageDecoder object suitable for
decoding from the supplied File , using the
supplied ImageDecodeParam object.
Parameters: name - The name associated with the codec. Parameters: src - A File to read from. Parameters: param - An instance of ImageDecodeParam suitablefor use with the named codec, or null . | public static ImageDecoder | createImageDecoder(String name, SeekableStream src, ImageDecodeParam param) Returns an ImageDecoder object suitable for
decoding from the supplied SeekableStream , using the
supplied ImageDecodeParam object.
Parameters: name - The name associated with the codec. Parameters: src - A SeekableStream to read from. Parameters: param - An instance of ImageDecodeParam suitablefor use with the named codec, or null . | protected ImageDecoder | createImageDecoder(InputStream src, ImageDecodeParam param) Returns an implementation of the ImageDecoder
interface appropriate for that codec. | protected ImageDecoder | createImageDecoder(File src, ImageDecodeParam param) Returns an implementation of the ImageDecoder
interface appropriate for that codec. | abstract protected ImageDecoder | createImageDecoder(SeekableStream src, ImageDecodeParam param) In a concrete subclass of ImageCodec , returns an
implementation of the ImageDecoder interface
appropriate for that codec.
Parameters: dst - A SeekableStream to read from. Parameters: param - An instance of ImageDecodeParam suitable for use with the ImageCodec subclass, or null . | public static ImageEncoder | createImageEncoder(String name, OutputStream dst, ImageEncodeParam param) Returns an ImageEncoder object suitable for
encoding to the supplied OutputStream , using the
supplied ImageEncoderParam object.
Parameters: name - The name associated with the codec. Parameters: dst - An OutputStream to write to. Parameters: param - An instance of ImageEncoderParam suitablefor use with the named codec, or null . | abstract protected ImageEncoder | createImageEncoder(OutputStream dst, ImageEncodeParam param) In a concrete subclass of ImageCodec , returns an
implementation of the ImageEncoder interface
appropriate for that codec.
Parameters: dst - An OutputStream to write to. Parameters: param - An instance of ImageEncoderParam suitable for use with the ImageCodec subclass, or null . | public static ImageCodec | getCodec(String name) Returns the ImageCodec associated with the given
name. | public static Enumeration | getCodecs() Returns an Enumeration of all regstered
ImageCodec objects. | abstract protected Class | getDecodeParamClass() Returns a Class object indicating the proper
subclass of ImageDecodeParam to be used with this
ImageCodec . | public static String[] | getDecoderNames(SeekableStream src) Returns an array of String s indicating the names
of registered ImageCodec s 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 FormatRecognizer s
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.
Parameters: src - A SeekableStream which optionally supportsseeking backwards. | abstract protected Class | getEncodeParamClass() Returns a Class object indicating the proper
subclass of ImageEncodeParam to be used with this
ImageCodec . | public static String[] | getEncoderNames(RenderedImage im, ImageEncodeParam param) Returns an array of String s indicating the names
of registered ImageCodec s that may be appropriate
for writing the given RenderedImage , using the
optional ImageEncodeParam , which may be
null .
Parameters: im - A RenderedImage to be encodec. Parameters: param - An ImageEncodeParam , or null. | abstract public String | getFormatName() Returns the name of this image format. | 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. | public boolean | isFormatRecognized(byte[] header) Returns true if the format is recognized in the
initial portion of a stream. | public boolean | isFormatRecognized(SeekableStream src) Returns true if the format is recognized in the
input data stream. | public static boolean | isIndicesForGrayscale(byte[] r, byte[] g, byte[] b) Tests whether the color indices represent a gray-scale image.
Parameters: r - The red channel color indices. Parameters: g - The green channel color indices. Parameters: b - The blue channel color indices. | public static void | registerCodec(ImageCodec codec) Associates an ImageCodec with its format name, as
determined by its getFormatName() method. | public static void | unregisterCodec(String name) Unregisters the ImageCodec object currently
responsible for handling the named format. |
ImageCodec | protected ImageCodec()(Code) | | Allow only subclasses to instantiate this class.
|
canEncodeImage | abstract public boolean canEncodeImage(RenderedImage im, ImageEncodeParam param)(Code) | | 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.
Parameters: im - a RenderedImage whose ability to be encoded is to bedetermined. Parameters: param - a suitable ImageEncodeParam object,or null . |
createComponentColorModel | public static ColorModel createComponentColorModel(SampleModel sm)(Code) | | 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.
|
createComponentColorModel | public static ColorModel createComponentColorModel(SampleModel sm, ColorSpace cp)(Code) | | A convenience method to create an instance of
ComponentColorModel suitable for use with the
given SampleModel and . 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.
|
createGrayIndexColorModel | public static ColorModel createGrayIndexColorModel(SampleModel sm, boolean blackIsZero)(Code) | | A convenience methods to create an instance of
IndexColorModel suitable for the given 1-banded
SampleModel .
Parameters: sm - a 1-banded SampleModel . Parameters: blackIsZero - true if the gray ramp shouldgo from black to white, false otherwise. |
createImageDecoder | public static ImageDecoder createImageDecoder(String name, InputStream src, ImageDecodeParam param)(Code) | | Returns an ImageDecoder object suitable for
decoding from the supplied InputStream , using the
supplied ImageDecodeParam object.
Parameters: name - The name associated with the codec. Parameters: src - An InputStream to read from. Parameters: param - An instance of ImageDecodeParam suitablefor use with the named codec, or null . An instance of ImageDecoder , or null . |
createImageDecoder | public static ImageDecoder createImageDecoder(String name, File src, ImageDecodeParam param) throws IOException(Code) | | Returns an ImageDecoder object suitable for
decoding from the supplied File , using the
supplied ImageDecodeParam object.
Parameters: name - The name associated with the codec. Parameters: src - A File to read from. Parameters: param - An instance of ImageDecodeParam suitablefor use with the named codec, or null . An instance of ImageDecoder , or null . |
createImageDecoder | public static ImageDecoder createImageDecoder(String name, SeekableStream src, ImageDecodeParam param)(Code) | | Returns an ImageDecoder object suitable for
decoding from the supplied SeekableStream , using the
supplied ImageDecodeParam object.
Parameters: name - The name associated with the codec. Parameters: src - A SeekableStream to read from. Parameters: param - An instance of ImageDecodeParam suitablefor use with the named codec, or null . An instance of ImageDecoder , or null . |
createImageDecoder | protected ImageDecoder createImageDecoder(InputStream src, ImageDecodeParam param)(Code) | | 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) .
Parameters: dst - An InputStream to read from. Parameters: param - An instance of ImageDecodeParam suitable for use with the ImageCodec subclass, or null . An instance of ImageDecoder . |
createImageDecoder | protected ImageDecoder createImageDecoder(File src, ImageDecodeParam param) throws IOException(Code) | | 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.
Parameters: dst - A File to read from. Parameters: param - An instance of ImageDecodeParam suitable for use with the ImageCodec subclass, or null . An instance of ImageDecoder . |
createImageDecoder | abstract protected ImageDecoder createImageDecoder(SeekableStream src, ImageDecodeParam param)(Code) | | In a concrete subclass of ImageCodec , returns an
implementation of the ImageDecoder interface
appropriate for that codec.
Parameters: dst - A SeekableStream to read from. Parameters: param - An instance of ImageDecodeParam suitable for use with the ImageCodec subclass, or null . An instance of ImageDecoder . |
createImageEncoder | public static ImageEncoder createImageEncoder(String name, OutputStream dst, ImageEncodeParam param)(Code) | | Returns an ImageEncoder object suitable for
encoding to the supplied OutputStream , using the
supplied ImageEncoderParam object.
Parameters: name - The name associated with the codec. Parameters: dst - An OutputStream to write to. Parameters: param - An instance of ImageEncoderParam suitablefor use with the named codec, or null . An instance of ImageEncoder , or null . |
createImageEncoder | abstract protected ImageEncoder createImageEncoder(OutputStream dst, ImageEncodeParam param)(Code) | | In a concrete subclass of ImageCodec , returns an
implementation of the ImageEncoder interface
appropriate for that codec.
Parameters: dst - An OutputStream to write to. Parameters: param - An instance of ImageEncoderParam suitable for use with the ImageCodec subclass, or null . An instance of ImageEncoder . |
getCodec | public static ImageCodec getCodec(String name)(Code) | | Returns the ImageCodec associated with the given
name. null is returned if no codec is registered
with the given name. Case is not significant.
Parameters: name - The name associated with the codec. The associated ImageCodec , or null . |
getCodecs | public static Enumeration getCodecs()(Code) | | Returns an Enumeration of all regstered
ImageCodec objects.
|
getDecodeParamClass | abstract protected Class getDecodeParamClass()(Code) | | 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.
|
getDecoderNames | public static String[] getDecoderNames(SeekableStream src)(Code) | | Returns an array of String s indicating the names
of registered ImageCodec s 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 FormatRecognizer s
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.
Parameters: src - A SeekableStream which optionally supportsseeking backwards. An array of String s. throws: IllegalArgumentException - if src supportsneither seeking backwards nor marking. |
getEncodeParamClass | abstract protected Class getEncodeParamClass()(Code) | | 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.
|
getEncoderNames | public static String[] getEncoderNames(RenderedImage im, ImageEncodeParam param)(Code) | | Returns an array of String s indicating the names
of registered ImageCodec s that may be appropriate
for writing the given RenderedImage , using the
optional ImageEncodeParam , which may be
null .
Parameters: im - A RenderedImage to be encodec. Parameters: param - An ImageEncodeParam , or null. An array of String s. |
getFormatName | abstract public String getFormatName()(Code) | | Returns the name of this image format.
A String containing the name of theimage format supported by this codec. |
getNumHeaderBytes | public int getNumHeaderBytes()(Code) | | 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)(Code) | | 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.
Parameters: header - An array of byte s containing the inputstream header. true if the format is recognized. |
isFormatRecognized | public boolean isFormatRecognized(SeekableStream src) throws IOException(Code) | | 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.
Parameters: src - A SeekableStream containing the inputdata. true if the format is recognized. |
isIndicesForGrayscale | public static boolean isIndicesForGrayscale(byte[] r, byte[] g, byte[] b)(Code) | | Tests whether the color indices represent a gray-scale image.
Parameters: r - The red channel color indices. Parameters: g - The green channel color indices. Parameters: b - The blue channel color indices. If all the indices have 256 entries, and are identical mappings,return true ; otherwise, return false . |
registerCodec | public static void registerCodec(ImageCodec codec)(Code) | | 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.
Parameters: codec - The ImageCodec object to be registered. |
unregisterCodec | public static void unregisterCodec(String name)(Code) | | Unregisters the ImageCodec object currently
responsible for handling the named format. Case is not
significant.
Parameters: name - The name associated with the codec to be removed. |
|
|