Top Fields Constructors Methods
org.apache.pdfbox.jbig2

public Class JBIG2ImageReader

extends ImageReader
Class Inheritance
Imports
java.awt.Dimension, .Rectangle, java.awt.image.BufferedImage, .Raster, java.io.IOException, java.util.ArrayList, .Iterator, .List, javax.imageio.ImageReadParam, .ImageReader, .ImageTypeSpecifier, javax.imageio.metadata.IIOMetadata, javax.imageio.spi.ImageReaderSpi, javax.imageio.stream.ImageInputStream, org.apache.pdfbox.jbig2.err.JBIG2Exception, org.apache.pdfbox.jbig2.image.Bitmaps, .FilterType, org.apache.pdfbox.jbig2.util.cache.CacheFactory

See Also
ImageReader

Field Summary

Modifier and TypeField and Description
private JBIG2Document
document

JBIG2 document to which we delegate current work.

private JBIG2Globals
globals

Globals are JBIG2 segments for PDF wide use.

Inherited from javax.imageio.ImageReader:
availableLocalesignoreMetadatainputlocaleminIndexoriginatingProviderprogressListenersseekForwardOnlyupdateListenerswarningListenerswarningLocales

Constructor Summary

AccessConstructor and Description
public
JBIG2ImageReader(ImageReaderSpi
- The ImageReaderSpi that is invoking this constructor, or null.
originatingProvider
)

Method Summary

Modifier and TypeMethod and Description
public boolean
canReadRaster()

Overrides javax.imageio.ImageReader.canReadRaster.

Returns true if this plug-in supports reading just a Raster of pixel data.

public JBIG2ReadParam
getDefaultReadParam()

Overrides javax.imageio.ImageReader.getDefaultReadParam.

Returns a default ImageReadParam object appropriate for this format.

private JBIG2ReadParam
getDefaultReadParam(final int
- The page number.
imageIndex
)

Returns a default ImageReadParam object for a specific page.

private JBIG2Document
public JBIG2Globals

Returns:

Decoded global segments.
getGlobals
()

Returns decoded segments that has been set as globals.

public int

Returns:

The height of the specified page or 0 if an error occurred.
getHeight
(int
- The image index. In this case it is the page number.
imageIndex
)

Implements abstract javax.imageio.ImageReader.getHeight.

Calculates the height of the specified page.

public IIOMetadata

Returns:

The associated JBIG2ImageMetadata.
getImageMetadata
(int
the index of the image whose metadata is to be retrieved.
imageIndex
)

Implements abstract javax.imageio.ImageReader.getImageMetadata.

Simply returns the JBIG2ImageMetadata.

public Iterator<ImageTypeSpecifier>

Returns:

An Iterator for available image types.
getImageTypes
(int
- The page number.
imageIndex
)

Implements abstract javax.imageio.ImageReader.getImageTypes.

Returns the iterator for available image types.

public int
getNumImages(boolean
if true, the true number of images will be returned even if a search is required. If false, the reader may return -1 without performing the search.
allowSearch
)

Implements abstract javax.imageio.ImageReader.getNumImages.

Returns the number of images, not including thumbnails, available from the current input source.

private JBIG2Page
getPage(int imageIndex)

public IIOMetadata

Returns:

null at every call.
getStreamMetadata
()

Implements abstract javax.imageio.ImageReader.getStreamMetadata.

This ImageIO plugin doesn't record IIOMetadata.

public int

Returns:

The width of the specified page.
getWidth
(int
- The image index. In this case it is the page number.
imageIndex
)

Implements abstract javax.imageio.ImageReader.getWidth.

Calculates the width of the specified page.

public JBIG2Globals

Returns:

The decoded JBIG2Globals.
processGlobals
(ImageInputStream
- The input stream of globals data.
globalsInputStream
)

Decodes and returns the global segments.

public BufferedImage
read(int
the index of the image to be retrieved.
imageIndex
,
ImageReadParam
an ImageReadParam used to control the reading process, or null.
param
)

Implements abstract javax.imageio.ImageReader.read.

Returns the decoded image of specified page considering the given JBIG2ReadParams.

public Raster
readRaster(int
the index of the image to be read.
imageIndex
,
ImageReadParam
an ImageReadParam used to control the reading process, or null.
param
)

