22enum class ImagePrecision :
unsigned int {
32enum class ImageChannel :
unsigned int {
46template <
typename VALUE_SRC,
typename VALUE_DST>
47inline VALUE_DST convert_channel_value(VALUE_SRC val);
49template <
typename PIX_SRC,
typename PIX_DST>
52 void operator()(
const PIX_SRC& src, PIX_DST& dst)
const;
56template <
typename TYPE>
59 static constexpr ImagePrecision precision = ImagePrecision::unknown;
60 static constexpr ImageChannel channel = ImageChannel::unknown;
63#ifdef LAGRANGE_IMAGE_TRAITS
64static_assert(
false,
"LAGRANGE_IMAGE_TRAITS was defined somewhere else")
65#elif LAGRANGE_IMAGE_COMMA
66static_assert(
false,
"LAGRANGE_IMAGE_COMMA was defined somewhere else")
69#define LAGRANGE_IMAGE_TRAITS(TYPE, VALUE, SIZE_OF_VALUE, PRECISION, CHANNEL) \
71 struct ImageTraits<TYPE> \
73 typedef VALUE TValue; \
74 static constexpr size_t value_size = SIZE_OF_VALUE; \
75 static constexpr ImagePrecision precision = ImagePrecision::PRECISION; \
76 static constexpr ImageChannel channel = ImageChannel::CHANNEL; \
79#define LAGRANGE_IMAGE_COMMA ,
80LAGRANGE_IMAGE_TRAITS(
unsigned char,
unsigned char, 1, uint8, one)
82 Eigen::Matrix<unsigned char LAGRANGE_IMAGE_COMMA 3 LAGRANGE_IMAGE_COMMA 1>,
88 Eigen::Matrix<unsigned char LAGRANGE_IMAGE_COMMA 4 LAGRANGE_IMAGE_COMMA 1>,
93LAGRANGE_IMAGE_TRAITS(
char,
char, 1, int8, one)
95 Eigen::Matrix<char LAGRANGE_IMAGE_COMMA 3 LAGRANGE_IMAGE_COMMA 1>,
100LAGRANGE_IMAGE_TRAITS(
101 Eigen::Matrix<char LAGRANGE_IMAGE_COMMA 4 LAGRANGE_IMAGE_COMMA 1>,
106LAGRANGE_IMAGE_TRAITS(
unsigned int,
unsigned int, 1, uint32, one)
107LAGRANGE_IMAGE_TRAITS(
108 Eigen::Matrix<unsigned int LAGRANGE_IMAGE_COMMA 3 LAGRANGE_IMAGE_COMMA 1>,
113LAGRANGE_IMAGE_TRAITS(
114 Eigen::Matrix<unsigned int LAGRANGE_IMAGE_COMMA 4 LAGRANGE_IMAGE_COMMA 1>,
119LAGRANGE_IMAGE_TRAITS(
int,
int, 1, int32, one)
120LAGRANGE_IMAGE_TRAITS(Eigen::Vector3i,
int, 3, int32, three)
121LAGRANGE_IMAGE_TRAITS(Eigen::Vector4i,
int, 4, int32, four)
122LAGRANGE_IMAGE_TRAITS(
float,
float, 1, float32, one)
123LAGRANGE_IMAGE_TRAITS(Eigen::Vector3f,
float, 3, float32, three)
124LAGRANGE_IMAGE_TRAITS(Eigen::Vector4f,
float, 4, float32, four)
125LAGRANGE_IMAGE_TRAITS(
double,
double, 1, float64, one)
126LAGRANGE_IMAGE_TRAITS(Eigen::Vector3d,
double, 3, float64, three)
127LAGRANGE_IMAGE_TRAITS(Eigen::Vector4d,
double, 4, float64, four)
128LAGRANGE_IMAGE_TRAITS(Eigen::half, Eigen::half, 1, float16, one)
129LAGRANGE_IMAGE_TRAITS(
130 Eigen::Matrix<Eigen::half LAGRANGE_IMAGE_COMMA 3 LAGRANGE_IMAGE_COMMA 1>,
135LAGRANGE_IMAGE_TRAITS(
136 Eigen::Matrix<Eigen::half LAGRANGE_IMAGE_COMMA 4 LAGRANGE_IMAGE_COMMA 1>,
142#undef LAGRANGE_IMAGE_TRAITS
143#undef LAGRANGE_IMAGE_COMMA
146 template <
typename VALUE_SRC,
typename VALUE_DST>
147 inline VALUE_DST convert_channel_value(VALUE_SRC val)
150 if constexpr (std::is_same<VALUE_SRC, VALUE_DST>::value) {
155 std::is_same<VALUE_SRC, unsigned char>::value && std::is_floating_point<VALUE_DST>::value) {
156 return static_cast<VALUE_DST
>(val) /
157 static_cast<VALUE_DST
>(std::numeric_limits<unsigned char>::max());
161 std::is_floating_point<VALUE_SRC>::value && std::is_same<VALUE_DST, unsigned char>::value) {
162 return static_cast<unsigned char>(
163 std::clamp(val,
static_cast<VALUE_SRC
>(0),
static_cast<VALUE_SRC
>(1)) *
164 static_cast<VALUE_SRC
>(std::numeric_limits<unsigned char>::max()));
167 if constexpr (std::is_signed<VALUE_SRC>::value && !std::is_signed<VALUE_DST>::value) {
168 val = std::max(val,
static_cast<VALUE_SRC
>(0));
172 (std::is_integral<VALUE_SRC>::value && std::is_integral<VALUE_DST>::value) &&
173 (
sizeof(VALUE_SRC) >
sizeof(VALUE_DST) ||
174 (
sizeof(VALUE_SRC) ==
sizeof(VALUE_DST) && std::is_signed<VALUE_DST>::value))) {
175 return static_cast<VALUE_DST
>(
176 std::min(val,
static_cast<VALUE_SRC
>(std::numeric_limits<VALUE_DST>::max())));
180 return static_cast<VALUE_DST
>(val);
185template <
typename PIX_SRC,
typename PIX_DST>
186inline void convert_image_pixel<PIX_SRC, PIX_DST>::operator()(
const PIX_SRC& src, PIX_DST& dst)
189 using V_SRC =
typename ImageTraits<PIX_SRC>::TValue;
190 using V_DST =
typename ImageTraits<PIX_DST>::TValue;
191 constexpr size_t L_SRC =
static_cast<size_t>(ImageTraits<PIX_SRC>::channel);
192 constexpr size_t L_DST =
static_cast<size_t>(ImageTraits<PIX_DST>::channel);
194 if constexpr (1 == L_SRC && 1 == L_DST) {
195 dst = convert_channel_value<V_SRC, V_DST>(src);
198 else if constexpr (1 == L_SRC) {
199 dst(0) = convert_channel_value<V_SRC, V_DST>(src);
200 for (
size_t i = 1; i < L_DST; ++i) {
201 dst(i) =
static_cast<V_DST
>(0);
203 if constexpr (3 <= L_DST) {
207 if constexpr (4 == L_DST) {
208 if constexpr (std::is_floating_point<V_DST>::value) {
209 dst(3) =
static_cast<V_DST
>(1);
210 }
else if constexpr (!std::is_signed<V_DST>::value && 1 ==
sizeof(V_DST)) {
211 dst(3) = std::numeric_limits<V_DST>::max();
213 dst(3) =
static_cast<V_DST
>(0);
218 else if constexpr (1 == L_DST) {
219 dst = convert_channel_value<V_SRC, V_DST>(src(0));
223 constexpr size_t L_MIN = std::min(L_SRC, L_DST);
224 for (
size_t i = 0; i < L_MIN; ++i) {
225 dst(i) = convert_channel_value<V_SRC, V_DST>(src(i));
227 if constexpr (3 == L_MIN && 4 == L_DST) {
228 if constexpr (std::is_floating_point<V_DST>::value) {
229 dst(3) =
static_cast<V_DST
>(1);
230 }
else if constexpr (!std::is_signed<V_DST>::value && 1 ==
sizeof(V_DST)) {
231 dst(3) = std::numeric_limits<V_DST>::max();
233 dst(3) =
static_cast<V_DST
>(0);
236 for (
size_t i = L_MIN; i < L_DST; ++i) {
237 dst(i) =
static_cast<V_DST
>(0);
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: ImageType.h:58
Definition: ImageType.h:51