UdonLibrary
1.0.0
機械システム研究部 C++ ライブラリ
Toggle main menu visibility
読み取り中…
検索中…
一致する文字列を見つけられません
RGB.hpp
[詳解]
1
//
2
// RGB色空間 前方定義
3
//
4
// Copyright (c) 2022 udonrobo
5
//
6
7
#pragma once
8
9
#include <
Udon/Traits/EnumerableMacro.hpp
>
10
#include <
Udon/Serializer/Serializer.hpp
>
11
#include <
Udon/Traits/Typedef.hpp
>
12
13
namespace
Udon
14
{
15
16
struct
HSV
;
17
18
20
struct
RGB
21
{
22
24
using
ValueType
= uint8_t;
25
27
ValueType
r
;
28
30
ValueType
g
;
31
33
ValueType
b
;
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
129
UDON_ENUMERABLE
(
r
,
g
,
b
);
130
};
131
132
}
// namespace Udon
EnumerableMacro.hpp
Serializer.hpp
F
#define F(x)
Definition
Show.hpp:17
Typedef.hpp
Udon
Definition
Bit.hpp:12
Udon::HSV
HSV色空間
Definition
HSV.hpp:20
Udon::RGB::ValueType
uint8_t ValueType
要素の型
Definition
RGB.hpp:24
Udon::RGB::r
ValueType r
赤成分
Definition
RGB.hpp:27
Udon::RGB::UDON_ENUMERABLE
UDON_ENUMERABLE(r, g, b)
Udon::RGB::RGB
constexpr RGB(ValueType r, ValueType g, ValueType b) noexcept
コンストラクタ
Definition
RGB.hpp:47
Udon::RGB::g
ValueType g
緑成分
Definition
RGB.hpp:30
Udon::RGB::toHSV
HSV toHSV() const noexcept
HSV色空間に変換
Definition
RGB.hpp:30
Udon::RGB::RGB
RGB(uint32_t rgb) noexcept
コンストラクタ
Definition
RGB.hpp:56
Udon::RGB::RGB
constexpr RGB() noexcept
デフォルトコンストラクタ
Definition
RGB.hpp:36
Udon::RGB::operator*
constexpr RGB operator*(FloatingPoint rhs) const noexcept
Definition
RGB.hpp:74
Udon::RGB::operator/
constexpr RGB operator/(FloatingPoint rhs) const noexcept
Definition
RGB.hpp:84
Udon::RGB::operator!=
constexpr bool operator!=(const RGB &rhs) const noexcept
Definition
RGB.hpp:98
Udon::RGB::b
ValueType b
青成分
Definition
RGB.hpp:33
Udon::RGB::to24bit
uint32_t to24bit() const noexcept
24bit値への変換
Definition
RGB.hpp:110
Udon::RGB::operator=
RGB & operator=(const RGB &)=default
コピー代入演算子
Udon::RGB::operator==
constexpr bool operator==(const RGB &rhs) const noexcept
Definition
RGB.hpp:93
Udon::RGB::RGB
RGB(const RGB &)=default
コピーコンストラクタ