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 static constexpr underlying_type minimumValuePerChannel = ValueRangeHelper<underlying_type, is_floating_point>::Minimum(
75 storageBitsPerChannel);
77 static constexpr underlying_type maximumValuePerChannel = ValueRangeHelper<underlying_type, is_floating_point>::Maximum(
78 storageBitsPerChannel);
80 static constexpr auto Channels()
82 return traits::Channels();
85 static constexpr const char* Name()
87 return traits::Name();
90 static constexpr size_t GetSizeInBytes(
const Size& size)
92 const auto area =
static_cast<uint64_t
>(size.GetWidth()) * size.GetHeight();
93 return static_cast<size_t>(((area * PixelFormatInfo<pixelFormat>::allocatedBitsPerPixel) + 7) / 8);
96 static constexpr bool IsPacked()
98 return traits::isPacked;
101 static constexpr bool IsInterleaved()
103 return traits::isInterleaved;
108 return traits::unpackedFormat;
112template <
typename PixelFormatInfo>
113inline auto ChannelsVector()
115 constexpr auto arr = PixelFormatInfo::Channels();
116 using T =
typename std::decay_t<
typename decltype(arr)::value_type>;
117 return std::vector<T>(arr.begin(), arr.end());
126 static_assert(
true,
"The given template type is not supported! Only size_t and float can be used.");
132 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:52
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
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:33