Skip to content

Commit 649b37c

Browse files
committed
Renamed GrayT -> GrayH, RgbT -> RgbD, HsvT -> HsvD
1 parent a9788e4 commit 649b37c

File tree

17 files changed

+459
-158
lines changed

17 files changed

+459
-158
lines changed

src/modm/ui/color/concepts.hpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#pragma once
22

33
#include <bit>
4+
#include <modm/ui/shape/point.hpp>
45

56
namespace modm::color {
67

78
template <int>
8-
class GrayT;
9+
class GrayD;
910

1011
template<int, int, int>
11-
class RgbT;
12+
class RgbD;
1213

1314
template <int, int, int>
14-
class HsvT;
15+
class HsvD;
1516

1617
template<int, int, int>
1718
class RgbStackedT;
@@ -24,22 +25,33 @@ template <int...Ts, template <int...> class U>
2425
struct is_instance<U<Ts...>, U> : public std::true_type {};
2526

2627
template<class C>
27-
concept ColorGray = is_instance<C, GrayT>::value;
28+
concept ColorGray = is_instance<C, GrayD>::value;
2829

2930
template<class C>
3031
concept ColorGrayBase2 = ColorGray<C> && std::popcount(unsigned(C::Wide)) == 1;
3132

3233
template<class C>
33-
concept ColorRgb = is_instance<C, RgbT>::value;
34+
concept ColorRgb = is_instance<C, RgbD>::value;
3435

3536
template<class C>
3637
concept ColorRgbStacked = is_instance<C, RgbStackedT>::value;
3738

3839
template<class C>
39-
concept ColorHsv = is_instance<C, HsvT>::value;
40+
concept ColorHsv = is_instance<C, HsvD>::value;
4041

4142
template<class C>
42-
// concept Color = std::convertible_to<C, RgbT<8,8,8> >; // convertability
43+
// concept Color = std::convertible_to<C, RgbD<8,8,8> >; // convertability
4344
concept Color = ColorGray<C> || ColorRgb<C> || ColorHsv<C> || ColorRgbStacked<C>; // conjunction of types
4445

46+
/**
47+
* @brief Concept for a function or functor, that returns a Color for a Point
48+
*
49+
* @tparam F
50+
*/
51+
template <typename F>
52+
concept ColorPattern = requires(F p)
53+
{
54+
{ p.operator()(modm::shape::Point()) } -> Color; // -> std::convertible_to<modm::color::Rgb888>;
55+
};
56+
4557
}

src/modm/ui/color/gray.hpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace modm::color {
2424
* @ingroup modm_color_gray
2525
*/
2626
template <int W>
27-
class GrayT
27+
class GrayD
2828
{
2929
public:
3030
static constexpr int Wide = W;
@@ -33,73 +33,73 @@ class GrayT
3333
static constexpr ValueType min = 0;
3434
static constexpr ValueType max = bitmask<W>();
3535

36-
constexpr GrayT() = default;
36+
constexpr GrayD() = default;
3737

3838
// FIXME want both:
3939
// COMTIME: static_assert(value <= max, "value out of range")
4040
// 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)) {
4242
// 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");
4444
}
4545

4646
// Construct from bigger or equal ColorGray
4747
template <ColorGray C, std::enable_if_t<(W <= C::Wide), void*> = nullptr>
48-
constexpr GrayT(const C& other)
48+
constexpr GrayD(const C& other)
4949
: value(other.value >> (C::Wide - W)) {}
5050

5151
template <ColorGray C, std::enable_if_t<(W <= C::Wide), void*> = nullptr>
52-
constexpr GrayT(C &&other)
52+
constexpr GrayD(C &&other)
5353
: value(other.value >> (C::Wide - W)) {}
5454

5555
// Construct from smaller ColorGray
5656
template <ColorGray C, std::enable_if_t<(W > C::Wide), void*> = nullptr>
57-
constexpr GrayT(const C& other)
57+
constexpr GrayD(const C& other)
5858
: value(other.value * max / other.max)
5959
{}
6060

6161
template <ColorGray C, std::enable_if_t<(W > C::Wide), void*> = nullptr>
62-
constexpr GrayT(C &&other)
62+
constexpr GrayD(C &&other)
6363
: value(other.value * max / other.max)
6464
{}
6565

6666
template<ColorRgb C>
67-
constexpr GrayT(const C& rgb)
67+
constexpr GrayD(const C& rgb)
6868
// OPTIMIZE Calc with fixed point instead float
6969
: 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)
7373
)
7474
{}
7575

7676
template<ColorHsv C>
77-
constexpr GrayT(const C& hsv) : GrayT(hsv.getValue())
77+
constexpr GrayD(const C& hsv) : GrayD(hsv.getValue())
7878
{}
7979

