Friction Ridge Image and Features Technology Evaluations
API for participating in NIST's Friction Ridge Image and Features Technology Evaluations.
Toggle main menu visibility
Loading...
Searching...
No Matches
libfrifte
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
15
FRIF::Coordinate::Coordinate
(
16
const
uint32_t x_,
17
const
uint32_t y_) :
18
x
{x_},
19
y
{y_}
20
{
21
22
}
23
24
auto
25
FRIF::Coordinate::operator<=>
(
26
const
FRIF::Coordinate
&)
27
const
=
default
;
28
29
bool
30
FRIF::Coordinate::operator==
(
31
const
FRIF::Coordinate
&)
32
const
=
default
;
33
34
auto
35
FRIF::ProductIdentifier::CBEFFIdentifier::operator<=>
(
36
const
FRIF::ProductIdentifier::CBEFFIdentifier
&)
37
const
=
default
;
38
39
bool
40
FRIF::ProductIdentifier::CBEFFIdentifier::operator==
(
41
const
FRIF::ProductIdentifier::CBEFFIdentifier
&)
42
const
=
default
;
43
44
auto
45
FRIF::ProductIdentifier::operator<=>
(
46
const
FRIF::ProductIdentifier
&)
47
const
=
default
;
48
49
bool
50
FRIF::ProductIdentifier::operator==
(
51
const
FRIF::ProductIdentifier
&)
52
const
=
default
;
53
54
FRIF::ReturnStatus::operator bool()
55
const
56
noexcept
57
{
58
return
(this->
result
==
Result::Success
);
59
}
60
61
static
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<
70
FRIF::Image::BitsPerPixel
>
>(image.
bpp
))};
71
}
72
73
FRIF::Image::Image
() =
default
;
74
FRIF::Image::Image
(
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
95
FRIF::Image::BitsPerPixel
96
FRIF::Image::toBitsPerPixel
(
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
114
FRIF::Image::BitsPerChannel
115
FRIF::Image::toBitsPerChannel
(
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
129
void
130
FRIF::Image::sanityCheck
()
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
}
common.h
FRIF::Coordinate
Pixel location in an image.
Definition
common.h:226
FRIF::Coordinate::operator==
bool operator==(const Coordinate &) const
FRIF::Coordinate::x
uint32_t x
X coordinate in pixels.
Definition
common.h:228
FRIF::Coordinate::y
uint32_t y
Y coordinate in pixels.
Definition
common.h:230
FRIF::Coordinate::operator<=>
auto operator<=>(const Coordinate &) const
FRIF::Coordinate::Coordinate
Coordinate(const uint32_t x={}, const uint32_t y={})
Coordinate constructor.
Definition
libfrifte_common.cpp:15
FRIF::Image
Data and metadata for an image.
Definition
common.h:58
FRIF::Image::height
uint16_t height
Height of the image.
Definition
common.h:191
FRIF::Image::bpp
BitsPerPixel bpp
Number of bits comprising a single pixel.
Definition
common.h:199
FRIF::Image::BitsPerPixel
BitsPerPixel
Number of bits comprising a single image pixel.
Definition
common.h:61
FRIF::Image::BitsPerPixel::TwentyFour
@ TwentyFour
Definition
common.h:64
FRIF::Image::BitsPerPixel::Sixteen
@ Sixteen
Definition
common.h:63
FRIF::Image::BitsPerPixel::FortyEight
@ FortyEight
Definition
common.h:65
FRIF::Image::BitsPerPixel::Eight
@ Eight
Definition
common.h:62
FRIF::Image::ppi
uint16_t ppi
Resolution of the image in pixels per inch.
Definition
common.h:193
FRIF::Image::pixels
std::vector< std::byte > pixels
Raw pixel data of image.
Definition
common.h:221
FRIF::Image::width
uint16_t width
Width of the image.
Definition
common.h:189
FRIF::Image::sanityCheck
void sanityCheck() const
Validate that the properties of this Image appear to correspond to valid image data.
Definition
libfrifte_common.cpp:130
FRIF::Image::toBitsPerPixel
static BitsPerPixel toBitsPerPixel(const std::underlying_type_t< BitsPerPixel > i)
Convert integer to enumerated type.
Definition
libfrifte_common.cpp:96
FRIF::Image::Colorspace
Colorspace
Definition
common.h:115
FRIF::Image::Colorspace::RGB
@ RGB
Three channels, with equal bit widths representing red, green, and blue, in order.
Definition
common.h:122
FRIF::Image::Colorspace::Grayscale
@ Grayscale
Single channel (shades of gray).
Definition
common.h:117
FRIF::Image::colorspace
Colorspace colorspace
Representation of color in each byte within pixels.
Definition
common.h:195
FRIF::Image::Image
Image()
FRIF::Image::BitsPerChannel
BitsPerChannel
Number of bits comprising a single color channel of a single pixel.
Definition
common.h:91
FRIF::Image::BitsPerChannel::Sixteen
@ Sixteen
Definition
common.h:93
FRIF::Image::BitsPerChannel::Eight
@ Eight
Definition
common.h:92
FRIF::Image::bpc
BitsPerChannel bpc
Number of bits used by each color component.
Definition
common.h:197
FRIF::Image::toBitsPerChannel
static BitsPerChannel toBitsPerChannel(const std::underlying_type_t< BitsPerChannel > i)
Convert integer to enumerated type.
Definition
libfrifte_common.cpp:115
FRIF::Image::identifier
uint8_t identifier
An identifier for this image.
Definition
common.h:187
FRIF::ProductIdentifier::CBEFFIdentifier
CBEFF information registered with and assigned by IBIA.
Definition
common.h:257
FRIF::ProductIdentifier::CBEFFIdentifier::operator<=>
auto operator<=>(const CBEFFIdentifier &) const
FRIF::ProductIdentifier::CBEFFIdentifier::operator==
bool operator==(const CBEFFIdentifier &) const
FRIF::ProductIdentifier
Identifying details about algorithm components for documentation.
Definition
common.h:254
FRIF::ProductIdentifier::operator<=>
auto operator<=>(const ProductIdentifier &) const
FRIF::ProductIdentifier::operator==
bool operator==(const ProductIdentifier &) const
FRIF::ReturnStatus::result
Result result
The result of the operation.
Definition
common.h:40
FRIF::ReturnStatus::Result::Success
@ Success
Successfully performed operation.
Definition
common.h:34
Generated by
1.17.0