24template <
typename T,
bool isFloat>
25struct ValueRangeHelper;
28struct ValueRangeHelper<T, false>
30 static constexpr T Minimum(
size_t)
35 static constexpr T Maximum(
size_t bitsPerChannel)
37 return static_cast<T
>((1ULL << bitsPerChannel) - 1);
42struct ValueRangeHelper<T, true>
44 static constexpr T Minimum(
size_t)
46 return std::numeric_limits<T>::lowest();
49 static constexpr T Maximum(
size_t)
51 return (std::numeric_limits<T>::max)();
55template <PixelFormat pixelFormat>
58 using traits = PixelFormatTraits<pixelFormat>;
59 using underlying_type =
typename traits::underlying_type;
60 static constexpr bool is_floating_point = std::is_floating_point<underlying_type>::value;
62 static constexpr size_t storageBitsPerPixel = traits::storageBitsPerPixel;
63 static constexpr size_t allocatedBitsPerPixel = traits::allocatedBitsPerPixel;
65 static constexpr bool isYUV = storageBitsPerPixel / traits::Channels().size() < 8;
67 static constexpr size_t storageBitsPerChannel = isYUV ? storageBitsPerPixel : storageBitsPerPixel / traits::Channels().size();
69 using unpacked_underlying_type =
typename PixelFormatTraits<traits::unpackedFormat>::underlying_type;
71 static constexpr unpacked_underlying_type minimumValuePerChannel =
72 ValueRangeHelper<unpacked_underlying_type, is_floating_point>::Minimum(storageBitsPerChannel);
74 static constexpr unpacked_underlying_type maximumValuePerChannel =
75 ValueRangeHelper<unpacked_underlying_type, is_floating_point>::Maximum(storageBitsPerChannel);
77 static constexpr auto Channels()
79 return traits::Channels();
82 static constexpr const char* Name()
84 return traits::Name();
87 static constexpr size_t GetSizeInBytes(
const Size& size)
89 const auto area =
static_cast<uint64_t
>(size.GetWidth()) * size.GetHeight();
90 return static_cast<size_t>(((
area * PixelFormatInfo<pixelFormat>::allocatedBitsPerPixel) + 7) / 8);
93 static constexpr bool IsPacked()
95 return traits::isPacked;
98 static constexpr bool IsInterleaved()
100 return traits::isInterleaved;
105 return traits::unpackedFormat;
109template <
typename PixelFormatInfo>
110inline auto ChannelsVector()
112 constexpr auto arr = PixelFormatInfo::Channels();
113 using T =
typename std::decay_t<
typename decltype(arr)::value_type>;
114 return std::vector<T>(arr.begin(), arr.end());
123 static_assert(
true,
"The given template type is not supported! Only size_t and float can be used.");
129 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:59
@ area
resampling using pixel area relation
Definition peak_ipl_simple_types.hpp:209
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:17
std::ostream & operator<<(std::ostream &os, PixelFormat pixelFormat)
Definition peak_common_pixel_format.ipp:14