16 r = r * int(other_color.
r_) / 255;
17 g = g * int(other_color.
g_) / 255;
18 b = b * int(other_color.
b_) / 255;
24 const int s =
static_cast<int>(
scale * 255.0f);
26 int r =
static_cast<int>(
r_) * s / 255;
27 int g =
static_cast<int>(
g_) * s / 255;
28 int b =
static_cast<int>(
b_) * s / 255;
45 if ((255 -
r_) < color.
r_)
r_ = 255;
47 if ((255 -
g_) < color.
g_)
g_ = 255;
49 if ((255 -
b_) < color.
b_)
b_ = 255;
55 const uint8_t* rgb =
At(rgb_index);
56 return rgb ? *rgb : 0;
61 uint8_t* rgb =
At(rgb_index);
71 }
else if (1.0f <=
t) {
75 Color3i new_color = other_color;
76 new_color.
Mul(1.0f -
t);
103 typedef double FloatT;
104 FloatT r = (FloatT) rgb.
r_/255.f;
105 FloatT g = (FloatT) rgb.
g_/255.f;
106 FloatT b = (FloatT) rgb.
b_/255.f;
107 FloatT max_rgb =
MAX(r,
MAX(g, b));
108 FloatT min_rgb =
MIN(r,
MIN(g, b));
111 FloatT d = max_rgb - min_rgb;
112 s_ = max_rgb == 0 ? 0 : d / max_rgb;
114 if (max_rgb == min_rgb) {
118 h_ = (g - b) / d + (g < b ? 6 : 0);
119 }
else if (max_rgb == g) {
120 h_ = (b - r) / d + 2;
121 }
else if (max_rgb == b) {
122 h_ = (r - g) / d + 4;
130 typedef double FloatT;
136 FloatT f =
h_ * 6.0 -
static_cast<FloatT
>(i);
137 FloatT p =
v_ * (1.0 -
s_);
138 FloatT q =
v_ * (1.0 - f *
s_);
139 FloatT
t =
v_ * (1.0 - (1.0 - f) *
s_);
142 case 0: r =
v_, g =
t, b = p;
break;
143 case 1: r = q, g =
v_, b = p;
break;
144 case 2: r = p, g =
v_, b =
t;
break;
145 case 3: r = p, g = q, b =
v_;
break;
146 case 4: r =
t, g = p, b =
v_;
break;
147 case 5: r =
v_, g = p, b = q;
break;
void Add(const Color3i &color)
Color3i(uint8_t r, uint8_t g, uint8_t b)
void Mul(const Color3i &other_color)
void Interpolate(const Color3i &other_color, float t)
void Sub(const Color3i &color)
void Set(uint8_t r, uint8_t g, uint8_t b)
uint8_t * At(int rgb_index)
uint8_t Get(int rgb_index) const
void FromRGB(const Color3i &rgb)