@@ -67,10 +67,86 @@ uint32_t Color::to_ARGB32() const {
6767 return c;
6868}
6969
70+ uint32_t Color::to_ABGR32 () const {
71+ uint32_t c = (uint8_t )(a * 255 );
72+ c <<= 8 ;
73+ c |= (uint8_t )(b * 255 );
74+ c <<= 8 ;
75+ c |= (uint8_t )(g * 255 );
76+ c <<= 8 ;
77+ c |= (uint8_t )(r * 255 );
78+
79+ return c;
80+ }
81+
82+ uint64_t Color::to_ABGR64 () const {
83+ uint64_t c = (uint16_t )(a * 65535 );
84+ c <<= 16 ;
85+ c |= (uint16_t )(b * 65535 );
86+ c <<= 16 ;
87+ c |= (uint16_t )(g * 65535 );
88+ c <<= 16 ;
89+ c |= (uint16_t )(r * 65535 );
90+
91+ return c;
92+ }
93+
94+ uint64_t Color::to_ARGB64 () const {
95+ uint64_t c = (uint16_t )(a * 65535 );
96+ c <<= 16 ;
97+ c |= (uint16_t )(r * 65535 );
98+ c <<= 16 ;
99+ c |= (uint16_t )(g * 65535 );
100+ c <<= 16 ;
101+ c |= (uint16_t )(b * 65535 );
102+
103+ return c;
104+ }
105+
106+ uint32_t Color::to_RGBA32 () const {
107+ uint32_t c = (uint8_t )(r * 255 );
108+ c <<= 8 ;
109+ c |= (uint8_t )(g * 255 );
110+ c <<= 8 ;
111+ c |= (uint8_t )(b * 255 );
112+ c <<= 8 ;
113+ c |= (uint8_t )(a * 255 );
114+
115+ return c;
116+ }
117+
118+ uint64_t Color::to_RGBA64 () const {
119+ uint64_t c = (uint16_t )(r * 65535 );
120+ c <<= 16 ;
121+ c |= (uint16_t )(g * 65535 );
122+ c <<= 16 ;
123+ c |= (uint16_t )(b * 65535 );
124+ c <<= 16 ;
125+ c |= (uint16_t )(a * 65535 );
126+
127+ return c;
128+ }
129+
70130float Color::gray () const {
71131 return (r + g + b) / 3.0 ;
72132}
73133
134+ uint8_t Color::get_r8 () const {
135+ return (uint8_t )(r * 255.0 );
136+ }
137+
138+ uint8_t Color::get_g8 () const {
139+ return (uint8_t )(g * 255.0 );
140+ }
141+
142+ uint8_t Color::get_b8 () const {
143+ return (uint8_t )(b * 255.0 );
144+ }
145+
146+ uint8_t Color::get_a8 () const {
147+ return (uint8_t )(a * 255.0 );
148+ }
149+
74150float Color::get_h () const {
75151
76152 float min = MIN (r, g);
@@ -167,6 +243,74 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
167243 }
168244}
169245
246+ Color Color::darkened (const float p_amount) const {
247+ Color res = *this ;
248+ res.r = res.r * (1 .0f - p_amount);
249+ res.g = res.g * (1 .0f - p_amount);
250+ res.b = res.b * (1 .0f - p_amount);
251+ return res;
252+ }
253+
254+ Color Color::lightened (const float p_amount) const {
255+ Color res = *this ;
256+ res.r = res.r + (1 .0f - res.r ) * p_amount;
257+ res.g = res.g + (1 .0f - res.g ) * p_amount;
258+ res.b = res.b + (1 .0f - res.b ) * p_amount;
259+ return res;
260+ }
261+
262+ Color Color::from_hsv (float p_h, float p_s, float p_v, float p_a) const {
263+ p_h = ::fmod (p_h * 360 .0f , 360 .0f );
264+ if (p_h < 0.0 )
265+ p_h += 360 .0f ;
266+
267+ const float h_ = p_h / 60 .0f ;
268+ const float c = p_v * p_s;
269+ const float x = c * (1 .0f - ::fabs (::fmod (h_, 2 .0f ) - 1 .0f ));
270+ float r, g, b;
271+
272+ switch ((int )h_) {
273+ case 0 : {
274+ r = c;
275+ g = x;
276+ b = 0 ;
277+ } break ;
278+ case 1 : {
279+ r = x;
280+ g = c;
281+ b = 0 ;
282+ } break ;
283+ case 2 : {
284+ r = 0 ;
285+ g = c;
286+ b = x;
287+ } break ;
288+ case 3 : {
289+ r = 0 ;
290+ g = x;
291+ b = c;
292+ } break ;
293+ case 4 : {
294+ r = x;
295+ g = 0 ;
296+ b = c;
297+ } break ;
298+ case 5 : {
299+ r = c;
300+ g = 0 ;
301+ b = x;
302+ } break ;
303+ default : {
304+ r = 0 ;
305+ g = 0 ;
306+ b = 0 ;
307+ } break ;
308+ }
309+
310+ const float m = p_v - c;
311+ return Color (m + r, m + g, m + b, p_a);
312+ }
313+
170314void Color::invert () {
171315 r = 1.0 - r;
172316 g = 1.0 - g;
0 commit comments