29template <
typename T,
bool isFloat>
30struct ValueRangeHelper;
33struct ValueRangeHelper<T, false>
35 static constexpr T Minimum(
size_t)
40 static constexpr T Maximum(
size_t bitsPerChannel)
42 return static_cast<T
>((1ULL << bitsPerChannel) - 1);
47struct ValueRangeHelper<T, true>
49 static constexpr T Minimum(
size_t)
51 return std::numeric_limits<T>::lowest();
54 static constexpr T Maximum(
size_t)
56 return (std::numeric_limits<T>::max)();
60template <PixelFormat pixelFormat>
63 using traits = PixelFormatTraits<pixelFormat>;
64 using underlying_type =
typename traits::underlying_type;
65 static constexpr bool is_floating_point = std::is_floating_point<underlying_type>::value;
67 static constexpr size_t storageBitsPerPixel = traits::storageBitsPerPixel;
68 static constexpr size_t allocatedBitsPerPixel = traits::allocatedBitsPerPixel;
70 static constexpr bool isYUV = storageBitsPerPixel / traits::Channels().size() < 8;
72 static constexpr size_t storageBitsPerChannel = isYUV ? storageBitsPerPixel : storageBitsPerPixel / traits::Channels().size();
74 using unpacked_underlying_type =
typename PixelFormatTraits<traits::unpackedFormat>::underlying_type;
76 static constexpr unpacked_underlying_type minimumValuePerChannel =
77 ValueRangeHelper<unpacked_underlying_type, is_floating_point>::Minimum(storageBitsPerChannel);
79 static constexpr unpacked_underlying_type maximumValuePerChannel =
80 ValueRangeHelper<unpacked_underlying_type, is_floating_point>::Maximum(storageBitsPerChannel);
82 static constexpr auto Channels()
84 return traits::Channels();
87 static constexpr const char* Name()
89 return traits::Name();
92 static constexpr size_t GetSizeInBytes(
const Size& size)
94 const auto area =
static_cast<uint64_t
>(size.GetWidth()) * size.GetHeight();
95 return static_cast<size_t>(((
area * PixelFormatInfo<pixelFormat>::allocatedBitsPerPixel) + 7) / 8);
98 static constexpr bool IsPacked()
100 return traits::isPacked;
103 static constexpr bool IsInterleaved()
105 return traits::isInterleaved;
110 return traits::unpackedFormat;
114template <
typename PixelFormatInfo>
115inline auto ChannelsVector()
117 constexpr auto arr = PixelFormatInfo::Channels();
118 using T =
typename std::decay_t<
typename decltype(arr)::value_type>;
119 return std::vector<T>(arr.begin(), arr.end());
128 static_assert(
true,
"The given template type is not supported! Only size_t and float can be used.");
134 static_assert(
true,
"The given template type is not supported! Only size_t and float can be used.");
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
Definition peak_common_pixel_format.hpp:64
@ area
resampling using pixel area relation
Definition peak_ipl_simple_types.hpp:214
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:22
std::ostream & operator<<(std::ostream &os, PixelFormat pixelFormat)
Definition peak_common_pixel_format.ipp:19