UdonLibrary 1.0.0
機械システム研究部 C++ ライブラリ
読み取り中…
検索中…
一致する文字列を見つけられません
RGB.hpp
[詳解]
1//
2// RGB色空間 前方定義
3//
4// Copyright (c) 2022-2024 udonrobo
5//
6
7#pragma once
8
12
13namespace Udon
14{
15
16 struct HSV;
17
18
20 struct RGB
21 {
22
24 using ValueType = uint8_t;
25
28
31
34
36 constexpr RGB() noexcept
37 : r()
38 , g()
39 , b()
40 {
41 }
42
47 constexpr RGB(ValueType r, ValueType g, ValueType b) noexcept
48 : r(r)
49 , g(g)
50 , b(b)
51 {
52 }
53
56 RGB(uint32_t rgb) noexcept
57 : r(static_cast<ValueType>(rgb >> 16))
58 , g(static_cast<ValueType>(rgb >> 8))
59 , b(static_cast<ValueType>(rgb >> 0))
60 {
61 }
62
65 RGB(const HSV& hsv) noexcept;
66
68 RGB(const RGB&) = default;
69
71 RGB& operator=(const RGB&) = default;
72
73 template <typename FloatingPoint, Traits::EnableIfNullptrT<Traits::IsFloatingPoint<FloatingPoint>::value> = nullptr>
74 constexpr RGB operator*(FloatingPoint rhs) const noexcept
75 {
76 return {
77 static_cast<ValueType>(r * rhs),
78 static_cast<ValueType>(g * rhs),
79 static_cast<ValueType>(b * rhs)
80 };
81 }
82
83 template <typename FloatingPoint, Traits::EnableIfNullptrT<Traits::IsFloatingPoint<FloatingPoint>::value> = nullptr>
84 constexpr RGB operator/(FloatingPoint rhs) const noexcept
85 {
86 return {
87 static_cast<ValueType>(r / rhs),
88 static_cast<ValueType>(g / rhs),
89 static_cast<ValueType>(b / rhs)
90 };
91 }
92
93 constexpr bool operator==(const RGB& rhs) const noexcept
94 {
95 return r == rhs.r && g == rhs.g && b == rhs.b;
96 }
97
98 constexpr bool operator!=(const RGB& rhs) const noexcept
99 {
100 return !(*this == rhs);
101 }
102
103 explicit constexpr operator bool() const noexcept
104 {
105 return r || g || b;
106 }
107
110 uint32_t to24bit() const noexcept
111 {
112 return (static_cast<uint32_t>(r) << 16) | (static_cast<uint32_t>(g) << 8) | (static_cast<uint32_t>(b) << 0);
113 }
114
117 HSV toHSV() const noexcept;
118
119#ifdef ARDUINO
121 void show() const
122 {
123 Serial.print(F("r: ")), Serial.print(r), Serial.print('\t');
124 Serial.print(F("g: ")), Serial.print(g), Serial.print('\t');
125 Serial.print(F("b: ")), Serial.print(b), Serial.print('\t');
126 }
127#endif
128
130 };
131
132} // namespace Udon
#define F(x)
Definition Show.hpp:17
Definition Bit.hpp:12
HSV色空間
Definition HSV.hpp:20
RGB色空間
Definition RGB.hpp:21
uint8_t ValueType
要素の型
Definition RGB.hpp:24
ValueType r
赤成分
Definition RGB.hpp:27
UDON_ENUMERABLE(r, g, b)
constexpr RGB(ValueType r, ValueType g, ValueType b) noexcept
コンストラクタ
Definition RGB.hpp:47
ValueType g
緑成分
Definition RGB.hpp:30
HSV toHSV() const noexcept
HSV色空間に変換
Definition RGB.hpp:30
RGB(uint32_t rgb) noexcept
コンストラクタ
Definition RGB.hpp:56
constexpr RGB() noexcept
デフォルトコンストラクタ
Definition RGB.hpp:36
constexpr RGB operator*(FloatingPoint rhs) const noexcept
Definition RGB.hpp:74
constexpr RGB operator/(FloatingPoint rhs) const noexcept
Definition RGB.hpp:84
constexpr bool operator!=(const RGB &rhs) const noexcept
Definition RGB.hpp:98
ValueType b
青成分
Definition RGB.hpp:33
uint32_t to24bit() const noexcept
24bit値への変換
Definition RGB.hpp:110
RGB & operator=(const RGB &)=default
コピー代入演算子
constexpr bool operator==(const RGB &rhs) const noexcept
Definition RGB.hpp:93
RGB(const RGB &)=default
コピーコンストラクタ