15const std::array<const char*, 33> palette16code = {
37 return red_ == rhs.red_ && green_ == rhs.green_ && blue_ == rhs.blue_ &&
46 if (is_background_color) {
48 case ColorType::Palette1:
50 case ColorType::Palette16:
51 return palette16code[2 * red_ + 1];
52 case ColorType::Palette256:
53 return "48;5;" + std::to_string(red_);
54 case ColorType::TrueColor:
55 return "48;2;" + std::to_string(red_) +
";" + std::to_string(green_) +
56 ";" + std::to_string(blue_);
60 case ColorType::Palette1:
62 case ColorType::Palette16:
63 return palette16code[2 * red_];
64 case ColorType::Palette256:
65 return "38;5;" + std::to_string(red_);
66 case ColorType::TrueColor:
67 return "38;2;" + std::to_string(red_) +
";" + std::to_string(green_) +
68 ";" + std::to_string(blue_);
83 : type_(ColorType::
Palette16), red_(index), alpha_(255) {}
87 : type_(ColorType::
Palette256), red_(index), alpha_(255) {
91 type_ = ColorType::Palette16;
103 : type_(ColorType::TrueColor),
113 const int max_distance = 256 * 256 * 3;
114 int closest = max_distance;
116 const int database_begin = 16;
117 const int database_end = 256;
118 for (
int i = database_begin; i < database_end; ++i) {
120 const int dr = color_info.
red - red;
121 const int dg = color_info.
green - green;
122 const int db = color_info.
blue - blue;
123 const int dist = dr * dr + dg * dg + db * db;
124 if (closest > dist) {
131 type_ = ColorType::Palette256;
134 type_ = ColorType::Palette16;
147 return RGBA(red, green, blue, 255);
159 return {red, green, blue, alpha};
171 uint8_t region = h / 43;
172 uint8_t remainder = (h - (region * 43)) * 6;
173 uint8_t p = (v * (255 - s)) >> 8;
174 uint8_t q = (v * (255 - ((s * remainder) >> 8))) >> 8;
175 uint8_t t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
179 case 0:
return Color(v,t,p, alpha);
180 case 1:
return Color(q,v,p, alpha);
181 case 2:
return Color(p,v,t, alpha);
182 case 3:
return Color(p,q,v, alpha);
183 case 4:
return Color(t,p,v, alpha);
184 case 5:
return Color(v,p,q, alpha);
187 return {0, 0, 0, alpha};
198 return HSVA(h, s, v, 255);
203 if (a.type_ == ColorType::Palette1 ||
204 b.type_ == ColorType::Palette1) {
213 uint8_t* red, uint8_t* green, uint8_t* blue) {
214 switch (color.type_) {
215 case ColorType::Palette1: {
219 case ColorType::Palette16: {
227 case ColorType::Palette256: {
235 case ColorType::TrueColor:
238 *green = color.green_;
251 get_color(a, &a_r, &a_g, &a_b);
252 get_color(b, &b_r, &b_g, &b_b);
256 auto interp = [t](uint8_t a_u, uint8_t b_u) {
257 constexpr float gamma = 2.2F;
258 const float a_f = powf(a_u, gamma);
259 const float b_f = powf(b_u, gamma);
260 const float c_f = a_f * (1.0F - t) +
262 return static_cast<uint8_t
>(powf(c_f, 1.F / gamma));
273 out.alpha_ = lhs.alpha_ + rhs.alpha_ - lhs.alpha_ * rhs.alpha_ / 255;
279Color operator""_rgb(
unsigned long long int combined) {
281 auto const red =
static_cast<uint8_t
>(combined >> 16U);
282 auto const green =
static_cast<uint8_t
>(combined >> 8U);
283 auto const blue =
static_cast<uint8_t
>(combined);
284 return {red, green, blue};
Decorator color(Color)
前景色を使用して装飾します。
static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value)
HSV表現から色を構築します。 https://en.wikipedia.org/wiki/HSL_and_HSV.
static Color RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
RGBA表現から色を構築します。 https://en.wikipedia.org/wiki/RGB_color_model.
static Color Blend(const Color &lhs, const Color &rhs)
アルファチャンネルを使用して2つの色をブレンドします。
bool operator!=(const Color &rhs) const
bool operator==(const Color &rhs) const
static Color RGB(uint8_t red, uint8_t green, uint8_t blue)
RGB表現から色を構築します。 https://en.wikipedia.org/wiki/RGB_color_model.
std::string Print(bool is_background_color) const
static Color Interpolate(float t, const Color &a, const Color &b)
static Color HSVA(uint8_t hue, uint8_t saturation, uint8_t value, uint8_t alpha)
HSV表現から色を構築します。 https://en.wikipedia.org/wiki/HSL_and_HSV.
Colorは、ターミナルユーザーインターフェースにおける色を表すクラスです。
ColorInfoは、ターミナルのカラーパレットに関する情報を含む構造体です。
ColorInfo GetColorInfo(Color::Palette256 index)
FTXUI ftxui::literals::名前空間