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_PROFILEsegments (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.0format (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.0format)
- Version:
- $Id: JPEGImageReader.java,v 1.0 24.01.11 16.37 haraldk Exp$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intInternal constant for referring all APP segmentsprivate int(package private) static final booleanprivate final ImageReaderOur JPEG reading delegate(package private) static final booleanprivate final JPEGImageReader.ProgressDelegatorListens to progress updates in the delegate, and delegates back to this instanceCached list of JPEG segments we filter from the underlying streamprivate ImageReaderExtra delegate for reading JPEG encoded thumbnailsprivate List<ThumbnailReader> Fields inherited from class ImageReaderBase
imageInputFields inherited from class ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()booleanprivate voidcheckThumbnailBounds(int imageIndex, int thumbnailIndex) private static voidconvertYCbCr2RGB(Raster raster, int numComponents) private static voidconvertYCCK2CMYK(Raster raster) private booleandelegateCSTypeMismatch(JFIF jfif, AdobeDCT adobeDCT, Frame startOfFrame, JPEGColorSpace sourceCSType) voiddispose()private ICC_ProfileensureDisplayProfile(ICC_Profile profile) (package private) AdobeDCT(package private) List<Application> getAppSegments(int marker, String identifier) (package private) ICC_ProfilegetEmbeddedICCProfile(boolean allowBadIndexes) private EXIFgetExif()intgetHeight(int imageIndex) getImageMetadata(int imageIndex) Default implementation that always returnsnull.getImageTypes(int imageIndex) (package private) JFIFgetJFIF()(package private) JFXXgetJFXX()intgetNumImages(boolean allowSearch) Default implementation that always returns1.intgetNumThumbnails(int imageIndex) getRawImageType(int imageIndex) (package private) FramegetSOF()(package private) static JPEGColorSpacegetSourceCSType(JFIF jfif, AdobeDCT adobeDCT, Frame startOfFrame) Default implementation that always returnsnull.intgetThumbnailHeight(int imageIndex, int thumbnailIndex) (package private) ImageReaderintgetThumbnailWidth(int imageIndex, int thumbnailIndex) intgetWidth(int imageIndex) private voidgotoImage(int imageIndex) private voidinitDelegate(boolean seekForwardOnly, boolean ignoreMetadata) private voidprivate voidinitHeader(int imageIndex) private void(package private) static intintFromBigEndian(byte[] array, int index) (package private) static voidintToBigEndian(int value, byte[] array, int index) private static voidinvertCMYK(Raster raster) private booleanprivate ApplicationlastAppSegment(int marker, String identifier) static voidprivate CompoundDirectoryprotected voidprocessWarningOccurred(String warning) read(int imageIndex, ImageReadParam param) readAsRenderedImage(int imageIndex, ImageReadParam param) booleanprivate ICC_ProfilereadICCProfileSafe(InputStream stream, boolean allowBadProfile) private BufferedImagereadImageAsRasterAndReplaceColorProfile(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 voidreadThumbnailMetadata(int imageIndex) protected voidResets all member variables.voidOverridessetInput, to allow easy access to the input, in case it is anImageInputStream.protected static voidshowIt(BufferedImage pImage, String pTitle) Methods inherited from class ImageReaderBase
assertInput, checkBounds, fakeAOI, fakeSubsampling, getDestination, hasExplicitDestination, resetMethods inherited from class 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
-
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:ImageReaderBaseResets all member variables. This method is by default invoked from:- Specified by:
resetMembersin classImageReaderBase
-
dispose
public void dispose()- Overrides:
disposein classImageReaderBase
-
getFormatName
- Overrides:
getFormatNamein classImageReader- Throws:
IOException
-
isLossless
- Throws:
IOException
-
getWidth
- Specified by:
getWidthin classImageReader- Throws:
IOException
-
getHeight
- Specified by:
getHeightin classImageReader- Throws:
IOException
-
getImageTypes
- Specified by:
getImageTypesin classImageReader- Throws:
IOException
-
getRawImageType
- Overrides:
getRawImageTypein classImageReader- Throws:
IOException
-
read
- Specified by:
readin 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:ImageReaderBaseOverridessetInput, to allow easy access to the input, in case it is anImageInputStream.- Overrides:
setInputin classImageReaderBase- Parameters:
input- theImageInputStreamor otherObjectto 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:ImageReaderBaseDefault implementation that always returns1.- Overrides:
getNumImagesin 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:
canReadRasterin classImageReader
-
readRaster
- Overrides:
readRasterin classImageReader- Throws:
IOException
-
readAsRenderedImage
- Overrides:
readAsRenderedImagein classImageReader- Throws:
IOException
-
abort
public void abort()- Overrides:
abortin classImageReader
-
getDefaultReadParam
- Overrides:
getDefaultReadParamin classImageReader
-
readerSupportsThumbnails
public boolean readerSupportsThumbnails()- Overrides:
readerSupportsThumbnailsin classImageReader
-
readThumbnailMetadata
- Throws:
IOException
-
getThumbnailReader
- Throws:
IOException
-
getNumThumbnails
- Overrides:
getNumThumbnailsin classImageReader- Throws:
IOException
-
checkThumbnailBounds
- Throws:
IOException
-
getThumbnailWidth
- Overrides:
getThumbnailWidthin classImageReader- Throws:
IOException
-
getThumbnailHeight
- Overrides:
getThumbnailHeightin classImageReader- Throws:
IOException
-
readThumbnail
- Overrides:
readThumbnailin classImageReader- Throws:
IOException
-
getImageMetadata
Description copied from class:ImageReaderBaseDefault implementation that always returnsnull.- Overrides:
getImageMetadatain classImageReaderBase- Parameters:
imageIndex- ignored, unless overridden- Returns:
null, unless overridden- Throws:
IOException- never, unless overridden.
-
getStreamMetadata
Description copied from class:ImageReaderBaseDefault implementation that always returnsnull.- Overrides:
getStreamMetadatain classImageReaderBase- Returns:
null, unless overridden- Throws:
IOException- never, unless overridden.
-
processWarningOccurred
- Overrides:
processWarningOccurredin classImageReader
-
invertCMYK
-
convertYCbCr2RGB
-
convertYCCK2CMYK
-
showIt
-
main
- Throws:
IOException
-