Enrollment 28.2.0
Loading...
Searching...
No Matches
ImageType.h
Go to the documentation of this file.
1
9#pragma once
10
11#include "enrollment/Export.h"
13#include <cstdint>
14
15namespace inno
16{
20 */
21 class ImageType
22 {
23 public:
26 */
27 enum Type : uint8_t
28 {
33 BMP,
40 PNG,
47 WSQ,
53 IRAW,
60 JPG,
66 TIFF,
77 JPG2000,
83 WEBP
84 };
86 static constexpr uint8_t UNKNOWN = 255;
87
91 */
92 constexpr explicit ImageType(Type t)
93 : type(t)
94 {
95 }
96
97 ImageType(const ImageType&) = default;
103 */
104 constexpr explicit ImageType(uint8_t t)
105 : type(Convert(t))
106 {
107 }
108
109 ImageType(ImageType&&) = default;
110 ImageType& operator=(const ImageType&) = default;
111 ImageType& operator=(ImageType&&) = default;
112 ~ImageType() = default;
113 explicit operator bool() = delete;
114 explicit constexpr operator Type() const
115 {
116 return type;
117 }
118
119 constexpr bool operator==(ImageType t) const
120 {
121 return type == t.type;
122 }
123 constexpr bool operator!=(ImageType t) const
124 {
125 return !(*this == t);
126 }
127 constexpr bool operator==(Type t) const
128 {
129 return type == t;
130 }
131 constexpr bool operator!=(Type t) const
132 {
133 return !(*this == t);
134 }
135
136 [[nodiscard]] constexpr const char* ToFileExtension() const
137 {
138 switch (type)
139 {
140 case BMP:
141 return ".bmp";
142 case PNG:
143 return ".png";
144 case WSQ:
145 return ".wsq";
146 case IRAW:
147 return ".iraw";
148 case JPG:
149 return ".jpg";
150 case TIFF:
151 return ".tiff";
152 case JPG2000:
153 return ".jp2";
154 case WEBP:
155 return ".webp";
156 }
157
158 throw ImageException(ImageException::UNKNOWN_IMAGE);
159 }
160
166 */
167 static ImageType FromFileExtension(const std::string& extension)
168 {
169 if (extension == ".bmp")
170 {
171 return ImageType{ BMP };
172 }
173
174 if (extension == ".png")
175 {
176 return ImageType{ PNG };
177 }
178
179 if (extension == ".wsq")
180 {
181 return ImageType{ WSQ };
182 }
183
184 if (extension == ".iraw")
185 {
186 return ImageType{ IRAW };
187 }
188
189 if (extension == ".jpeg" || extension == ".jpg" || extension == ".jpe")
190 {
191 return ImageType{ JPG };
192 }
193
194 if (extension == ".tiff" || extension == ".tif")
195 {
196 return ImageType{ TIFF };
197 }
198
199 if (extension == ".jp2")
200 {
201 return ImageType{ JPG2000 };
202 }
203
204 if (extension == ".webp")
205 {
206 return ImageType{ WEBP };
207 }
208
210 }
211
212 private:
213 Type type;
214
215 static constexpr Type Convert(uint8_t t)
216 {
217 switch (t)
218 {
219 case BMP:
220 return BMP;
221 case PNG:
222 return PNG;
223 case WSQ:
224 return WSQ;
225 case IRAW:
226 return IRAW;
227 case JPG:
228 return JPG;
229 case TIFF:
230 return TIFF;
231 case JPG2000:
232 return JPG2000;
233 case WEBP:
234 return WEBP;
235 default:
237 }
238 }
239 };
240} // namespace inno
Exception for image processing.
Definition ImageException.h:24
@ UNKNOWN_IMAGE
Image type is not supported.
Definition ImageException.h:35
It contains all supported image types.
Definition ImageType.h:21
constexpr ImageType(uint8_t t)
Construct ImageType from basic type When value does not match enum value then UNKNOWN is set.
Definition ImageType.h:103
static ImageType FromFileExtension(const std::string &extension)
Construct ImageType from file extension.
Definition ImageType.h:166
Type
Type of supported images.
Definition ImageType.h:27
@ JPG2000
JPEG 2000 is an image compression standard and coding system - jp2.
Definition ImageType.h:76
@ JPG
Joint Photographic Experts Group - jpeg, jpg, jpe.
Definition ImageType.h:59
@ BMP
Windows bitmaps - bmp, dib.
Definition ImageType.h:32
@ TIFF
Tagged Image File Format - tiff, tif.
Definition ImageType.h:65
@ PNG
Portable Network Graphics - png.
Definition ImageType.h:39
@ WEBP
WebP is an image file format developed by Google - webp.
Definition ImageType.h:82
@ IRAW
Innovatrics proprietary RAW image - iraw.
Definition ImageType.h:52
@ WSQ
Wavelet Scalar Quantization - wsq.
Definition ImageType.h:46
constexpr ImageType(Type t)
Construct ImageType from enum Type.
Definition ImageType.h:91
static constexpr uint8_t UNKNOWN
Unknown image type.
Definition ImageType.h:85