8080
/* // 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){}
8282
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) {
8585
value = other.value ? bitmask<W>() : 0;
8686
return *this;
8787
} */
8888

8989
void setValue(ValueType value) {
9090
this->value = std::min(value, max);
9191
// 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");
9393
}
9494
ValueType getValue() const { return value; }
9595

96-
// Assign GrayT with more or equal Depth
96+
// Assign GrayD with more or equal Depth
9797
template <ColorGray C, std::enable_if_t<(W <= C::Wide), void*> = nullptr>
9898
void operator=(const C& other) {
9999
value = other.value >> (C::Wide - W);
100100
}
101101

102-
// Assign GrayT with less Depth
102+
// Assign GrayD with less Depth
103103
template <ColorGray C, std::enable_if_t<(W > C::Wide), void*> = nullptr>
104104
void operator=(const C& other) {
105105
value = other.value * max / other.max;
@@ -111,15 +111,15 @@ class GrayT
111111
// operator*=() {}
112112

113113
template<std::integral U>
114-
GrayT operator+(const U value) const {
114+
GrayD operator+(const U value) const {
115115
modm::Saturated<ValueType> result(this->value);
116116
result+=value;
117117

118118
// Unnecessary std::min optimises away when max = std::numeric_limits<ValueType>::max()
119119
return {std::min(result.getValue(), max)};
120120
}
121121

122-
GrayT operator+(const GrayT<W>& other) const {
122+
GrayD operator+(const GrayD<W>& other) const {
123123
modm::Saturated<ValueType> result(value);
124124
result+=other.value;
125125

@@ -128,23 +128,23 @@ class GrayT
128128
}
129129

130130
template<std::integral U>
131-
GrayT operator-(const U value) const {
131+
GrayD operator-(const U value) const {
132132
modm::Saturated<ValueType> result(this->value);
133133
result-=value;
134134

135135
// Unnecessary std::min optimises away when max = std::numeric_limits<ValueType>::max()
136136
return {std::min(result.getValue(), max)};
137137
}
138138

139-
GrayT operator-(const GrayT<W>& other) const {
139+
GrayD operator-(const GrayD<W>& other) const {
140140
modm::Saturated<ValueType> result(value);
141141
result -= other.value;
142142

143143
return result.getValue();
144144
}
145145

146146
template<std::integral ScaleType>
147-
GrayT operator*(const ScaleType &scale) const {
147+
GrayD operator*(const ScaleType &scale) const {
148148
modm::Saturated<ValueType> result(value);
149149
result *= scale;
150150

@@ -153,7 +153,7 @@ class GrayT
153153
}
154154

155155
template<std::floating_point ScaleType>
156-
GrayT
156+
GrayD
157157
operator*(const ScaleType &scale) const
158158
{
159159
// TODO trait optimal decimal-count from W
@@ -166,34 +166,34 @@ class GrayT
166166
return value == max;
167167
}
168168

169-
constexpr auto operator<=>(const GrayT<W> &) const = default;
169+
constexpr auto operator<=>(const GrayD<W> &) const = default;
170170

171171
private:
172172
ValueType value = 0;
173173

174174
template<int>
175-
friend class GrayT;
175+
friend class GrayD;
176176

177177
template <int V>
178178
friend modm::IOStream &
179-
operator<<(modm::IOStream &, const GrayT<V> &);
179+
operator<<(modm::IOStream &, const GrayD<V> &);
180180
};
181181

182182
template<typename U>
183-
using GrayT_t = GrayT<std::numeric_limits<U>::digits>;
183+
using GrayT = GrayD<std::numeric_limits<U>::digits>;
184184

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>;
190190

191191
#if __has_include(<modm/io/iostream.hpp>)
192192
#include <modm/io/iostream.hpp>
193193

194194
template <int V>
195195
modm::IOStream &
196-
operator<<(modm::IOStream &os, const GrayT<V> &color)
196+
operator<<(modm::IOStream &os, const GrayD<V> &color)
197197
{
198198
os << color.value;
199199
return os;

src/modm/ui/color/hsv.hpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
/*
2-
* Copyright (c) 2009, Martin Rosekeit
3-
* Copyright (c) 2009-2013, Fabian Greif
4-
* Copyright (c) 2012-2013, 2015, Niklas Hauser
5-
* Copyright (c) 2013, David Hebbeker
62
* Copyright (c) 2021, Thomas Sommer
73
*
84
* This file is part of the modm project.
@@ -24,35 +20,39 @@
2420
namespace modm::color
2521
{
2622
/**
27-
* @brief Color in HSV Colorspace
23+
* @brief Color in HSV space. Each channel has it's own Memoryaddress.
24+
*
25+
* @tparam DH Bits for hue
26+
* @tparam DS Bits for saturation
27+
* @tparam DV Bits for value
2828
*
29-
* @author Martin Rosekeit, Fabian Greif, Niklas Hauser, David Hebbeker, Thomas Sommer
30-
* @ingroup modm_ui_color
29+
* @author Thomas Sommer
30+
* @ingroup modm_ui_color
3131
*/
32-
template<int WH, int WS = WH, int WV = WH>
33-
class HsvT
32+
template<int DH, int DS = DH, int DV = DH>
33+
class HsvD
3434
{
3535
public:
36-
using HueType = GrayT<WH>;
37-
using SaturationType = GrayT<WS>;
38-
using ValueType = GrayT<WV>;
36+
using HueType = GrayD<DH>;
37+
using SaturationType = GrayD<DS>;
38+
using ValueType = GrayD<DV>;
3939

40-
constexpr HsvT() = default;
40+
constexpr HsvD() = default;
4141

42-
constexpr HsvT(HueType hue, SaturationType saturation, ValueType value)
42+
constexpr HsvD(HueType hue, SaturationType saturation, ValueType value)
4343
: hue(hue), saturation(saturation), value(value)
4444
{}
4545

4646
template<ColorHsv C>
47-
constexpr HsvT(const C &other)
47+
constexpr HsvD(const C &other)
4848
: hue(other.hue), saturation(other.saturation), value(other.value)
4949
{}
5050

5151
template<ColorRgb C>
52-
constexpr HsvT(const C& rgb);
52+
constexpr HsvD(const C& rgb);
5353

5454
template<ColorRgbStacked CS>
55-
constexpr HsvT(const CS& rgbstacked) : HsvT(RgbT<CS::WR, CS::WG, CS::WB>(rgbstacked)) {}
55+
constexpr HsvD(const CS& rgbstacked) : HsvD(RgbD<CS::DR, CS::DG, CS::DB>(rgbstacked)) {}
5656

5757
void setHue(HueType hue) { this->hue = hue;}
5858
void setSaturation(SaturationType saturation) { this->saturation = saturation;}
@@ -64,37 +64,41 @@ class HsvT
6464

6565
static char* getSignature() {
6666
// TODO
67-
static char signature[10] = {"Hsv"}; // , str(WH), str(WS), str(WV), "\0"};
67+
static char signature[10] = {"Hsv"}; // , str(DH), str(DS), str(DV), "\0"};
6868
return signature;
6969
}
7070

7171
constexpr bool
72-
operator==(const HsvT& other) const = default;
72+
operator==(const HsvD& other) const = default;
7373

7474
private:
7575
HueType hue{0}; // TODO Hue may not saturate but wrap for arithmetic operations
7676
SaturationType saturation{0};
7777
ValueType value{0};
7878

7979
template<int, int, int>
80-
friend class HsvT;
80+
friend class HsvD;
8181

82-
template<int V>
82+
template<ColorHsv C>
8383
friend IOStream&
84-
operator<<(IOStream&, const HsvT<V>&);
84+
operator<<(IOStream&, const C&);
8585
};
8686

87+
template<std::unsigned_integral T>
88+
using HsvT = HsvD<std::numeric_limits<T>::digits>;
89+
8790
/// @ingroup modm_ui_color
88-
using Hsv888 = HsvT<8>;
91+
using Hsv888 = HsvD<8>; // Alternative using Hsv888 = HsvT<uint8_t>;
92+
using Hsv161616 = HsvD<16>; // Alternative using Hsv888 = HsvT<uint16_t>;
8993

9094
#if __has_include(<modm/io/iostream.hpp>)
9195
#include <modm/io/iostream.hpp>
9296

93-
template<int V>
97+
template<ColorHsv C>
9498
IOStream&
95-
operator<<(IOStream& os, const color::HsvT<V>& color)
99+
operator<<(IOStream& os, const C& hsv)
96100
{
97-
os << color.hue << "\t" << color.saturation << "\t" << color.value;
101+
os << hsv.getHue() << "\t" << hsv.getSaturation() << "\t" << hsv.getValue();
98102
return os;
99103
}
100104
#endif

src/modm/ui/color/hsv_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
/**
2424
* @see https://en.wikipedia.org/wiki/HSL_and_HSV
2525
*/
26-
template<int WH, int WS, int WV>
26+
template<int DH, int DS, int DV>
2727
template<modm::color::ColorRgb C>
28-
constexpr modm::color::HsvT<WH, WS, WV>::HsvT(const C& rgb)
28+
constexpr modm::color::HsvD<DH, DS, DV>::HsvD(const C& rgb)
2929
{
3030
using CalcType = float;
3131
using MaxValueType = C::RedType; // TODO smarter choice

0 commit comments

Comments
 (0)