Class JPEGImageReader
java.lang.Object
javax.imageio.ImageReader
com.twelvemonkeys.imageio.ImageReaderBase
com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader
A JPEG
Main features:
ImageReader
implementation based on the JRE JPEGImageReader
,
that adds support and properly handles cases where the JRE version throws exceptions.
Main features:
- Support for YCbCr JPEGs without JFIF segment (converted to RGB, using the embedded ICC profile if applicable)
- Support for CMYK JPEGs (converted to RGB by default or as CMYK, using the embedded ICC profile if applicable)
- Support for Adobe YCCK JPEGs (converted to RGB by default or as CMYK, using the embedded ICC profile if applicable)
- Support for JPEGs containing ICC profiles with interpretation other than 'Perceptual' (profile is assumed to be 'Perceptual' and used)
- Support for JPEGs containing ICC profiles with class other than 'Display' (profile is assumed to have class 'Display' and used)
- Support for JPEGs containing ICC profiles that are incompatible with stream data (image data is read, profile is ignored)
- Support for JPEGs with corrupted ICC profiles (image data is read, profile is ignored)
- Support for JPEGs with corrupted
ICC_PROFILE
segments (image data is read, profile is ignored) - Support for JPEGs using non-standard color spaces, unsupported by Java 2D (image data is read, profile is ignored)
- Issues warnings instead of throwing exceptions in cases of corrupted data where ever the image data can still be read in a reasonable way
- Support for JFIF thumbnails (even if stream contains inconsistent metadata)
- Support for JFXX thumbnails (JPEG, Indexed and RGB)
- Support for EXIF thumbnails (JPEG, RGB and YCbCr)
- Support for JPEG metadata in both standard and native formats (even if stream contains inconsistent metadata)
- Support for
javax_imageio_jpeg_image_1.0
format (currently as native format, may change in the future) - Support for illegal combinations of JFIF, Exif and Adobe markers, using "unknown" segments in the
"MarkerSequence" tag for the unsupported segments (for
javax_imageio_jpeg_image_1.0
format)
- Version:
- $Id: JPEGImageReader.java,v 1.0 24.01.11 16.37 haraldk Exp$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
private class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int
Internal constant for referring all APP segmentsprivate int
(package private) static final boolean
private final ImageReader
Our JPEG reading delegate(package private) static final boolean
private final JPEGImageReader.ProgressDelegator
Listens to progress updates in the delegate, and delegates back to this instanceCached list of JPEG segments we filter from the underlying streamprivate ImageReader
Extra delegate for reading JPEG encoded thumbnailsprivate List
<ThumbnailReader> Fields inherited from class com.twelvemonkeys.imageio.ImageReaderBase
imageInput
Fields inherited from class javax.imageio.ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
boolean
private void
checkThumbnailBounds
(int imageIndex, int thumbnailIndex) private static void
convertYCbCr2RGB
(Raster raster, int numComponents) private static void
convertYCCK2CMYK
(Raster raster) private boolean
delegateCSTypeMismatch
(JFIF jfif, AdobeDCT adobeDCT, Frame startOfFrame, JPEGColorSpace sourceCSType) void
dispose()
private ICC_Profile
ensureDisplayProfile
(ICC_Profile profile) (package private) AdobeDCT
(package private) List
<Application> getAppSegments
(int marker, String identifier) (package private) ICC_Profile
getEmbeddedICCProfile
(boolean allowBadIndexes) private EXIF
getExif()
int
getHeight
(int imageIndex) getImageMetadata
(int imageIndex) Default implementation that always returnsnull
.getImageTypes
(int imageIndex) (package private) JFIF
getJFIF()
(package private) JFXX
getJFXX()
int
getNumImages
(boolean allowSearch) Default implementation that always returns1
.int
getNumThumbnails
(int imageIndex) getRawImageType
(int imageIndex) (package private) Frame
getSOF()
(package private) static JPEGColorSpace
getSourceCSType
(JFIF jfif, AdobeDCT adobeDCT, Frame startOfFrame) Default implementation that always returnsnull
.int
getThumbnailHeight
(int imageIndex, int thumbnailIndex) (package private) ImageReader
int
getThumbnailWidth
(int imageIndex, int thumbnailIndex) int
getWidth
(int imageIndex) private void
gotoImage
(int imageIndex) private void
initDelegate
(boolean seekForwardOnly, boolean ignoreMetadata) private void
private void
initHeader
(int imageIndex) private void
(package private) static int
intFromBigEndian
(byte[] array, int index) (package private) static void
intToBigEndian
(int value, byte[] array, int index) private static void
invertCMYK
(Raster raster) private boolean
private Application
lastAppSegment
(int marker, String identifier) static void
private CompoundDirectory
protected void
processWarningOccurred
(String warning) read
(int imageIndex, ImageReadParam param) readAsRenderedImage
(int imageIndex, ImageReadParam param) boolean
private ICC_Profile
readICCProfileSafe
(InputStream stream, boolean allowBadProfile) private BufferedImage
readImageAsRasterAndReplaceColorProfile
(int imageIndex, ImageReadParam param, Frame startOfFrame, JPEGColorSpace csType, ICC_Profile profile) readRaster
(int imageIndex, ImageReadParam param) private List
<JPEGSegment> readThumbnail
(int imageIndex, int thumbnailIndex) private void
readThumbnailMetadata
(int imageIndex) protected void
Resets all member variables.void
OverridessetInput
, to allow easy access to the input, in case it is anImageInputStream
.protected static void
showIt
(BufferedImage pImage, String pTitle) Methods inherited from class com.twelvemonkeys.imageio.ImageReaderBase
assertInput, checkBounds, fakeAOI, fakeSubsampling, getDestination, hasExplicitDestination, reset
Methods inherited from class javax.imageio.ImageReader
abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, checkReadParamBandSettings, clearAbortRequest, computeRegions, getAspectRatio, getAvailableLocales, getImageMetadata, getInput, getLocale, getMinIndex, getOriginatingProvider, getSourceRegion, getStreamMetadata, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, hasThumbnails, isIgnoringMetadata, isImageTiled, isRandomAccessEasy, isSeekForwardOnly, processImageComplete, processImageProgress, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, read, readAll, readAll, readTile, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, setInput, setInput, setLocale
-
Field Details
-
DEBUG
static final boolean DEBUG -
FORCE_RASTER_CONVERSION
static final boolean FORCE_RASTER_CONVERSION -
ALL_APP_MARKERS
static final int ALL_APP_MARKERSInternal constant for referring all APP segments- See Also:
-
delegate
Our JPEG reading delegate -
progressDelegator
Listens to progress updates in the delegate, and delegates back to this instance -
thumbnailReader
Extra delegate for reading JPEG encoded thumbnails -
thumbnails
-
segments
Cached list of JPEG segments we filter from the underlying stream -
currentStreamIndex
private int currentStreamIndex -
streamOffsets
-
-
Constructor Details
-
JPEGImageReader
JPEGImageReader(ImageReaderSpi provider, ImageReader delegate)
-
-
Method Details
-
installListeners
private void installListeners() -
resetMembers
protected void resetMembers()Description copied from class:ImageReaderBase
Resets all member variables. This method is by default invoked from:- Specified by:
resetMembers
in classImageReaderBase
-
dispose
public void dispose()- Overrides:
dispose
in classImageReaderBase
-
getFormatName
- Overrides:
getFormatName
in classImageReader
- Throws:
IOException
-
isLossless
- Throws:
IOException
-
getWidth
- Specified by:
getWidth
in classImageReader
- Throws:
IOException
-
getHeight
- Specified by:
getHeight
in classImageReader
- Throws:
IOException
-
getImageTypes
- Specified by:
getImageTypes
in classImageReader
- Throws:
IOException
-
getRawImageType
- Overrides:
getRawImageType
in classImageReader
- Throws:
IOException
-
read
- Specified by:
read
in classImageReader
- Throws:
IOException
-
delegateCSTypeMismatch
private boolean delegateCSTypeMismatch(JFIF jfif, AdobeDCT adobeDCT, Frame startOfFrame, JPEGColorSpace sourceCSType) throws IOException - Throws:
IOException
-
readImageAsRasterAndReplaceColorProfile
private BufferedImage readImageAsRasterAndReplaceColorProfile(int imageIndex, ImageReadParam param, Frame startOfFrame, JPEGColorSpace csType, ICC_Profile profile) throws IOException - Throws:
IOException
-
getSourceCSType
static JPEGColorSpace getSourceCSType(JFIF jfif, AdobeDCT adobeDCT, Frame startOfFrame) throws IIOException - Throws:
IIOException
-
ensureDisplayProfile
- Throws:
IOException
-
intFromBigEndian
static int intFromBigEndian(byte[] array, int index) -
intToBigEndian
static void intToBigEndian(int value, byte[] array, int index) -
setInput
Description copied from class:ImageReaderBase
OverridessetInput
, to allow easy access to the input, in case it is anImageInputStream
.- Overrides:
setInput
in classImageReaderBase
- Parameters:
input
- theImageInputStream
or otherObject
to use for future decoding.seekForwardOnly
- iftrue
, images and metadata may only be read in ascending order from this input source.ignoreMetadata
- iftrue
, metadata may be ignored during reads.- See Also:
-
initDelegate
- Throws:
IOException
-
initHeader
- Throws:
IOException
-
initHeader
- Throws:
IOException
-
gotoImage
- Throws:
IOException
-
getNumImages
Description copied from class:ImageReaderBase
Default implementation that always returns1
.- Overrides:
getNumImages
in classImageReaderBase
- Parameters:
allowSearch
- ignored, unless overridden- Returns:
1
, unless overridden- Throws:
IOException
- never, unless overridden
-
readSegments
- Throws:
IOException
-
getAppSegments
- Throws:
IOException
-
getSOF
- Throws:
IOException
-
lastAppSegment
- Throws:
IOException
-
getAdobeDCT
- Throws:
IOException
-
getJFIF
- Throws:
IOException
-
getJFXX
- Throws:
IOException
-
getExif
- Throws:
IOException
-
parseExif
- Throws:
IOException
-
getEmbeddedICCProfile
- Throws:
IOException
-
readICCProfileSafe
-
canReadRaster
public boolean canReadRaster()- Overrides:
canReadRaster
in classImageReader
-
readRaster
- Overrides:
readRaster
in classImageReader
- Throws:
IOException
-
readAsRenderedImage
- Overrides:
readAsRenderedImage
in classImageReader
- Throws:
IOException
-
abort
public void abort()- Overrides:
abort
in classImageReader
-
getDefaultReadParam
- Overrides:
getDefaultReadParam
in classImageReader
-
readerSupportsThumbnails
public boolean readerSupportsThumbnails()- Overrides:
readerSupportsThumbnails
in classImageReader
-
readThumbnailMetadata
- Throws:
IOException
-
getThumbnailReader
- Throws:
IOException
-
getNumThumbnails
- Overrides:
getNumThumbnails
in classImageReader
- Throws:
IOException
-
checkThumbnailBounds
- Throws:
IOException
-
getThumbnailWidth
- Overrides:
getThumbnailWidth
in classImageReader
- Throws:
IOException
-
getThumbnailHeight
- Overrides:
getThumbnailHeight
in classImageReader
- Throws:
IOException
-
readThumbnail
- Overrides:
readThumbnail
in classImageReader
- Throws:
IOException
-
getImageMetadata
Description copied from class:ImageReaderBase
Default implementation that always returnsnull
.- Overrides:
getImageMetadata
in classImageReaderBase
- Parameters:
imageIndex
- ignored, unless overridden- Returns:
null
, unless overridden- Throws:
IOException
- never, unless overridden.
-
getStreamMetadata
Description copied from class:ImageReaderBase
Default implementation that always returnsnull
.- Overrides:
getStreamMetadata
in classImageReaderBase
- Returns:
null
, unless overridden- Throws:
IOException
- never, unless overridden.
-
processWarningOccurred
- Overrides:
processWarningOccurred
in classImageReader
-
invertCMYK
-
convertYCbCr2RGB
-
convertYCCK2CMYK
-
showIt
-
main
- Throws:
IOException
-