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