Overrides javax.imageio.ImageReader.readRaster.

Returns a new Raster object containing the raw pixel data from the image stream, without any color conversion applied.

public void
setGlobals(JBIG2Globals
- The globals to set.
globals
)

Simply sets the globals.

public void
setInput(Object
the ImageInputStream or other Object to use for future decoding.
input
,
boolean
if true, images and metadata may only be read in ascending order from this input source.
seekForwardOnly
,
boolean
if true, metadata may be ignored during reads.
ignoreMetadata
)

Overrides javax.imageio.ImageReader.setInput.

Sets the input source to use to the given ImageInputStream or other Object.

Inherited from javax.imageio.ImageReader:
abortabortRequestedaddIIOReadProgressListeneraddIIOReadUpdateListeneraddIIOReadWarningListenercheckReadParamBandSettingsclearAbortRequestcomputeRegionsdisposegetAspectRatiogetAvailableLocalesgetDestinationgetFormatNamegetImageMetadatagetInputgetLocalegetMinIndexgetNumThumbnailsgetOriginatingProvidergetRawImageTypegetSourceRegiongetStreamMetadatagetThumbnailHeightgetThumbnailWidthgetTileGridXOffsetgetTileGridYOffsetgetTileHeightgetTileWidthhasThumbnailsisIgnoringMetadataisImageTiledisRandomAccessEasyisSeekForwardOnlyprocessImageCompleteprocessImageProgressprocessImageStartedprocessImageUpdateprocessPassCompleteprocessPassStartedprocessReadAbortedprocessSequenceCompleteprocessSequenceStartedprocessThumbnailCompleteprocessThumbnailPassCompleteprocessThumbnailPassStartedprocessThumbnailProgressprocessThumbnailStartedprocessThumbnailUpdateprocessWarningOccurredprocessWarningOccurredreadreadAllreadAllreadAsRenderedImagereaderSupportsThumbnailsreadThumbnailreadTilereadTileRasterremoveAllIIOReadProgressListenersremoveAllIIOReadUpdateListenersremoveAllIIOReadWarningListenersremoveIIOReadProgressListenerremoveIIOReadUpdateListenerremoveIIOReadWarningListenerresetsetInputsetInputsetLocale

Field Detail

documentback to summary
private JBIG2Document document

JBIG2 document to which we delegate current work.

globalsback to summary
private JBIG2Globals globals

Globals are JBIG2 segments for PDF wide use.

Constructor Detail

JBIG2ImageReaderback to summary
public JBIG2ImageReader(ImageReaderSpi originatingProvider) throws IOException
Parameters
originatingProvider:ImageReaderSpi

- The ImageReaderSpi that is invoking this constructor, or null.

Exceptions
IOException:
if something went wrong while reading the provided stream.
See Also
ImageReader#ImageReader(ImageReaderSpi)

Method Detail

canReadRasterback to summary
public boolean canReadRaster()

Overrides javax.imageio.ImageReader.canReadRaster.

Doc from javax.imageio.ImageReader.canReadRaster.

Returns true if this plug-in supports reading just a Raster of pixel data. If this method returns false, calls to readRaster or readTileRaster will throw an UnsupportedOperationException.

The default implementation returns false.

Returns:boolean

true if this plug-in supports reading raw Rasters.

Annotations
@Override
getDefaultReadParamback to summary
public JBIG2ReadParam getDefaultReadParam()

Overrides javax.imageio.ImageReader.getDefaultReadParam.

Doc from javax.imageio.ImageReader.getDefaultReadParam.

Returns a default ImageReadParam object appropriate for this format. All subclasses should define a set of default values for all parameters and return them with this call. This method may be called before the input source is set.

