1 /************************************************************************
2  *									*
3  *  This file is part of Kooka, a scanning/OCR application using	*
4  *  Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>.	*
5  *									*
6  *  Copyright (C) 2004-2016 Klaas Freitag <freitag@suse.de>		*
7  *                          Jonathan Marten <jjm@keelhaul.me.uk>	*
8  *									*
9  *  Kooka is free software; you can redistribute it and/or modify it	*
10  *  under the terms of the GNU Library General Public License as	*
11  *  published by the Free Software Foundation and appearing in the	*
12  *  file COPYING included in the packaging of this file;  either	*
13  *  version 2 of the License, or (at your option) any later version.	*
14  *									*
15  *  As a special exception, permission is given to link this program	*
16  *  with any version of the KADMOS OCR/ICR engine (a product of		*
17  *  reRecognition GmbH, Kreuzlingen), and distribute the resulting	*
18  *  executable without including the source code for KADMOS in the	*
19  *  source distribution.						*
20  *									*
21  *  This program is distributed in the hope that it will be useful,	*
22  *  but WITHOUT ANY WARRANTY; without even the implied warranty of	*
23  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	*
24  *  GNU General Public License for more details.			*
25  *									*
26  *  You should have received a copy of the GNU General Public		*
27  *  License along with this program;  see the file COPYING.  If		*
28  *  not, see <http://www.gnu.org/licenses/>.				*
29  *									*
30  ************************************************************************/
31 
32 #ifndef IMAGEMETAINFO_H
33 #define IMAGEMETAINFO_H
34 
35 #include "kookascan_export.h"
36 
37 #include <qstring.h>
38 
39 class QImage;
40 
41 /**
42  * @short Image meta-information.
43  *
44  * Information about an image which may be useful to an application, but
45  * is not stored with or is not readily available from a @c QImage.
46  *
47  * @author Klaas Freitag
48  * @author Jonathan Marten
49  **/
50 
51 class KOOKASCAN_EXPORT ImageMetaInfo
52 {
53 public:
54 
55     /**
56      * An image type.  This is not the detailed format of the image
57      * data (which is available via @c QImage::Format), but a general
58      * category which an application or its user will be interested in.
59      **/
60     enum ImageType
61     {
62         Unknown     = 0x00,				///< Unknown or not resolved yet
63         None        = Unknown,				///< None specified
64         BlackWhite  = 0x01,				///< Black/white bitmap
65         Greyscale   = 0x02,				///< Grey scale (indexed with palette)
66         LowColour   = 0x04,				///< Low colour (indexed with palette)
67         HighColour  = 0x08,				///< High colour (RGB)
68         Preview     = 0x10,				///< A preview image (application defined)
69         Thumbnail   = 0x20				///< A thumbnail image (application defined)
70     };
71     Q_DECLARE_FLAGS(ImageTypes, ImageType)
72 
73     /**
74      * Constructor.
75      *
76      * The image type is initialised to @c Unknown, and the
77      * X and Y resolutions to -1.
78      **/
79     explicit ImageMetaInfo();
80 
81     // TODO: can use QImage::text(key,value) to replace this?
82     /**
83      * Set the X resolution of the image.
84      *
85      * @param res The new X resolution
86      * @see getXResolution
87      **/
setXResolution(int res)88     void setXResolution(int res)
89     {
90         m_xRes = res;
91     }
92 
93     /**
94      * Set the Y resolution of the image.
95      *
96      * @param res The new Y resolution
97      * @see getYResolution
98      **/
setYResolution(int res)99     void setYResolution(int res)
100     {
101         m_yRes = res;
102     }
103 
104     /**
105      * Set the mode of the image.
106      *
107      * This is intended to be a user readable description.
108      *
109      * @param mode The new mode string
110      * @see getMode
111      **/
setMode(const QString & mode)112     void setMode(const QString &mode)
113     {
114         m_mode = mode;
115     }
116 
117     /**
118      * Set the name of the scanner that was used to generate the image.
119      *
120      * @param scanner The new scanner name
121      * @see getScannerName
122      **/
setScannerName(const QByteArray & scanner)123     void setScannerName(const QByteArray &scanner)
124     {
125         m_scanner = scanner;
126     }
127 
128     /**
129      * Set the image type.
130      *
131      * @param type The new image type
132      * @see getImageType
133      **/
setImageType(ImageMetaInfo::ImageType type)134     void setImageType(ImageMetaInfo::ImageType type)
135     {
136         m_type = type;
137     }
138 
139     /**
140      * Get the X resolution of the image.
141      *
142      * @return The X resolution, or -1 if it has not been set.
143      * @see setXResolution
144      **/
getXResolution()145     int getXResolution() const
146     {
147         return (m_xRes);
148     }
149 
150     /**
151      * Get the Y resolution of the image.
152      *
153      * @return The Y resolution, or -1 if it has not been set.
154      * @see setYResolution
155      **/
getYResolution()156     int getYResolution() const
157     {
158         return (m_yRes);
159     }
160 
161     /**
162      * Get the mode description of the image.
163      *
164      * @return The mode string
165      * @see setMode
166      **/
getMode()167     QString getMode() const
168     {
169         return (m_mode);
170     }
171 
172     /**
173      * Get the scanner name for the image.
174      *
175      * @return The scanner name
176      * @see setScannerName
177      **/
getScannerName()178     QByteArray getScannerName() const
179     {
180         return (m_scanner);
181     }
182 
183     /**
184      * Get the image type.
185      *
186      * @return The set image type.
187      * @see setImageType
188      **/
getImageType()189     ImageMetaInfo::ImageType getImageType() const
190     {
191         return (m_type);
192     }
193 
194     /**
195      * Deduce the image type for an image.
196      *
197      * @param image The image to examine
198      * @return The image type
199      *
200      * @note This will never return the type as @c Preview or @c Thumbnail.
201      **/
202     static ImageType findImageType(const QImage *image);
203 
204 private:
205     int m_xRes;
206     int m_yRes;
207     QString m_mode;
208     QByteArray m_scanner;
209     ImageMetaInfo::ImageType m_type;
210 };
211 
212 Q_DECLARE_OPERATORS_FOR_FLAGS(ImageMetaInfo::ImageTypes)
213 
214 #endif							// IMAGEMETAINFO_H
215