scantools  1.0.4
Graphics manipulation with a view towards scanned documents
Public Member Functions | List of all members
JBIG2Document Class Reference

Reads, writes and renders JBIG2 files, and chops them into pieces for inclusion into a PDF document. More...

#include <JBIG2Document.h>

Public Member Functions

 JBIG2Document ()
 Creates an empty JBIG2 document.
 
 JBIG2Document (QIODevice *device)
 Constructs a JBIG2 document from a QIODevice. More...
 
 JBIG2Document (QString fileName)
 Constructs a JBIG2 document from a file. More...
 
void clear ()
 Resets the document. More...
 
void read (QIODevice *device)
 Reads a JBIG2 document from a QIODevice. More...
 
void read (const QString &fileName)
 Reads a JBIG2 document from a file. More...
 
bool isEmpty () const
 Checks if the document is empty. More...
 
bool hasError () const
 Error status. More...
 
QString error () const
 Error message. More...
 
bool hasWarnings () const
 Warning status. More...
 
QSet< QString > warnings () const
 Warning messages. More...
 
QList< quint32 > pageNumbers () const
 Page numbers used by this document. More...
 
QString info () const
 Human-readable info string about the document. More...
 
QByteArray getPDFDataChunk (quint32 pageNumber) const
 Return data ready for inclusion into a PDF file. More...
 
imageInfo pageInfo (quint32 pageNumber) const
 Compute imageInfo describing a given page. More...
 
QImage operator[] (quint32 pageNumber) const
 Render image. More...
 

Detailed Description

Reads, writes and renders JBIG2 files, and chops them into pieces for inclusion into a PDF document.

This class reads, interprets and renders JBIG2 image files. There exists minimal support for file validation, inspection and manipulation. The main use of this class is to chop JBIG2 files into pieces which can then be included into a PDF file.

The methods of this class are reentrant, but not thread safe.

Definition at line 39 of file JBIG2Document.h.

Constructor & Destructor Documentation

◆ JBIG2Document() [1/2]

JBIG2Document::JBIG2Document ( QIODevice *  device)
inlineexplicit

Constructs a JBIG2 document from a QIODevice.

This is a convenience constructor that constructs an empty document and calls read(device).

Parameters
devicePointer to a QIODevice from which the file is read

Definition at line 52 of file JBIG2Document.h.

◆ JBIG2Document() [2/2]

JBIG2Document::JBIG2Document ( QString  fileName)
inlineexplicit

Constructs a JBIG2 document from a file.

This is a convenience constructor that constructs an empty document, opens a file and calls read(QIODevice *device).

Parameters
fileNameName of the JBIG2 file

Definition at line 61 of file JBIG2Document.h.

Member Function Documentation

◆ clear()

void JBIG2Document::clear ( )

Resets the document.

This method clears all errors, warnings, and any file content.

◆ error()

QString JBIG2Document::error ( ) const
inline

Error message.

Returns
An empty string if read() succeeded. Otherwise, this method returns a description of the error in enlish language.

Definition at line 122 of file JBIG2Document.h.

◆ getPDFDataChunk()

QByteArray JBIG2Document::getPDFDataChunk ( quint32  pageNumber) const

Return data ready for inclusion into a PDF file.

This method returns a concatenation of all JBIG2 segments pertaining to a given page. Following the PDF specification, all end-of-page segements are removed, and all page associations other than '0' are set to '1'. This method must not be called when an error condition exists. Use hasError() or error() to check the error status first.

Parameters
pageNumberIf zero, the method returns the global data, which is used by all pages of the document. If larger than zero, the method returns the data for the given page.
Returns
A QByteArray containg the data, or an empty array if no data could be found.

◆ hasError()

bool JBIG2Document::hasError ( ) const
inline

Error status.

Returns
True if read() terminated with an error. In that case, an error description can be retrieved using the error() method.

Definition at line 115 of file JBIG2Document.h.

◆ hasWarnings()

bool JBIG2Document::hasWarnings ( ) const
inline

Warning status.

Returns
True if read() found issues in the JBIG2 file that could be fixed. For instance, Google's 'jbig2' encoder is known to produce JBIG2 files that contain segements whose 'retain bit for this segment' contains wrong values.

Definition at line 131 of file JBIG2Document.h.

◆ info()

QString JBIG2Document::info ( ) const

Human-readable info string about the document.

This method is mainly useful for debugging purposes.

Returns
A QString with text describing the document. Lines are separated by newline characters, '
'.

◆ isEmpty()

bool JBIG2Document::isEmpty ( ) const
inline

Checks if the document is empty.

Returns
True if the document does not contain any pages.

Definition at line 99 of file JBIG2Document.h.

◆ operator[]()

QImage JBIG2Document::operator[] ( quint32  pageNumber) const

Render image.

Parameters
pageNumberNumber of the page that rendered
Returns
A QImage with the rendered page, or a null image in case of error

◆ pageInfo()

imageInfo JBIG2Document::pageInfo ( quint32  pageNumber) const

Compute imageInfo describing a given page.

  • Resolutions are set to zero if they are not specified in the JBIG2 file, of if the resolution is specified, but falls out of the bounds given by resolution::minResDPI and resolution::maxResDPI.
  • If the page does not exist, or if no "page info segment" could be found in the JBIG2 data, and empty bitmap info is returned.
Warning
This method must not be called when an error condition exists. Use hasError() or error() to check the error status first.
Parameters
pageNumberNumber of the page that will be described
Returns
imageInfo that describes the given page.

◆ pageNumbers()

QList<quint32> JBIG2Document::pageNumbers ( ) const

Page numbers used by this document.

Returns
List of page numbers that appear in this document

◆ read() [1/2]

void JBIG2Document::read ( const QString &  fileName)

Reads a JBIG2 document from a file.

This is a convenience method that opens a file and calls read(QIODevice device).

Parameters
fileNameName of the JBIG2 file

◆ read() [2/2]

void JBIG2Document::read ( QIODevice *  device)

Reads a JBIG2 document from a QIODevice.

This method clears the document, and reads a JBIG2 file from a QIODevice. After method returns, the caller shoud check if an error occurred, by using the methods hasError() and/or error(). The caller might also wish to check if the file contained fixable errors, by calling the method warnings().

The absense of an error or of warnings does not imply that the JBIG2 file is valid. In fact, only minimal checks are made.

Parameters
deviceQIODevice from which the file should be read

◆ warnings()

QSet<QString> JBIG2Document::warnings ( ) const
inline

Warning messages.

Returns
A list descriptions of fixable issues found in the JBIG2 file.

Definition at line 137 of file JBIG2Document.h.


The documentation for this class was generated from the following file: