scantools 1.0.8
Graphics manipulation with a view towards scanned documents
JBIG2Document.h
1/*
2 * Copyright © 2016-2018 Stefan Kebekus <stefan.kebekus@math.uni-freiburg.de>
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation, either version 3 of the License, or (at your option) any later
7 * version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19#ifndef JBIG2DOCUMENT
20#define JBIG2DOCUMENT 1
21
22#include <QSet>
23
24#include "imageInfo.h"
25#include "JBIG2Segment.h"
26
27
40{
41 public:
43 inline JBIG2Document() {clear();};
44
52 explicit inline JBIG2Document(QIODevice *device) {read(device);};
53
61 explicit inline JBIG2Document(QString fileName) {read(fileName);};
62
67 void clear();
68
82 void read(QIODevice *device);
83
84
92 void read(const QString& fileName);
93
94
99 inline bool isEmpty() const
100 {
101 QListIterator<JBIG2Segment> i(segments);
102 while (i.hasNext()) {
103 quint32 number = i.next().pageAssociation();
104 if (number != 0)
105 return false;
106 }
107 return true;
108 };
109
115 inline bool hasError() const {return !_error.isEmpty();};
116
122 inline QString error() const {return _error; };
123
131 inline bool hasWarnings() const {return !_warnings.isEmpty();};
132
137 inline QSet<QString> warnings() const {return _warnings;};
138
143 QList<quint32> pageNumbers() const;
144
145
153 QString info() const;
154
155
171 QByteArray getPDFDataChunk(quint32 pageNumber) const;
172
173
190 imageInfo pageInfo(quint32 pageNumber) const;
191
198 QImage operator[](quint32 pageNumber) const;
199
200 private:
201 // Checks for fixable errors, fixes them, and sets '_warnings' accordingly
202 void check_n_fix();
203
204 // Helper function for image rendering
205 static void myImageCleanupHandler(void *info);
206
207 // Returns list of numbers of those segements that refer to given
208 // segmentNumber
209 QList<quint32> referrers(quint32 segmentNumber);
210
211 // Warnings
212 QSet<QString> _warnings;
213
214 // Error
215 QString _error;
216
217 // List of segments that make up the JBIG2 file
218 QList<JBIG2Segment> segments;
219};
220
221#endif
Reads, writes and renders JBIG2 files, and chops them into pieces for inclusion into a PDF document.
void read(QIODevice *device)
Reads a JBIG2 document from a QIODevice.
bool isEmpty() const
Checks if the document is empty.
QString info() const
Human-readable info string about the document.
bool hasError() const
Error status.
QByteArray getPDFDataChunk(quint32 pageNumber) const
Return data ready for inclusion into a PDF file.
QString error() const
Error message.
JBIG2Document(QString fileName)
Constructs a JBIG2 document from a file.
JBIG2Document()
Creates an empty JBIG2 document.
bool hasWarnings() const
Warning status.
void clear()
Resets the document.
JBIG2Document(QIODevice *device)
Constructs a JBIG2 document from a QIODevice.
QImage operator[](quint32 pageNumber) const
Render image.
QSet< QString > warnings() const
Warning messages.
imageInfo pageInfo(quint32 pageNumber) const
Compute imageInfo describing a given page.
QList< quint32 > pageNumbers() const
Page numbers used by this document.
void read(const QString &fileName)
Reads a JBIG2 document from a file.
Trivial class to store elementary info about bitmap graphics.
Definition imageInfo.h:31