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 
30 class imageInfo
31 {
32  public:
33 
38  imageInfo();
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
imageInfo
Trivial class to store elementary info about bitmap graphics.
Definition: imageInfo.h:30
imageInfo::isEmpty
bool isEmpty() const
Checks if image is empty.
Definition: imageInfo.h:110
imageInfo::imageInfo
imageInfo()
Default constructor.
imageInfo::readAll
static QList< imageInfo > readAll(const QString &fileName)
Construct image infos for all images in a file.
imageInfo::error
QString error
Error string.
Definition: imageInfo.h:149
imageInfo::imageInfo
imageInfo(const QString &fileName)
Constructs an image info from a file.
Definition: imageInfo.h:57
imageInfo::imageInfo
imageInfo(const QImage &image)
Constructs an image info from a QImage.
Definition: imageInfo.h:47
imageInfo::heightInPixel
quint32 heightInPixel
Image height in pixels.
Definition: imageInfo.h:152
imageInfo::_xResolution
resolution _xResolution
Horizontal resolution of the image, in dots per inch.
Definition: imageInfo.h:161
imageInfo::numberOfColorComponents
quint8 numberOfColorComponents
Number of color components.
Definition: imageInfo.h:155
imageInfo::widthInPixel
quint32 widthInPixel
Image width in pixels.
Definition: imageInfo.h:158
imageInfo::_yResolution
resolution _yResolution
Horizontal resolution of the image, in dots per inch.
Definition: imageInfo.h:164
resolution
The resolution class stores a resolution and converts between units.
Definition: resolution.h:39
resolution::get
qreal get(unit u) const
Get numerical value for resolution.
imageInfo::yResolution
resolution yResolution() const
Horizontal resolution.
Definition: imageInfo.h:126
imageInfo::read
bool read(const QImage &image)
Reads image info from a QImage.
imageInfo::xResolution
resolution xResolution() const
Vertical resolution.
Definition: imageInfo.h:118
resolution::dpi
@ dpi
Pixel per Inch.
Definition: resolution.h:55
imageInfo::clear
void clear()
Sets all values to zero.