The default implementation constructs and returns a new ImageReadParam object that does not allow source scaling (i.e., it returns new ImageReadParam().

Returns:JBIG2ReadParam

an ImageReadParam object which may be used to control the decoding process using a set of default settings.

Annotations
@Override
See Also
ImageReader#getDefaultReadParam()
getDefaultReadParamback to summary
private JBIG2ReadParam getDefaultReadParam(final int imageIndex)

Returns a default ImageReadParam object for a specific page.

Parameters
imageIndex:int

- The page number.

getDocumentback to summary
private JBIG2Document getDocument() throws IOException
getGlobalsback to summary
public JBIG2Globals getGlobals() throws IOException

Returns decoded segments that has been set as globals. Globals are jbig2 segments that are used in embedded case for file wide access. They are not assigned to a specific page.

Returns:JBIG2Globals

Decoded global segments.

Exceptions
IOException:
if an error occurs reading the height information from the input source.
getHeightback to summary
public int getHeight(int imageIndex) throws IOException

Implements abstract javax.imageio.ImageReader.getHeight.

Calculates the height of the specified page.

Parameters
imageIndex:int

- The image index. In this case it is the page number.

Returns:int

The height of the specified page or 0 if an error occurred.

Annotations
@Override
Exceptions
IOException:
if an error occurs reading the height information from the input source.
getImageMetadataback to summary
public IIOMetadata getImageMetadata(int imageIndex) throws IOException

Implements abstract javax.imageio.ImageReader.getImageMetadata.

Simply returns the JBIG2ImageMetadata.

Parameters
imageIndex:int

Doc from javax.imageio.ImageReader.getImageMetadata.

the index of the image whose metadata is to be retrieved.

Returns:IIOMetadata

The associated JBIG2ImageMetadata.

Annotations
@Override
Exceptions
IOException:
if an error occurs reading the height information from the input source.
getImageTypesback to summary
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException

Implements abstract javax.imageio.ImageReader.getImageTypes.

Returns the iterator for available image types.

Parameters
imageIndex:int

- The page number.

Returns:Iterator<ImageTypeSpecifier>

An Iterator for available image types.

Annotations
@Override
Exceptions
IOException:
if an error occurs reading the height information from the input source.
getNumImagesback to summary
public int getNumImages(boolean allowSearch) throws IOException

Implements abstract javax.imageio.ImageReader.getNumImages.

Doc from javax.imageio.ImageReader.getNumImages.

Returns the number of images, not including thumbnails, available from the current input source.

Note that some image formats (such as animated GIF) do not specify how many images are present in the stream. Thus determining the number of images will require the entire stream to be scanned and may require memory for buffering. If images are to be processed in order, it may be more efficient to simply call read with increasing indices until an IndexOutOfBoundsException is thrown to indicate that no more images are available. The allowSearch parameter may be set to false to indicate that an exhaustive search is not desired; the return value will be -1 to indicate that a search is necessary. If the input has been specified with seekForwardOnly set to true, this method throws an IllegalStateException if allowSearch is set to true.

Parameters
allowSearch:boolean

if true, the true number of images will be returned even if a search is required. If false, the reader may return -1 without performing the search.

Returns:int

the number of images, as an int, or -1 if allowSearch is false and a search would be required.

Annotations
@Override
Exceptions
IOException:
if an error occurs reading the information from the input source.
See Also
ImageReader#getNumImages(boolean)
getPageback to summary
private JBIG2Page getPage(int imageIndex) throws IOException
getStreamMetadataback to summary
public IIOMetadata getStreamMetadata()

Implements abstract javax.imageio.ImageReader.getStreamMetadata.

This ImageIO plugin doesn't record IIOMetadata.

Returns:IIOMetadata

null at every call.

Annotations
@Override
getWidthback to summary
public int getWidth(int imageIndex) throws IOException

Implements abstract javax.imageio.ImageReader.getWidth.

Calculates the width of the specified page.

Parameters
imageIndex:int

- The image index. In this case it is the page number.

Returns:int

The width of the specified page.

Annotations
@Override
Exceptions
IOException:
if an error occurs reading the width information from the input source.
processGlobalsback to summary
public JBIG2Globals processGlobals(ImageInputStream globalsInputStream) throws IOException

Decodes and returns the global segments.

Parameters
globalsInputStream:ImageInputStream

- The input stream of globals data.

Returns:JBIG2Globals

The decoded JBIG2Globals.

Exceptions
IOException:
if an error occurs reading the height information from the input source.
readback to summary
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException

Implements abstract javax.imageio.ImageReader.read.

Returns the decoded image of specified page considering the given JBIG2ReadParams.

Parameters
imageIndex:int

Doc from javax.imageio.ImageReader.read.

the index of the image to be retrieved.

param:ImageReadParam

Doc from javax.imageio.ImageReader.read.

an ImageReadParam used to control the reading process, or null.

Returns:BufferedImage

Doc from javax.imageio.ImageReader.read.

the desired portion of the image as a BufferedImage.

Annotations
@Override
Exceptions
IOException:

Doc from javax.imageio.ImageReader.read.

if an error occurs during reading.

See Also
ImageReader#read(int, ImageReadParam)
readRasterback to summary
public Raster readRaster(int imageIndex, ImageReadParam param) throws IOException

Overrides javax.imageio.ImageReader.readRaster.

Doc from javax.imageio.ImageReader.readRaster.

Returns a new Raster object containing the raw pixel data from the image stream, without any color conversion applied. The application must determine how to interpret the pixel data by other means. Any destination or image-type parameters in the supplied ImageReadParam object are ignored, but all other parameters are used exactly as in the read method, except that any destination offset is used as a logical rather than a physical offset. The size of the returned Raster will always be that of the source region clipped to the actual image. Logical offsets in the stream itself are ignored.

This method allows formats that normally apply a color conversion, such as JPEG, and formats that do not normally have an associated colorspace, such as remote sensing or medical imaging data, to provide access to raw pixel data.

Any registered readUpdateListeners are ignored, as there is no BufferedImage, but all other listeners are called exactly as they are for the read method.

If canReadRaster() returns false, this method throws an UnsupportedOperationException.

If the supplied ImageReadParam contains optional setting values not supported by this reader (e.g. source render size or any format-specific settings), they will be ignored.

The default implementation throws an UnsupportedOperationException.

Parameters
imageIndex:int

the index of the image to be read.

param:ImageReadParam

an ImageReadParam used to control the reading process, or null.

Returns:Raster

the desired portion of the image as a Raster.

Annotations
@Override
Exceptions
IOException:
if an error occurs during reading.
setGlobalsback to summary
public void setGlobals(JBIG2Globals globals) throws IOException

Simply sets the globals.

Parameters
globals:JBIG2Globals

- The globals to set.

Exceptions
IOException:
if an error occurs
setInputback to summary
public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)

