IDS peak genericC++ v1.16.0
Loading...
Searching...
No Matches
peak_common_pixel_format.ipp
Go to the documentation of this file.
1
10
11#pragma once
12
14
15namespace peak
16{
17namespace common
18{
19inline std::ostream& operator<<(std::ostream& os, PixelFormat pixelFormat)
20{
21 PixelFormatInfo info(pixelFormat);
22 os << info.GetName();
23 return os;
24}
25
26namespace detail
27{
29template <typename T, bool isFloat>
30struct ValueRangeHelper;
31
32template <typename T>
33struct ValueRangeHelper<T, false> // Integer
34{
35 static constexpr T Minimum(size_t)
36 {
37 return 0;
38 }
39
40 static constexpr T Maximum(size_t bitsPerChannel)
41 {
42 return static_cast<T>((1ULL << bitsPerChannel) - 1);
43 }
44};
45
46template <typename T>
47struct ValueRangeHelper<T, true> // Float
48{
49 static constexpr T Minimum(size_t)
50 {
51 return std::numeric_limits<T>::lowest();
52 }
53
54 static constexpr T Maximum(size_t)
55 {
56 return (std::numeric_limits<T>::max)();
57 }
58};
59
60template <PixelFormat pixelFormat>
61struct PixelFormatInfo
62{
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;
66
67 static constexpr size_t storageBitsPerPixel = traits::storageBitsPerPixel;
68 static constexpr size_t allocatedBitsPerPixel = traits::allocatedBitsPerPixel;
69
70 static constexpr bool isYUV = storageBitsPerPixel / traits::Channels().size() < 8;
71
72 static constexpr size_t storageBitsPerChannel = isYUV ? storageBitsPerPixel : storageBitsPerPixel / traits::Channels().size();
73
74 using unpacked_underlying_type = typename PixelFormatTraits<traits::unpackedFormat>::underlying_type;
75
76 static constexpr unpacked_underlying_type minimumValuePerChannel =
77 ValueRangeHelper<unpacked_underlying_type, is_floating_point>::Minimum(storageBitsPerChannel);
78
79 static constexpr unpacked_underlying_type maximumValuePerChannel =
80 ValueRangeHelper<unpacked_underlying_type, is_floating_point>::Maximum(storageBitsPerChannel);
81
82 static constexpr auto Channels()
83 {
84 return traits::Channels();
85 }
86
87 static constexpr const char* Name()
88 {
89 return traits::Name();
90 }
91
92 static constexpr size_t GetSizeInBytes(const Size& size)
93 {
94 const auto area = static_cast<uint64_t>(size.GetWidth()) * size.GetHeight();
95 return static_cast<size_t>(((area * PixelFormatInfo<pixelFormat>::allocatedBitsPerPixel) + 7) / 8);
96 }
97
98 static constexpr bool IsPacked()
99 {
100 return traits::isPacked;
101 }
102
103 static constexpr bool IsInterleaved()
104 {
105 return traits::isInterleaved;
106 }
107
108 static constexpr PixelFormat GetUnpackedFormat()
109 {
110 return traits::unpackedFormat;
111 }
112};
113
114template <typename PixelFormatInfo>
115inline auto ChannelsVector()
116{
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());
120}
121
123} // namespace detail
124
125template <typename T>
127{
128 static_assert(true, "The given template type is not supported! Only size_t and float can be used.");
129}
130
131template <typename T>
133{
134 static_assert(true, "The given template type is not supported! Only size_t and float can be used.");
135}
136} // namespace common
137} // namespace peak
138
Provides information and utility functions for pixel formats.
Definition peak_common_pixel_format.hpp:239
PEAK_COMMON_NO_DISCARD T GetMinimumValuePerChannel() const
Returns the minimum possible value per channel for the pixel format.
PEAK_COMMON_NO_DISCARD std::string GetName() const
Returns the human-readable name of the pixel format.
Definition peak_common_pixel_format_info.ipp:674
PEAK_COMMON_NO_DISCARD T GetMaximumValuePerChannel() const
Returns the maximum possible value per channel for the pixel format.
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
Definition peak_common_pixel_format.hpp:64
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:35