@@ -24,7 +24,7 @@ namespace modm::color {
24
24
* @ingroup modm_color_gray
25
25
*/
26
26
template <int W>
27
- class GrayT
27
+ class GrayD
28
28
{
29
29
public:
30
30
static constexpr int Wide = W;
@@ -33,73 +33,73 @@ class GrayT
33
33
static constexpr ValueType min = 0 ;
34
34
static constexpr ValueType max = bitmask<W>();
35
35
36
- constexpr GrayT () = default;
36
+ constexpr GrayD () = default;
37
37
38
38
// FIXME want both:
39
39
// COMTIME: static_assert(value <= max, "value out of range")
40
40
// RUNTIME: std::min(value, max) or modm_assert(value <= max, ...)
41
- constexpr GrayT (ValueType value) : value(std::min(value, max)) {
41
+ constexpr GrayD (ValueType value) : value(std::min(value, max)) {
42
42
// TODO disable via lbuild option
43
- modm_assert (value <= max, " modm::color::GrayT <W>" , " constructor" , " value out of range" );
43
+ modm_assert (value <= max, " modm::color::GrayD <W>" , " constructor" , " value out of range" );
44
44
}
45
45
46
46
// Construct from bigger or equal ColorGray
47
47
template <ColorGray C, std::enable_if_t <(W <= C::Wide), void *> = nullptr >
48
- constexpr GrayT (const C& other)
48
+ constexpr GrayD (const C& other)
49
49
: value(other.value >> (C::Wide - W)) {}
50
50
51
51
template <ColorGray C, std::enable_if_t <(W <= C::Wide), void *> = nullptr >
52
- constexpr GrayT (C &&other)
52
+ constexpr GrayD (C &&other)
53
53
: value(other.value >> (C::Wide - W)) {}
54
54
55
55
// Construct from smaller ColorGray
56
56
template <ColorGray C, std::enable_if_t <(W > C::Wide), void *> = nullptr >
57
- constexpr GrayT (const C& other)
57
+ constexpr GrayD (const C& other)
58
58
: value(other.value * max / other.max)
59
59
{}
60
60
61
61
template <ColorGray C, std::enable_if_t <(W > C::Wide), void *> = nullptr >
62
- constexpr GrayT (C &&other)
62
+ constexpr GrayD (C &&other)
63
63
: value(other.value * max / other.max)
64
64
{}
65
65
66
66
template <ColorRgb C>
67
- constexpr GrayT (const C& rgb)
67
+ constexpr GrayD (const C& rgb)
68
68
// OPTIMIZE Calc with fixed point instead float
69
69
: value(
70
- 0.2125 * float (GrayT (rgb.getRed()).value) +
71
- 0.7154 * float(GrayT (rgb.getGreen()).value) +
72
- 0.0721 * float(GrayT (rgb.getblue()).value)
70
+ 0.2125 * float (GrayD (rgb.getRed()).value) +
71
+ 0.7154 * float(GrayD (rgb.getGreen()).value) +
72
+ 0.0721 * float(GrayD (rgb.getblue()).value)
73
73
)
74
74
{}
75
75
76
76
template <ColorHsv C>
77
- constexpr GrayT (const C& hsv) : GrayT (hsv.getValue())
77
+ constexpr GrayD (const C& hsv) : GrayD (hsv.getValue())
78
78
{}
79
79
80
80
/* // Faster construction from monochrome
81
- constexpr GrayT (const GrayT <1> &other) : value(other.value ? bitmask<W>() : 0){}
81
+ constexpr GrayD (const GrayD <1> &other) : value(other.value ? bitmask<W>() : 0){}
82
82
83
- // constexpr GrayT(GrayT <1> &&other) : value(other.value ? bitmask<W>() : 0){}
84
- constexpr GrayT & operator=(const GrayT <1> &other) {
83
+ // constexpr GrayD(GrayD <1> &&other) : value(other.value ? bitmask<W>() : 0){}
84
+ constexpr GrayD & operator=(const GrayD <1> &other) {
85
85
value = other.value ? bitmask<W>() : 0;
86
86
return *this;
87
87
} */
88
88
89
89
void setValue (ValueType value) {
90
90
this ->value = std::min (value, max);
91
91
// TODO disable via lbuild option
92
- modm_assert (value <= max, " modm::color::GrayT <W>" , " constructor" , " value out of range" );
92
+ modm_assert (value <= max, " modm::color::GrayD <W>" , " constructor" , " value out of range" );
93
93
}
94
94
ValueType getValue () const { return value; }
95
95
96
- // Assign GrayT with more or equal Depth
96
+ // Assign GrayD with more or equal Depth
97
97
template <ColorGray C, std::enable_if_t <(W <= C::Wide), void*> = nullptr>
98
98
void operator=(const C& other) {
99
99
value = other.value >> (C::Wide - W);
100
100
}
101
101
102
- // Assign GrayT with less Depth
102
+ // Assign GrayD with less Depth
103
103
template <ColorGray C, std::enable_if_t <(W > C::Wide), void *> = nullptr >
104
104
void operator =(const C& other) {
105
105
value = other.value * max / other.max ;
@@ -111,15 +111,15 @@ class GrayT
111
111
// operator*=() {}
112
112
113
113
template <std::integral U>
114
- GrayT operator +(const U value) const {
114
+ GrayD operator +(const U value) const {
115
115
modm::Saturated<ValueType> result (this ->value );
116
116
result+=value;
117
117
118
118
// Unnecessary std::min optimises away when max = std::numeric_limits<ValueType>::max()
119
119
return {std::min (result.getValue (), max)};
120
120
}
121
121
122
- GrayT operator +(const GrayT <W>& other) const {
122
+ GrayD operator +(const GrayD <W>& other) const {
123
123
modm::Saturated<ValueType> result (value);
124
124
result+=other.value ;
125
125
@@ -128,23 +128,23 @@ class GrayT
128
128
}
129
129
130
130
template <std::integral U>
131
- GrayT operator -(const U value) const {
131
+ GrayD operator -(const U value) const {
132
132
modm::Saturated<ValueType> result (this ->value );
133
133
result-=value;
134
134
135
135
// Unnecessary std::min optimises away when max = std::numeric_limits<ValueType>::max()
136
136
return {std::min (result.getValue (), max)};
137
137
}
138
138
139
- GrayT operator -(const GrayT <W>& other) const {
139
+ GrayD operator -(const GrayD <W>& other) const {
140
140
modm::Saturated<ValueType> result (value);
141
141
result -= other.value ;
142
142
143
143
return result.getValue ();
144
144
}
145
145
146
146
template <std::integral ScaleType>
147
- GrayT operator *(const ScaleType &scale) const {
147
+ GrayD operator *(const ScaleType &scale) const {
148
148
modm::Saturated<ValueType> result (value);
149
149
result *= scale;
150
150
@@ -153,7 +153,7 @@ class GrayT
153
153
}
154
154
155
155
template <std::floating_point ScaleType>
156
- GrayT
156
+ GrayD
157
157
operator *(const ScaleType &scale) const
158
158
{
159
159
// TODO trait optimal decimal-count from W
@@ -166,34 +166,34 @@ class GrayT
166
166
return value == max;
167
167
}
168
168
169
- constexpr auto operator <=>(const GrayT <W> &) const = default ;
169
+ constexpr auto operator <=>(const GrayD <W> &) const = default ;
170
170
171
171
private:
172
172
ValueType value = 0 ;
173
173
174
174
template <int >
175
- friend class GrayT ;
175
+ friend class GrayD ;
176
176
177
177
template <int V>
178
178
friend modm::IOStream &
179
- operator <<(modm::IOStream &, const GrayT <V> &);
179
+ operator <<(modm::IOStream &, const GrayD <V> &);
180
180
};
181
181
182
182
template <typename U>
183
- using GrayT_t = GrayT <std::numeric_limits<U>::digits>;
183
+ using GrayT = GrayD <std::numeric_limits<U>::digits>;
184
184
185
- using Monochrome = GrayT <1 >;
186
- using Gray2 = GrayT <2 >;
187
- using Gray4 = GrayT <4 >;
188
- using Gray8 = GrayT_t <uint8_t >;
189
- using Gray16 = GrayT_t <uint16_t >;
185
+ using Monochrome = GrayD <1 >;
186
+ using Gray2 = GrayD <2 >;
187
+ using Gray4 = GrayD <4 >;
188
+ using Gray8 = GrayT <uint8_t >;
189
+ using Gray16 = GrayT <uint16_t >;
190
190
191
191
#if __has_include(<modm/io/iostream.hpp>)
192
192
#include < modm/io/iostream.hpp>
193
193
194
194
template <int V>
195
195
modm::IOStream &
196
- operator <<(modm::IOStream &os, const GrayT <V> &color)
196
+ operator <<(modm::IOStream &os, const GrayD <V> &color)
197
197
{
198
198
os << color.value ;
199
199
return os;
0 commit comments