Class JPEGDecoder
java.lang.Object
is.galia.codec.AbstractDecoder
is.galia.codec.AbstractImageIODecoder
is.galia.codec.jpeg.JPEGDecoder
- All Implemented Interfaces:
Decoder
,AutoCloseable
Implementation wrapping the default JDK Image I/O JPEG
ImageReader
.-
Field Summary
Fields inherited from class is.galia.codec.AbstractImageIODecoder
iioReader
Fields inherited from class is.galia.codec.AbstractDecoder
arena, imageFile, inputStream
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canSeek()
decode
(int imageIndex) Expedient but not necessarily efficient method that reads a whole image (excluding subimages) in one shot.decode
(int imageIndex, Region region, double[] scales, ReductionFactor reductionFactor, double[] diffScales, Set<DecoderHint> hints) Override to handle images with incompatible ICC profiles, and also CMYK images, neither of which the Sun JPEGImageReader can do.Called after a source has been set.protected org.slf4j.Logger
int
Overridden because the parent will include the thumbnail and other embedded images in the count, which we don't want.int
getNumThumbnails
(int imageIndex) The default implementation returns0
.protected String[]
N.B.: This method returns a list of strings rather thanclasses
because some readers reside under thecom.sun
package, which is encapsulated.getThumbnailSize
(int imageIndex, int thumbIndex) The default implementation throws anUnsupportedOperationException
.readMetadata
(int imageIndex) Reads metadata pertaining to the image at the given index.readThumbnail
(int imageIndex, int thumbIndex) Reads a thumbnail image into memory.Methods inherited from class is.galia.codec.AbstractImageIODecoder
close, decodeSequence, dispose, getNumResolutions, getSize, getTileSize, handle, initializeInputStream, readMonoResolution, readSmallestUsableSubimage
Methods inherited from class is.galia.codec.AbstractDecoder
setArena, setSource, setSource
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface is.galia.codec.Decoder
close, decodeSequence, getNumResolutions, getSize, getTileSize, setArena, setSource, setSource
-
Constructor Details
-
JPEGDecoder
public JPEGDecoder()
-
-
Method Details
-
canSeek
public boolean canSeek()- Specified by:
canSeek
in classAbstractImageIODecoder
-
detectFormat
Description copied from interface:Decoder
Called after a source has been set.
If reading from a
Decoder.setSource(ImageInputStream)
stream}, the stream position is reset to 0 before returning.Unlike many of the other interface methods, implementations should not throw a
SourceFormatException
, and instead just returnFormat.UNKNOWN
.- Specified by:
detectFormat
in interfaceDecoder
- Returns:
- Format of the image to decode, if supported by the instance;
otherwise
Format.UNKNOWN
. The implementation must create the instance from scratch and not obtain it from theformat registry
, which may be empty at the time this method is invoked. - Throws:
IOException
- if there is some other error reading the image.
-
getLogger
protected org.slf4j.Logger getLogger()- Specified by:
getLogger
in classAbstractImageIODecoder
-
getNumImages
Overridden because the parent will include the thumbnail and other embedded images in the count, which we don't want.- Specified by:
getNumImages
in interfaceDecoder
- Overrides:
getNumImages
in classAbstractImageIODecoder
- Returns:
1
, always.- Throws:
IOException
- if there is some other error reading the number of images.
-
getNumThumbnails
Description copied from interface:Decoder
The default implementation returns0
.- Specified by:
getNumThumbnails
in interfaceDecoder
- Overrides:
getNumThumbnails
in classAbstractImageIODecoder
- Returns:
- Number of thumbnail images available for the image at the given
index. (See
class documentation
.) - Throws:
IOException
- if there is some other error reading the number of thumbnails.
-
getPreferredIIOImplementations
Description copied from class:AbstractImageIODecoder
N.B.: This method returns a list of strings rather thanclasses
because some readers reside under thecom.sun
package, which is encapsulated.- Specified by:
getPreferredIIOImplementations
in classAbstractImageIODecoder
- Returns:
- Preferred reader implementation classes, in order of highest to lowest priority, or an empty array if there is no preference.
-
getSupportedFormats
- Specified by:
getSupportedFormats
in interfaceDecoder
- Specified by:
getSupportedFormats
in classAbstractImageIODecoder
- Returns:
- All formats supported by the implementation. The instances must
be created from scratch and not obtained from
the
format registry
, which may be empty at the time this method is invoked.
-
getThumbnailSize
Description copied from interface:Decoder
The default implementation throws an
UnsupportedOperationException
.- Specified by:
getThumbnailSize
in interfaceDecoder
- Overrides:
getThumbnailSize
in classAbstractImageIODecoder
- Parameters:
imageIndex
- See theclass documentation.
.thumbIndex
- Value between 0 andDecoder.getNumThumbnails(int)
- 1.- Returns:
- Size of the thumbnail at the given coordinates.
- Throws:
IOException
- if there is an error reading the size.
-
decode
Expedient but not necessarily efficient method that reads a whole image (excluding subimages) in one shot.- Specified by:
decode
in interfaceDecoder
- Overrides:
decode
in classAbstractImageIODecoder
- Throws:
IOException
-
decode
public BufferedImage decode(int imageIndex, Region region, double[] scales, ReductionFactor reductionFactor, double[] diffScales, Set<DecoderHint> hints) throws IOException Override to handle images with incompatible ICC profiles, and also CMYK images, neither of which the Sun JPEGImageReader can do.- Specified by:
decode
in interfaceDecoder
- Overrides:
decode
in classAbstractImageIODecoder
- Parameters:
imageIndex
- Image index.region
- May benull
.scales
- May benull
.reductionFactor
- TheReductionFactor.factor
property will be modified to reflect the reduction factor of the returned image.diffScales
- Two-element array that will be populated with the X and Y axis differential scales used during reading (if the decoder supports this).hints
- Will be populated by information returned from the reader.- Returns:
- Image best matching the given arguments.
- Throws:
IOException
- if there is some other error reading the image.
-
readMetadata
Description copied from interface:Decoder
Reads metadata pertaining to the image at the given index.- Specified by:
readMetadata
in interfaceDecoder
- Specified by:
readMetadata
in classAbstractImageIODecoder
- Returns:
- Metadata for the image at the given index. If there is none, an
EmptyMetadata
can be returned. - Throws:
IOException
- if there is some other error reading the metadata.
-
readThumbnail
Description copied from interface:Decoder
Reads a thumbnail image into memory.
Implementations are encouraged to return an instance whose
Raster
is backed by aDataBufferByte
. See the documentation ofDecoder.decode(int, Region, double[], ReductionFactor, double[], Set)
for more information.The default implementation throws an
UnsupportedOperationException
.- Specified by:
readThumbnail
in interfaceDecoder
- Overrides:
readThumbnail
in classAbstractImageIODecoder
- Parameters:
imageIndex
- See the class documentation.thumbIndex
- Value between 0 andDecoder.getNumThumbnails(int)
- 1.- Throws:
IOException
- if there is some other error reading the image.
-