scantools  1.0.4
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:
34  imageInfo(imageInfo const &) = default;
35 
41 
48  // cppcheck-suppress noExplicitConstructor
49  imageInfo(const QImage &image) {
50  read(image);
51  }
52 
59  explicit imageInfo(const QString &fileName) {
60  read(fileName);
61  }
62 
64  void clear();
65 
72  bool read(const QImage &image);
73 
91  bool read(const QString &fileName);
92 
106  static QList<imageInfo> readAll(const QString &fileName);
107 
112  inline bool isEmpty() const {
113  return ((widthInPixel == 0) || (heightInPixel == 0));
114  };
115 
120  inline resolution xResolution() const {
121  return _xResolution;
122  }
123 
128  inline resolution yResolution() const {
129  return _yResolution;
130  }
131 
138  inline operator QString() const {
139  QString result;
140  if (!error.isEmpty())
141  result += QString("Error: %1; ").arg(error);
142  result += QString("Width: %1px; ").arg(widthInPixel);
143  result += QString("Height: %1px; ").arg(heightInPixel);
144  result += QString("xRes: %1dpi; ").arg(_xResolution.get(resolution::dpi));
145  result += QString("yRes: %1dpi; ").arg(_yResolution.get(resolution::dpi));
146  result += QString("color components: %1").arg(numberOfColorComponents);
147  return result;
148  }
149 
151  QString error;
152 
154  quint32 heightInPixel{};
155 
158 
160  quint32 widthInPixel{};
161 
164 
167 
168  private:
169  /* Reads info from a JPEG file, without decoding the image data. The method
170  is therefore rather inexpensive. In case of error, an error message is
171  saved in the 'error' member, all other members are set to their default
172  values, and 'false' is returned. Returns 'true' otherwise.
173  */
174  bool readJPEG(const QString &fileName);
175 
176  /* Reads info from a JPEG2000 file (in JP2 or JPX format), without decoding
177  the image data. The method is therefore rather inexpensive. In case of
178  error, an error message is saved in the 'error' member, all other members
179  are set to their default values, and 'false' is returned. Returns 'true'
180  otherwise.
181  */
182  bool readJP2(const QString &fileName);
183 };
184 
185 #endif
Trivial class to store elementary info about bitmap graphics.
Definition: imageInfo.h:31
quint32 heightInPixel
Image height in pixels.
Definition: imageInfo.h:154
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:166
imageInfo(imageInfo const &)=default
Copy constructor.
resolution yResolution() const
Horizontal resolution.
Definition: imageInfo.h:128
imageInfo(const QImage &image)
Constructs an image info from a QImage.
Definition: imageInfo.h:49
void clear()
Sets all values to zero.
imageInfo(const QString &fileName)
Constructs an image info from a file.
Definition: imageInfo.h:59
resolution xResolution() const
Vertical resolution.
Definition: imageInfo.h:120
resolution _xResolution
Horizontal resolution of the image, in dots per inch.
Definition: imageInfo.h:163
quint8 numberOfColorComponents
Number of color components.
Definition: imageInfo.h:157
QString error
Error string.
Definition: imageInfo.h:151
static QList< imageInfo > readAll(const QString &fileName)
Construct image infos for all images in a file.
bool isEmpty() const
Checks if image is empty.
Definition: imageInfo.h:112
bool read(const QString &fileName)
Read image info from an image file.
imageInfo()
Default constructor.
quint32 widthInPixel
Image width in pixels.
Definition: imageInfo.h:160
The resolution class stores a resolution and converts between units.
Definition: resolution.h:40
@ dpi
Pixel per Inch.
Definition: resolution.h:55
qreal get(unit u) const
Get numerical value for resolution.