IDS peak IPL v1.17.1
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 static constexpr underlying_type minimumValuePerChannel = ValueRangeHelper<underlying_type, is_floating_point>::Minimum(
75 storageBitsPerChannel);
76
77 static constexpr underlying_type maximumValuePerChannel = ValueRangeHelper<underlying_type, is_floating_point>::Maximum(
78 storageBitsPerChannel);
79
80 static constexpr auto Channels()
81 {
82 return traits::Channels();
83 }
84
85 static constexpr const char* Name()
86 {
87 return traits::Name();
88 }
89
90 static constexpr size_t GetSizeInBytes(const Size& size)
91 {
92 const auto area = static_cast<uint64_t>(size.GetWidth()) * size.GetHeight();
93 return static_cast<size_t>(((area * PixelFormatInfo<pixelFormat>::allocatedBitsPerPixel) + 7) / 8);
94 }
95
96 static constexpr bool IsPacked()
97 {
98 return traits::isPacked;
99 }
100
101 static constexpr bool IsInterleaved()
102 {
103 return traits::isInterleaved;
104 }
105
106 static constexpr PixelFormat GetUnpackedFormat()
107 {
108 return traits::unpackedFormat;
109 }
110};
111
112template <typename PixelFormatInfo>
113inline auto ChannelsVector()
114{
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());
118}
119
121} // namespace detail
122
123template <typename T>
125{
126 static_assert(true, "The given template type is not supported! Only size_t and float can be used.");
127}
128
129template <typename T>
131{
132 static_assert(true, "The given template type is not supported! Only size_t and float can be used.");
133}
134} // namespace common
135} // namespace peak
136
Provides information and utility functions for pixel formats.
Definition peak_common_pixel_format.hpp:225
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:662
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:52
@ 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