acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
color.h
1#pragma once
2
3
4#include "acme/graphics/draw2d/color32.h"
5#include "acme/graphics/draw2d/opacity.h"
6#include "acme/graphics/image/color_indexes.h"
7
8
9struct rgba_t
10{
11
12 ::u32 m_u32;
13
14
15 constexpr ::u8 u8_red()const { return lower_byte(m_u32); }
16 constexpr ::u8 u8_green()const { return lower_byte(m_u32 >> 8); }
17 constexpr ::u8 u8_blue()const { return lower_byte(m_u32 >> 16); }
18 constexpr ::u8 u8_opacity()const { return lower_byte(m_u32 >> 24); }
19
20
21 constexpr bool operator == (const rgba_t & rgba) const { return m_u32 == rgba.m_u32; }
22
23
24};
25
26
27struct bgra_t
28{
29
30 ::u32 m_u32;
31
32
33 constexpr ::u8 u8_blue() const { return lower_byte(m_u32); }
34 constexpr ::u8 u8_green()const { return lower_byte(m_u32 >> 8); }
35 constexpr ::u8 u8_red() const { return lower_byte(m_u32 >> 16); }
36 constexpr ::u8 u8_opacity()const { return lower_byte(m_u32 >> 24); }
37
38
39 constexpr bool operator == (const bgra_t & rgba) const { return m_u32 == rgba.m_u32; }
40
41
42};
43
44
45
46constexpr ::color32_t argb32_color32(
47 ::iptr u8Opacity,
48 ::iptr u8Red,
49 ::iptr u8Green,
50 ::iptr u8Blue)
51{
52
53 return { make_u32(u8Red, u8Green, u8Blue, u8Opacity) };
54
55}
56
57
58//constexpr ::u8 color32_u8_red(::color32_t color32) { return lower_byte(color32.m_u32); }
59//constexpr ::u8 color32_u8_green(::color32_t color32) { return lower_byte(color32.m_u32 >> 8); }
60//constexpr ::u8 color32_u8_blue(::color32_t color32) { return lower_byte(color32.m_u32 >> 16); }
61//constexpr ::u8 color32_u8_opacity(::color32_t color32) { return lower_byte(color32.m_u32 >> 24); }
62
63
64
65//#define HLSMAX 100.0 /* H,L, and S vary over 0-HLSMAX */
66//#define RGBMAX 100.0 /* R,G, and B vary over 0-RGBMAX */
67/* HLSMAX BEST IF DIVISIBLE BY 6 */
68/* RGBMAX, HLSMAX must each fit in a ::u8. */
69/* Hue is undefined if Saturation is 0 (grey-scale) */
70/* This value determines where the Hue scrollbar is */
71/* initially set for achromatic colors */
72#define UNDEFINED_HUE (HLSMAX*2.0/3.0)
73
74
75
76
77//auto inline red(::color32_t rgba) { return ((::u8)(rgba & 0xff)); }
78//auto inline green(::color32_t rgba) { return ((::u8)((rgba >> 8) & 0xff)); }
79//auto inline blue(::color32_t rgba) { return ((::u8)((rgba >> 16) & 0xff)); }
80//auto inline opacity(::color32_t rgba) { return ((::u8)((rgba >> 24) & 0xff)); }
81
82
83namespace color
84{
85
86
87 class color;
88
89 class hsv;
90
91
92 struct HLS
93 {
94
95 ::f64 m_dH;
96 ::f64 m_dL;
97 ::f64 m_dS;
98
99 };
100
101
102 class CLASS_DECL_ACME hls :
103 public HLS
104 {
105 public:
106
107
108
109
110 hls(): HLS{ 0.0,0.0, 0.0 } {}
111 hls(enum_zero_init) : HLS{ 0.0,0.0, 0.0 } {}
112 hls(::f64 dH, ::f64 dL = 0.5, ::f64 dS = 1.0) :HLS{ dH, dL, dS } {}
113 hls(const ::color::color & color);
114 hls(const ::color::hsv & hsv);
115 hls & operator =(const ::payload & payload);
116
117
118 };
119
120 struct HSV
121 {
122
123 ::f64 m_dH;
124 ::f64 m_dS;
125 ::f64 m_dV;
126
127 };
128
129
130 class CLASS_DECL_ACME hsv :
131 public HSV
132 {
133 public:
134
135
136
137
138 hsv() {}
139 hsv(enum_zero_init) : HSV{ 0.0,0.0, 0.0 } {}
140 hsv(::f64 dH, ::f64 dS = 1.0, ::f64 dV = .5) :HSV{ dH, dS, dV } {}
141 hsv(const ::color::color & color);
142 hsv(const ::color::hls & hls);
143 hsv & operator =(const ::payload & payload);
144
145
146 };
147
148
149 enum enum_channel
150 {
151
152 e_channel_red = 0,
153 e_channel_green = 1,
154 e_channel_blue = 2,
155 e_channel_opacity = 3
156
157 };
158
159
160 class CLASS_DECL_ACME color :
161 public COLOR32
162 {
163 public:
164
165
166 constexpr color() { m_u8Red = m_u8Green = m_u8Blue = m_u8Opacity = 0; }
167 constexpr color(no_initialize_t) { }
168 template < prototype_number GRAY, prototype_number ALPHA >
169 constexpr color(GRAY gray, ALPHA u8Opacity) { set_red(gray); set_green(gray); set_blue(gray); set_opacity(u8Opacity); }
170 //template < prototype_number R, prototype_number G, prototype_number B >
171 //constexpr color(R r, G g, B b) { set_red(r); set_green(g); set_blue(b); }
172 //template < prototype_number R, prototype_number G, prototype_number B, prototype_number A >
173 //constexpr color(R r, G g, B b, A a) { set_red(r); set_green(g); set_blue(b); set_opacity(a); }
174 constexpr color(const ::color32_t & color32) { set(color32); }
175 constexpr color(const ::rgba_t & rgba) { set(rgba); }
176 constexpr color(const ::bgra_t & bgra) { set(bgra); }
177 constexpr color(const ::color::color & color) { m_u32 = color.m_u32; }
178 constexpr color(const ::color::color & color, const class ::opacity& opacity) { m_u32 = color.m_u32; m_u8Opacity = opacity.u8_opacity(); }
179 //color() { m_flags = -1; }
180//color(const ::color::color & color) { this->m_u32 =h color.m_u32; m_flags = color.m_flags; }
181 constexpr color(enum_plain_color eplaincolor);
182 constexpr color(enum_plain_color eplaincolor, ::u8 u8Opacity) : color(eplaincolor) { m_u8Opacity = u8Opacity; }
183 color(const hls & hls, ::u8 A = 255);
184 color(const hsv & hsv, ::u8 A = 255);
185 //color(const COLOR32 & color32, ::i32 flags = 0) { this->m_u32 = color32.m_u32; m_flags = flags; }
186 //color(::color32_t color32, ::i32 flags = 0) { this->m_u32 = color32; m_flags = flags; }
187 //color(::u8 R, ::u8 G, ::u8 B, ::u8 A = 255);
188
189 constexpr ::u8 u8_red() const { return m_u8Red; }
190 constexpr ::u8 u8_green() const { return m_u8Green; }
191 constexpr ::u8 u8_blue() const { return m_u8Blue; }
192 constexpr ::u8 u8_opacity() const { return m_u8Opacity; }
193 constexpr ::f32 f32_red() const { return m_u8Red / 255.f; }
194 constexpr ::f32 f32_green() const { return m_u8Green / 255.f; }
195 constexpr ::f32 f32_blue() const { return m_u8Blue / 255.f; }
196 constexpr ::f32 f32_opacity() const { return m_u8Opacity / 255.f; }
197 constexpr ::f64 f64_red() const { return m_u8Red / 255.; }
198 constexpr ::f64 f64_green() const { return m_u8Green / 255.; }
199 constexpr ::f64 f64_blue() const { return m_u8Blue / 255.; }
200 constexpr ::f64 f64_opacity() const { return m_u8Opacity / 255.; }
201
202 constexpr color contrasting_color() const {
203 ::f32 luminance = 0.299f * f32_red() + 0.587f * f32_green() + 0.144f * f32_blue();
204 return color(luminance < 0.5f ? 255 : 0, 255);
205 }
206
207 color & operator =(const ::payload & payload);
208
209
210 //};
211
212
213
214 // ::i32 m_flags;
215
216
217
218
220
221
222 constexpr bool is_opaque() const { return m_u8Opacity == 255; }
223 constexpr bool is_translucent() const { return m_u8Opacity > 0 && m_u8Opacity < 255; }
224 constexpr bool is_transparent() const { return m_u8Opacity == 0; }
225 constexpr bool non_transparent() const { return m_u8Opacity > 0; }
226 constexpr bool has_opacity() const { return non_transparent(); }
227
228
229 void hls_mult(::f64 dRateH, ::f64 dRateL, ::f64 dRateS);
230 void hls_rate(::f64 dRateH, ::f64 dRateL, ::f64 dRateS);
231 void hue_rate(::f64 dRateL);
232 void lightness_rate(::f64 dRateL);
233 void saturation_rate(::f64 dRateL);
234 constexpr void set(::rgba_t rgba);
235 //constexpr void set(::rgba_t rgba);
236 //constexpr void set_bgr(::bgra_t bgra);
237 constexpr void set(::bgra_t bgra);
238 void get_hls(::f64 & dHue, ::f64 & dLightness, ::f64 & dSaturation) const;
239 void get_hsv(::f64 & dHue, ::f64 & dBlack, ::f64 & dWhite) const;
240
241 static ::color::color from_hue(::f64 dHue);
242
243 void set_hls(::f64 dHue, ::f64 dLightness, ::f64 dSaturation);
244 void set_hsv(::f64 dHue, ::f64 dBlack, ::f64 dWhite);
245 void hls_mult(hls & hls);
246 void hls_rate(hls & hls);
247 void get_hls(hls & hls) const;
248 void get_hsv(hsv & hsv) const;
249 void set_hls(const hls & hls);
250 void set_hsv(const hsv & hsv);
251
252
253
254 ::color::hls get_hls() const { hls hls; get_hls(hls); return hls; }
255
256 ::color::hsv get_hsv() const { hsv hsv; get_hsv(hsv); return hsv; }
257
258 constexpr ::rgba_t rgba() const;
259 constexpr ::bgra_t bgra() const;
260 constexpr ::rgba_t rgb() const;
261 constexpr ::bgra_t bgr() const;
262 constexpr ::color32_t color32() const
263 {
264
265 return argb32_color32(
266 m_u8Opacity,
267 m_u8Red,
268 m_u8Green,
269 m_u8Blue);
270
271 }
272
273 // rgb & () {return m_rgb;}
274 // operator const rgb & () const {return m_rgb;}
275 // operator rgba & () {return m_rgba;}
276 // operator const rgba & () const {return m_rgba;}
277
278 template < typename R, typename G, typename B >
279 constexpr void set(R r, G g, B b) { set_red(r); set_green(g); set_blue(b); }
280
281 template < typename R, typename G, typename B, typename A >
282 constexpr void set(R r, G g, B b, A a) { set_red(r); set_green(g); set_blue(b); set_opacity(a); }
283
284 constexpr ::u8 set_red(::u8 r) { return this->m_u8Red = r; }
285
286 constexpr ::u8 set_green(::u8 g) { return this->m_u8Green = g; }
287
288 constexpr ::u8 set_blue(::u8 b) { return this->m_u8Blue = b; }
289
290 constexpr ::u8 set_opacity(::u8 a) { return this->m_u8Opacity = a; }
291
292 constexpr ::u16 set_red(::u16 r) { this->m_u8Red = r >> 8; return r; }
293
294 constexpr ::u16 set_green(::u16 g) { this->m_u8Green = g >> 8; return g;}
295
296 constexpr ::u16 set_blue(::u16 b) { this->m_u8Blue = b >> 8; return b;}
297
298 constexpr ::u16 set_opacity(::u16 a) { this->m_u8Opacity = a >> 8; return a;}
299
300 constexpr ::i32 set_red(::i32 r) { this->m_u8Red = r; return r; }
301
302 constexpr ::i32 set_green(::i32 g) { this->m_u8Green = g; return g; }
303
304 constexpr ::i32 set_blue(::i32 b) { this->m_u8Blue = b; return b;}
305
306 constexpr ::i32 set_opacity(::i32 a) { this->m_u8Opacity = a; return a;}
307
308 constexpr ::f32 set_red(::f32 f) { this->m_u8Red = (::u8)(f * 255.0f); return f; }
309
310 constexpr ::f32 set_green(::f32 f) { this->m_u8Green = (::u8)(f * 255.0f); return f; }
311
312 constexpr ::f32 set_blue(::f32 f) { this->m_u8Blue = (::u8)(f * 255.0f); return f; }
313
314 constexpr ::f32 set_opacity(::f32 f) { this->m_u8Opacity = (::u8)(f * 255.0f); return f; }
315
316 constexpr ::f64 set_red(::f64 f) { this->m_u8Red = (::u8)(f * 255.0); return f; }
317
318 constexpr ::f64 set_green(::f64 f) { this->m_u8Green = (::u8)(f * 255.0); return f; }
319
320 constexpr ::f64 set_blue(::f64 f) { this->m_u8Blue = (::u8)(f * 255.0); return f; }
321
322 constexpr ::f64 set_opacity(::f64 f) { this->m_u8Opacity = (::u8)(f * 255.0); return f; }
323
324 constexpr void set_opacity(class ::opacity opacity) { this->m_u8Opacity = (::u8)(opacity.u8_opacity() * 255.0); }
325
326 constexpr void set_opaque() { this->m_u8Opacity = 255; }
327
328 constexpr void set_unsigned_char(::u8 R, ::u8 G, ::u8 B) { m_u8Red = R; m_u8Green = G; m_u8Blue = B; m_u8Opacity = 255; }
329 constexpr void set_unsigned_char(::u8 R, ::u8 G, ::u8 B, ::u8 A) { m_u8Red = R; m_u8Green = G; m_u8Blue = B; m_u8Opacity = A; }
330 constexpr void set_f64(::f64 R, ::f64 G, ::f64 B) { m_u8Red = (::u8) (R * 255.); m_u8Green = (::u8) (G * 255.); m_u8Blue = (::u8) (B * 255.); m_u8Opacity = 255; }
331 constexpr void set_f64(::f64 R, ::f64 G, ::f64 B, ::f64 A) { m_u8Red = (::u8)(R * 255.); m_u8Green = (::u8) (G * 255.); m_u8Blue = (::u8) (B * 255.); m_u8Opacity = (::u8) (A * 255.); }
332
333 void make_black_and_white();
334
335 constexpr operator ::color32_t() const
336 {
337
338 return this->color32();
339
340 }
341
342
343 constexpr void set(::color32_t color32)
344 {
345
346 m_u8Red = color32.u8_red();
347 m_u8Green = color32.u8_green();
348 m_u8Blue = color32.u8_blue();
349 m_u8Opacity = color32.u8_opacity();
350
351 }
352
353
354 constexpr void set(const ::color::color & color)
355 {
356
357 m_u32 = color.m_u32;
358
359 }
360
361
362 constexpr color & operator = (const ::color::color & color);
363 constexpr color & operator = (::color32_t color32);
364 constexpr color & operator = (enum_plain_color ecolor);
365 color & operator = (const hls & hls);
366 color & operator = (const hsv & hsv);
367
368 bool parse_color(const ::scoped_string & scopedstr);
369
370 //void set_color32(::color32_t color32);
371
372 void hue_offset(::f64 dRadians);
373
374
375 constexpr auto byte_minimum_rgb() const { return minimum({ u8_red(), u8_green(), u8_blue() }); }
376 constexpr auto byte_maximum_rgb() const { return maximum({ u8_red(), u8_green(), u8_blue() }); }
377 constexpr auto f32_minimum_rgb() const { return byte_minimum_rgb() / 255.f; }
378 constexpr auto f32_maximum_rgb() const { return byte_maximum_rgb() / 255.f; }
379 constexpr auto f64_minimum_rgb() const { return byte_minimum_rgb() / 255.; }
380 constexpr auto f64_maximum_rgb() const { return byte_maximum_rgb() / 255.; }
381
382
383 constexpr ::color::color & rate_rgb_set_opacity(class ::opacity opacity, ::f64 dRate)
384 {
385
386 rate_red(dRate);
387 rate_green(dRate);
388 rate_blue(dRate);
389
390 set_opacity(opacity);
391
392 return *this;
393
394 }
395
396
397 constexpr void rate_red(::f64 dRate) { m_u8Red = (::u8)(m_u8Red * dRate); }
398 constexpr void rate_green(::f64 dRate) { m_u8Green = (::u8)(m_u8Green * dRate); }
399 constexpr void rate_blue(::f64 dRate) { m_u8Blue = (::u8)(m_u8Blue * dRate); }
400 constexpr void rate_opacity(::f64 dRate) { m_u8Opacity = (::u8)(m_u8Opacity * dRate); }
401
402
403 inline static bool similar_color_component(::f64 d1, ::f64 d2) { return fabs(d2 - d1) < (1.0 / 255.0); }
404
405 constexpr bool operator == (const ::color::color& color) const { return m_u32 == color.m_u32; }
406 constexpr bool operator == (::color32_t color32) const { return this->operator color32_t().m_u32 == color32.m_u32; }
407 constexpr bool operator == (enum_plain_color ecolor) const { return m_u32 == ::color::color(ecolor).m_u32; }
408 bool operator == (const hls & hls) const
409 {
410
411 auto hlsThis = get_hls();
412
413 return similar_color_component(hlsThis.m_dH, hls.m_dH)
414 && similar_color_component(hlsThis.m_dL, hls.m_dL)
415 && similar_color_component(hlsThis.m_dS, hls.m_dS);
416 }
417 //bool operator != (const ::color::color & color) const { return !operator == (color); }
418 //bool operator != (::color32_t color32) const { return !operator == (color32); }
419 //bool operator != (enum_plain_color ecolor) const { return !operator == (ecolor); }
420 //bool operator != (const hls & hls) const { return !operator == (hls); }
421
422
423
424
425 void blend(const ::color::color & color, ::f64 dRate)
426 {
427
428 ::f64 dComplement = 1.0 - dRate;
429
430 m_u8Red = (::u8)(m_u8Red * dComplement + color.m_u8Red * dRate);
431 m_u8Green = (::u8)(m_u8Green * dComplement + color.m_u8Green * dRate);
432 m_u8Blue = (::u8)(m_u8Blue * dComplement + color.m_u8Blue * dRate);
433 m_u8Opacity = (::u8)(m_u8Opacity * dComplement + color.m_u8Opacity * dRate);
434
435 }
436
437 ::color::color get_blend(const ::color::color& color, ::f64 dRate) const
438 {
439
440 ::color::color colorResult(*this);
441
442 colorResult.blend(color, dRate);
443
444 return colorResult;
445
446 }
447
448 //::f64 get_opacity_rate() const { return f64_opacity(); }
449 //::f64 get_red_rate() const { return f64_red(); }
450 //::f64 get_green_rate() const { return f64_green(); }
451 //::f64 get_blue_rate() const { return f64_blue(); }
452
453 constexpr ::f64 get_luminance() const { return (m_u8Red + m_u8Green + m_u8Blue) / (255.0 * 3.0); }
454 ::f64 get_saturation() const { return get_hls().m_dS; }
455 ::f64 get_hue() const { return get_hls().m_dH; }
456
457 constexpr auto opaque() const { return *this & ::opacity(255); }
458
459
460 constexpr color & operator &=(const class ::opacity & opacity)
461 {
462
463 this->m_u8Opacity = opacity.u8_opacity();
464
465 return *this;
466
467 }
468
469
470 //constexpr color& operator &=(color32_t color32)
471 //{
472
473 // m_u32 &= color32;
474
475 // return *this;
476
477 //}
478
479 constexpr color operator &(const class ::opacity & opacity) const
480 {
481
482 color color(*this);
483
484 color &= opacity;
485
486 return color;
487
488 }
489
490
491 //constexpr color operator &(color32_t color32) const
492 //{
493
494 // color color(*this);
495
496 // color.m_u32 &= color32;
497
498 // return color;
499
500 //}
501
502 //constexpr ::color::color plain_color(enum_plain_color ecolor);
503
504
505 };
506
507
508 CLASS_DECL_ACME extern color transparent;
509 CLASS_DECL_ACME extern color black;
510 CLASS_DECL_ACME extern color red;
511 CLASS_DECL_ACME extern color green;
512 CLASS_DECL_ACME extern color blue;
513 CLASS_DECL_ACME extern color yellow;
514 CLASS_DECL_ACME extern color cyan;
515 CLASS_DECL_ACME extern color magenta;
516 CLASS_DECL_ACME extern color gray;
517 CLASS_DECL_ACME extern color white;
518
519
520 using array = ::array < color >;
521
522
523
524//
525// Color utils
526//
527// Colors in NanoVG are stored as ::u32 ints in ABGR format.
528
529// Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
530//CLASS_DECL_ACME ::color::color RGB_color(::u8 r, ::u8 g, ::u8 b);
531
532// Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
533//CLASS_DECL_ACME ::color::color RGBf_color(::f32 r, ::f32 g, ::f32 b);
534
535// Returns a color value from red, green, blue and m_u8Opacity values.
536//CLASS_DECL_ACME ::color::color RGBA_color(::u8 r, ::u8 g, ::u8 b, ::u8 a);
537
538// Returns a color value from red, green, blue and m_u8Opacity values.
539//CLASS_DECL_ACME::color::color RGBAf_color(::f32 r, ::f32 g, ::f32 b, ::f32 a);
540
541// Linearly interpolates from color c0 to c1, and returns resulting color value.
542CLASS_DECL_ACME::color::color LerpRGBA_color(color c0, color c1, ::f64 u);
543
544// Sets transparency of a color value.
545CLASS_DECL_ACME::color::color TransRGBA_color(color c0, ::u8 a);
546
547// Sets transparency of a color value.
548CLASS_DECL_ACME::color::color TransRGBAf(color c0, ::f64 a);
549
550// Returns color value specified by hue, saturation and lightness.
551// HSL values are all in range [0..1], m_u8Opacity will be set to 255.
552CLASS_DECL_ACME::color::color HSL_color(::f64 h, ::f64 s, ::f64 l);
553
554// Returns color value specified by hue, saturation and lightness and m_u8Opacity.
555// HSL values are all in range [0..1], m_u8Opacity in range [0..255]
556CLASS_DECL_ACME ::color::color HSLA_color(::f64 h, ::f64 s, ::f64 l, ::u8 a);
557
558
559} // namespace color
560
561
562constexpr ::color::color color_with_u8_opacity(::u8 bAlpha, ::color32_t color);
563constexpr ::color::color color_with_u8_opacity(::u8 bAlpha, enum_plain_color ecolor);
564constexpr ::color::color opaque_color(::color32_t color32);
565//constexpr ::color::color _color(enum_plain_color ecolor);
566constexpr ::color::color opaque_color(enum_plain_color ecolor);
567
568
569
570constexpr rgba_t argb_rgba(::u8 u8Opacity, ::u8 u8Red, ::u8 u8Green, ::u8 u8Blue)
571{
572 return { make_u32(u8Red, u8Green, u8Blue, u8Opacity) };
573}
574
575//constexpr ::u8 rgba_u8_red(::rgba_t rgba) { return lower_byte(rgba.m_u32); }
576//constexpr ::u8 rgba_u8_green(::rgba_t rgba) { return lower_byte(rgba.m_u32 >> 8); }
577//constexpr ::u8 rgba_u8_blue(::rgba_t rgba) { return lower_byte(rgba.m_u32 >> 16); }
578//constexpr ::u8 rgba_u8_opacity(::rgba_t rgba) { return lower_byte(rgba.m_u32 >> 24); }
579
580
581//constexpr ::u8 bgr_u8_blue(::u32 bgr) { return lower_byte(bgr); }
582//constexpr ::u8 bgr_u8_green(::u32 bgr) { return lower_byte((bgr) >> 8); }
583//constexpr ::u8 bgr_u8_red(::u32 bgr) { return lower_byte((bgr) >> 16); }
584//constexpr ::u8 bgr_u8_opacity(::u32 bgr) { return lower_byte((bgr) >> 24); }
585
586
587constexpr bgra_t argb_bgra(::u8 u8Opacity, ::u8 u8Red, ::u8 u8Green, ::u8 u8Blue)
588{
589 return { make_u32(u8Blue, u8Green, u8Red, u8Opacity) };
590}
591
592
593
594//CLASS_DECL_ACME void __exchange(::stream & s, ::color::color & color);
595//
596//
597//
598//CLASS_DECL_ACME void __exchange(::stream & s, ::color::hls & hls);
599
600
601CLASS_DECL_ACME ::payload & assign(::payload & payload, const ::color::hls & hls);
602
603//struct image_argb_type {};
604
605//constexpr auto red(const ::color::color & color) { return color.m_u8Red; }
606//constexpr auto green(const ::color::color & color) { return color.m_u8Green; }
607//constexpr auto blue(const ::color::color & color) { return color.m_u8Blue; }
608//constexpr auto opacity(const ::color::color & color) { return color.m_u8Opacity; }
609
610template < typename RED, typename GREEN, typename BLUE, typename OPACITY >
611constexpr auto rgba(RED red, GREEN green, BLUE blue, OPACITY opacity)
612{
613
615
616 color.set_red(red);
617 color.set_green(green);
618 color.set_blue(blue);
619 color.set_opacity(opacity);
620
621 return color;
622
623}
624
625
626template < typename RED, typename GREEN, typename BLUE >
627constexpr auto rgb(RED red, GREEN green, BLUE blue)
628{
629
630 return rgba(red, green, blue, 255);
631
632}
633
634
635
636
637template < typename OPACITY, typename RED, typename GREEN, typename BLUE >
638constexpr auto argb(OPACITY opacity, RED red, GREEN green, BLUE blue)
639{
640
642
643 color.set_opacity(opacity);
644 color.set_red(red);
645 color.set_green(green);
646 color.set_blue(blue);
647
648 return color;
649
650}
651
652inline constexpr auto hex_color(::u8 opacity, ::u32 rgb)
653{
655
656 color.set_opacity(opacity);
657 color.set_red((::u8)((rgb >> 16) & 0xff));
658 color.set_green((::u8)((rgb >> 8) & 0xff));
659 color.set_blue((::u8)(rgb & 0xff));
660
661 return color;
662}
663
664//constexpr auto opacity(const class ::opacity & opacity, const ::color::color& rgb) { return ::color::color(rgb, opacity); }
665//constexpr auto opaque(const ::color::color& color) { return opacity(255, color); }
666
667
668CLASS_DECL_ACME::color::color _020GetColor(::collection::index i);
669
670
671//constexpr ::color::color argb(::i32 a, ::i32 r, ::i32 g, ::i32 b)
672//{
673//
674// return ::color::color(r, g, b, a);
675//
676//}
677
678
679//constexpr ::color::color argb(::f64 a, ::f64 r, ::f64 g, ::f64 b)
680//{
681//
682// return ::color::color(r, g, b, a);
683//
684//}
685
686
687namespace color
688{
689
690
691 constexpr color::color(enum_plain_color eplaincolor)
692 {
693
694 ::u32 ui;
695
696 switch (eplaincolor)
697 {
698 case e_plain_color_black:
699 ui = ::rgb(0, 0, 0).m_u32;
700 break;
701 case e_plain_color_red:
702 ui = ::rgb(255, 0, 0).m_u32;
703 break;
704 case e_plain_color_green:
705 ui = ::rgb(0, 255, 0).m_u32;
706 break;
707 case e_plain_color_blue:
708 ui = ::rgb(0, 0, 255).m_u32;
709 break;
710 case e_plain_color_white:
711 ui = ::rgb(255, 255, 255).m_u32;
712 break;
713 case e_plain_color_yellow:
714 ui = ::rgb(255, 255, 0).m_u32;
715 break;
716 case e_plain_color_magenta:
717 ui = ::rgb(255, 0, 255).m_u32;
718 break;
719 case e_plain_color_cyan:
720 ui = ::rgb(0, 255, 255).m_u32;
721 break;
722 case e_plain_color_gray:
723 ui = ::rgb(127, 127, 127).m_u32;
724 break;
725 default:
726 ui = 0;
727 break;
728 };
729
730 m_u32 = ui;
731
732 }
733
734
735 constexpr ::color::color & color::operator = (const ::color::color & color)
736 {
737
738 if (&color != this)
739 {
740
741 m_u8Red = color.m_u8Red;
742 m_u8Green = color.m_u8Green;
743 m_u8Blue = color.m_u8Blue;
744 m_u8Opacity = color.m_u8Opacity;
745
746 }
747
748 return *this;
749
750 }
751
752
753 constexpr ::color::color & color::operator = (::color32_t color32)
754 {
755
756 set(color32);
757
758 return *this;
759
760 }
761
762
763 constexpr ::color::color & color::operator = (enum_plain_color eplaincolor)
764 {
765
766 return operator=(color(eplaincolor));
767
768 }
769
770
771 constexpr rgba_t color::rgba() const
772 {
773
774 return argb_rgba(m_u8Opacity, m_u8Red, m_u8Green, m_u8Blue);
775
776 }
777
778
779 constexpr bgra_t color::bgra() const
780 {
781
782 return argb_bgra(m_u8Opacity, m_u8Red, m_u8Green, m_u8Blue);
783
784 }
785
786
787 constexpr rgba_t color::rgb() const
788 {
789
790 return this->rgba();
791
792 }
793
794
795 constexpr bgra_t color::bgr() const
796 {
797
798 return this->bgra();
799
800 }
801
802
803 constexpr void color::set(::rgba_t rgba)
804 {
805
806 m_u8Red = rgba.u8_red();
807 m_u8Green = rgba.u8_green();
808 m_u8Blue = rgba.u8_blue();
809 m_u8Opacity = rgba.u8_opacity();
810
811 }
812
813
814 constexpr void color::set(bgra_t bgra)
815 {
816
817 m_u8Red = bgra.u8_red();
818 m_u8Green = bgra.u8_green();
819 m_u8Blue = bgra.u8_blue();
820 m_u8Opacity = bgra.u8_opacity();
821
822 }
823
824
825 CLASS_DECL_ACME ::color::color hex_to_color(const_char_pointer psz);
826
827 //constexpr void color::set_bgr(::u32 ui)
828 //{
829
830 // m_u8Red = bgr_u8_red(ui);
831 // m_u8Green = bgr_u8_green(ui);
832 // m_u8Blue = bgr_u8_blue(ui);
833 // m_u8Opacity = bgr_u8_opacity(ui);
834
835 //}
836
837
838 //constexpr void color::set_bgra(::u32 ui)
839 //{
840
841 // m_u8Red = bgra_u8_red(ui);
842 // m_u8Green = bgra_u8_green(ui);
843 // m_u8Blue = bgra_u8_blue(ui);
844 // m_u8Opacity = bgra_u8_opacity(ui);
845
846 //}
847
848} // namespace color
849
850
851constexpr ::color::color color_with_u8_opacity(::u8 bAlpha, ::color32_t color32)
852{
853
854 ::color::color color;
855
856 color.m_u32 = (color32.m_u32 & 0xffffff) | ((bAlpha & 0xff) << 24);
857
858 return color;
859
860}
861
862
863constexpr::color::color color_with_u8_opacity(::u8 bAlpha, enum_plain_color ecolor)
864{
865
866 return color_with_u8_opacity(bAlpha, ::color::color(ecolor));
867
868}
869
870
871constexpr ::color::color opaque_color(::color32_t color32)
872{
873
874 return color_with_u8_opacity(255, color32);
875
876}
877
878
879constexpr ::color::color opaque_color(enum_plain_color ecolor)
880{
881
882 return opaque_color(::color::color(ecolor));
883
884}
885
886
887
888
889
890constexpr ::color::color color32_color_with_u8_opacity(::u8 u8Opacity, ::color32_t color32)
891{
892
893 return argb(u8Opacity, color32.u8_red(), color32.u8_green(), color32.u8_blue());
894
895}
896
897
898//constexpr ::color::color color32_color(color32_t color32)
899//{
900//
901// ::color::color color;
902//
903// color.m_u8Red = color32_u8_red(color32);
904// color.m_u8Green = color32_u8_green(color32);
905// color.m_u8Blue = color32_u8_blue(color32);
906// color.m_u8Opacity = color32_u8_opacity(color32);
907//
908// return color;
909//
910//}
911
912
913#define __expand_f32_rgba(color) color.f32_red(), color.f32_green(), color.f32_blue(), color.f32_opacity()
914#define __expand_f64_rgba(color) color.f64_red(), color.f64_green(), color.f64_blue(), color.f64_opacity()
915#define __expand_f32_rgb(color) color.f32_red(), color.f32_green(), color.f32_blue()
916#define __expand_f64_rgb(color) color.f64_red(), color.f64_green(), color.f64_blue()
917
918
919
920namespace color
921{
922
923
924 inline hls::hls(const ::color::color & color)
925 {
926
927 operator=(color.get_hls());
928
929 }
930
931
932
933
934 inline hsv::hsv(const ::color::color & color)
935 {
936
937 operator=(color.get_hsv());
938
939 }
940
941
942} // namespace color
943
944
945
Definition color32.h:65
Definition color.h:162
constexpr bool is_opaque() const
bool is_set() const { return m_flags >= 0; }
Definition color.h:222
Definition color.h:104
Definition color.h:132
Definition opacity.h:8
Definition payload.h:54
Definition color.h:28
Definition color32.h:12
Definition color.h:93
Definition color.h:121
Definition _tags.h:5
Definition color.h:10