Overrides javax.imageio.ImageReader.setInput.

Doc from javax.imageio.ImageReader.setInput.

Sets the input source to use to the given ImageInputStream or other Object. The input source must be set before any of the query or read methods are used. If input is null, any currently set input source will be removed. In any case, the value of minIndex will be initialized to 0.

The seekForwardOnly parameter controls whether the value returned by getMinIndex will be increased as each image (or thumbnail, or image metadata) is read. If seekForwardOnly is true, then a call to read(index) will throw an IndexOutOfBoundsException if index < this.minIndex; otherwise, the value of minIndex will be set to index. If seekForwardOnly is false, the value of minIndex will remain 0 regardless of any read operations.

The ignoreMetadata parameter, if set to true, allows the reader to disregard any metadata encountered during the read. Subsequent calls to the getStreamMetadata and getImageMetadata methods may return null, and an IIOImage returned from readAll may return null from their getMetadata method. Setting this parameter may allow the reader to work more efficiently. The reader may choose to disregard this setting and return metadata normally.

Subclasses should take care to remove any cached information based on the previous stream, such as header information or partially decoded image data.

Use of a general Object other than an ImageInputStream is intended for readers that interact directly with a capture device or imaging protocol. The set of legal classes is advertised by the reader's service provider's getInputTypes method; most readers will return a single-element array containing only ImageInputStream.class to indicate that they accept only an ImageInputStream.

The default implementation checks the input argument against the list returned by originatingProvider.getInputTypes() and fails if the argument is not an instance of one of the classes in the list. If the originating provider is set to null, the input is accepted only if it is an ImageInputStream.

Parameters
input:Object

the ImageInputStream or other Object to use for future decoding.

seekForwardOnly:boolean

if true, images and metadata may only be read in ascending order from this input source.

ignoreMetadata:boolean

if true, metadata may be ignored during reads.

Annotations
@Override
See Also
ImageReader#setInput(Object, boolean, boolean)