scantools 1.0.8
Graphics manipulation with a view towards scanned documents
imageInfo.h
1/*
2 * Copyright © 2017--2020 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 imageINFO
20#define imageINFO 1
21
22#include <QImage>
23#include <QString>
24
25#include "resolution.h"
26
27
29
31{
32 public:
33
39
46 // cppcheck-suppress noExplicitConstructor
47 imageInfo(const QImage &image) {
48 read(image);
49 }
50
57 explicit imageInfo(const QString &fileName) {
58 read(fileName);
59 }
60
62 void clear();
63
70 bool read(const QImage &image);
71
89 bool read(const QString &fileName);
90
104 static QList<imageInfo> readAll(const QString &fileName);
105
110 inline bool isEmpty() const {
111 return ((widthInPixel == 0) || (heightInPixel == 0));
112 };
113
118 inline resolution xResolution() const {
119 return _xResolution;
120 }
121
126 inline resolution yResolution() const {
127 return _yResolution;
128 }
129
136 inline operator QString() const {
137 QString result;
138 if (!error.isEmpty())
139 result += QString("Error: %1; ").arg(error);
140 result += QString("Width: %1px; ").arg(widthInPixel);
141 result += QString("Height: %1px; ").arg(heightInPixel);
142 result += QString("xRes: %1dpi; ").arg(_xResolution.get(resolution::dpi));
143 result += QString("yRes: %1dpi; ").arg(_yResolution.get(resolution::dpi));
144 result += QString("color components: %1").arg(numberOfColorComponents);
145 return result;
146 }
147
149 QString error;
150
152 quint32 heightInPixel{};
153
156
158 quint32 widthInPixel{};
159
162
165
166 private:
167 /* Reads info from a JPEG file, without decoding the image data. The method
168 is therefore rather inexpensive. In case of error, an error message is
169 saved in the 'error' member, all other members are set to their default
170 values, and 'false' is returned. Returns 'true' otherwise.
171 */
172 bool readJPEG(const QString &fileName);
173
174 /* Reads info from a JPEG2000 file (in JP2 or JPX format), without decoding
175 the image data. The method is therefore rather inexpensive. In case of
176 error, an error message is saved in the 'error' member, all other members
177 are set to their default values, and 'false' is returned. Returns 'true'
178 otherwise.
179 */
180 bool readJP2(const QString &fileName);
181};
182
183#endif
quint32 heightInPixel
Image height in pixels.
Definition imageInfo.h:152
bool read(const QImage &image)
Reads image info from a QImage.
resolution _yResolution
Horizontal resolution of the image, in dots per inch.
Definition imageInfo.h:164
resolution yResolution() const
Horizontal resolution.
Definition imageInfo.h:126
imageInfo(const QImage &image)
Constructs an image info from a QImage.
Definition imageInfo.h:47
void clear()
Sets all values to zero.
imageInfo(const QString &fileName)
Constructs an image info from a file.
Definition imageInfo.h:57
resolution xResolution() const
Vertical resolution.
Definition imageInfo.h:118
resolution _xResolution
Horizontal resolution of the image, in dots per inch.
Definition imageInfo.h:161
quint8 numberOfColorComponents
Number of color components.
Definition imageInfo.h:155
QString error
Error string.
Definition imageInfo.h:149
bool isEmpty() const
Checks if image is empty.
Definition imageInfo.h:110
bool read(const QString &fileName)
Read image info from an image file.
imageInfo()
Default constructor.
quint32 widthInPixel
Image width in pixels.
Definition imageInfo.h:158
static QList< imageInfo > readAll(const QString &fileName)
Construct image infos for all images in a file.
The resolution class stores a resolution and converts between units.
Definition resolution.h:40
@ dpi
Pixel per Inch.
Definition resolution.h:55