Friction Ridge Image and Features Technology Evaluations
API for participating in NIST's Friction Ridge Image and Features Technology Evaluations.
Loading...
Searching...
No Matches
libfrifte_common.cpp
Go to the documentation of this file.
1/*
2 * This software was developed at the National Institute of Standards and
3 * Technology (NIST) by employees of the Federal Government in the course
4 * of their official duties. Pursuant to title 17 Section 105 of the
5 * United States Code, this software is not subject to copyright protection
6 * and is in the public domain. NIST assumes no responsibility whatsoever for
7 * its use by other parties, and makes no guarantees, expressed or implied,
8 * about its quality, reliability, or any other characteristic.
9 */
10
11#include <exception>
12
13#include <frifte/common.h>
14
16 const uint32_t x_,
17 const uint32_t y_) :
18 x{x_},
19 y{y_}
20{
21
22}
23
24auto
26 const FRIF::Coordinate&)
27 const = default;
28
29bool
31 const FRIF::Coordinate&)
32 const = default;
33
34auto
37 const = default;
38
39bool
42 const = default;
43
44auto
47 const = default;
48
49bool
52 const = default;
53
54FRIF::ReturnStatus::operator bool()
55 const
56 noexcept
57{
58 return (this->result == Result::Success);
59}
60
61static std::string imagePropertiesString(const FRIF::Image &image)
62{
63 return {std::to_string(image.width) + 'x' +
64 std::to_string(image.height) + ", colorspace = " +
65 std::to_string(static_cast<std::underlying_type_t<
66 FRIF::Image::Colorspace>>(image.colorspace)) + ", bpc = " +
67 std::to_string(static_cast<std::underlying_type_t<
68 FRIF::Image::BitsPerChannel>>(image.bpc)) + ", bpp = " +
69 std::to_string(static_cast<std::underlying_type_t<
71}
72
73FRIF::Image::Image() = default;
75 const uint8_t identifier_,
76 const uint16_t width_,
77 const uint16_t height_,
78 const uint16_t ppi_,
79 const Colorspace colorspace_,
80 const BitsPerChannel bpc_,
81 const BitsPerPixel bpp_,
82 const std::vector<std::byte> &pixels_) :
83 identifier{identifier_},
84 width{width_},
85 height{height_},
86 ppi{ppi_},
87 colorspace{colorspace_},
88 bpc{bpc_},
89 bpp{bpp_},
90 pixels{pixels_}
91{
92
93}
94
97 const std::underlying_type_t<BitsPerPixel> i)
98{
99 switch (static_cast<BitsPerPixel>(i)) {
100 case BitsPerPixel::Eight:
101 [[fallthrough]];
102 case BitsPerPixel::Sixteen:
103 [[fallthrough]];
104 case BitsPerPixel::TwentyFour:
105 [[fallthrough]];
106 case BitsPerPixel::FortyEight:
107 return (static_cast<BitsPerPixel>(i));
108 default:
109 throw std::runtime_error{"Invalid BitsPerPixel value: " +
110 std::to_string(i)};
111 }
112}
113
116 const std::underlying_type_t<BitsPerChannel> i)
117{
118 switch (static_cast<BitsPerChannel>(i)) {
119 case BitsPerChannel::Eight:
120 [[fallthrough]];
121 case BitsPerChannel::Sixteen:
122 return (static_cast<BitsPerChannel>(i));
123 default:
124 throw std::runtime_error{"Invalid BitsPerChannel value: " +
125 std::to_string(i)};
126 }
127}
128
129void
131 const
132{
133 if (this->width == 0 || this->height == 0)
134 throw std::logic_error{"Unexpected dimensions (" +
135 imagePropertiesString(*this) + ')'};
136
137 decltype(pixels.size()) expected{};
138 switch (colorspace) {
139 case Colorspace::Grayscale:
140 switch (bpc) {
141 case BitsPerChannel::Sixteen:
142 switch (bpp) {
143 case BitsPerPixel::Sixteen:
144 break;
145
146 case BitsPerPixel::Eight:
147 [[fallthrough]];
148 case BitsPerPixel::TwentyFour:
149 [[fallthrough]];
150 case BitsPerPixel::FortyEight:
151 throw std::logic_error{"Unexpected "
152 "combination (" +
153 imagePropertiesString(*this) + ')'};
154 }
155
156 expected = width * height * 2ul;
157 if (pixels.size() != expected)
158 throw std::logic_error{"Unexpected pixel "
159 "length (expected = " +
160 std::to_string(expected) +", actual = " +
161 std::to_string(pixels.size()) + ')'};
162
163 return;
164 case BitsPerChannel::Eight:
165 switch (bpp) {
166 case BitsPerPixel::Eight:
167 break;
168
169 case BitsPerPixel::Sixteen:
170 [[fallthrough]];
171 case BitsPerPixel::TwentyFour:
172 [[fallthrough]];
173 case BitsPerPixel::FortyEight:
174 throw std::logic_error{"Unexpected "
175 "combination (" +
176 imagePropertiesString(*this) + ')'};
177 }
178
179 expected = width * height;
180 if (pixels.size() != expected)
181 throw std::logic_error{"Unexpected pixel "
182 "length (expected = " +
183 std::to_string(expected) +", actual = " +
184 std::to_string(this->pixels.size()) + ')'};
185
186 return;
187 }
188 break;
189
190 case Colorspace::RGB:
191 switch (bpc) {
192 case BitsPerChannel::Sixteen:
193 switch (bpp) {
194 case BitsPerPixel::FortyEight:
195 break;
196
197 case BitsPerPixel::Eight:
198 [[fallthrough]];
199 case BitsPerPixel::Sixteen:
200 [[fallthrough]];
201 case BitsPerPixel::TwentyFour:
202 throw std::logic_error{"Unexpected "
203 "combination (" +
204 imagePropertiesString(*this) + ')'};
205 }
206
207 expected = width * height * (3ul * 2ul);
208 if (pixels.size() != expected)
209 throw std::logic_error{"Unexpected pixel "
210 "length (expected = " +
211 std::to_string(expected) +", actual = " +
212 std::to_string(this->pixels.size()) + ')'};
213
214 return;
215 case BitsPerChannel::Eight:
216 switch (bpp) {
217 case BitsPerPixel::TwentyFour:
218 break;
219
220 case BitsPerPixel::Eight:
221 [[fallthrough]];
222 case BitsPerPixel::Sixteen:
223 [[fallthrough]];
224 case BitsPerPixel::FortyEight:
225 throw std::logic_error{"Unexpected "
226 "combination (" +
227 imagePropertiesString(*this) + ')'};
228 }
229
230 expected = width * height * 3ul;
231 if (pixels.size() != expected)
232 throw std::logic_error{"Unexpected pixel "
233 "length (expected = " +
234 std::to_string(expected) +", actual = " +
235 std::to_string(this->pixels.size()) + ')'};
236
237 return;
238 }
239 break;
240 }
241
242 throw std::logic_error{"Untested "
243 "combination (" + imagePropertiesString(*this) + ')'};
244}
Pixel location in an image.
Definition common.h:226
bool operator==(const Coordinate &) const
auto operator<=>(const Coordinate &) const
Coordinate(const uint32_t x={}, const uint32_t y={})
Coordinate constructor.
Data and metadata for an image.
Definition common.h:58
uint16_t height
Height of the image.
Definition common.h:191
BitsPerPixel bpp
Number of bits comprising a single pixel.
Definition common.h:199
BitsPerPixel
Number of bits comprising a single image pixel.
Definition common.h:61
uint16_t width
Width of the image.
Definition common.h:189
void sanityCheck() const
Validate that the properties of this Image appear to correspond to valid image data.
static BitsPerPixel toBitsPerPixel(const std::underlying_type_t< BitsPerPixel > i)
Convert integer to enumerated type.
Colorspace colorspace
Representation of color in each byte within pixels.
Definition common.h:195
BitsPerChannel
Number of bits comprising a single color channel of a single pixel.
Definition common.h:91
BitsPerChannel bpc
Number of bits used by each color component.
Definition common.h:197
static BitsPerChannel toBitsPerChannel(const std::underlying_type_t< BitsPerChannel > i)
Convert integer to enumerated type.
CBEFF information registered with and assigned by IBIA.
Definition common.h:257
auto operator<=>(const CBEFFIdentifier &) const
bool operator==(const CBEFFIdentifier &) const
Identifying details about algorithm components for documentation.
Definition common.h:254
auto operator<=>(const ProductIdentifier &) const
bool operator==(const ProductIdentifier &) const