C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
argb_color.hpp
1/*
2 * Copyright (c) 2024 The RefValue Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <cstdint>
26#include <limits>
27#include <type_traits>
28
29namespace essence {
33 struct alignas(std::uint32_t) argb_color {
34 std::uint8_t r{};
35 std::uint8_t g{};
36 std::uint8_t b{};
37 std::uint8_t alpha{0xFF};
38
42 constexpr explicit operator std::uint32_t() const noexcept {
43 return (static_cast<std::uint32_t>(alpha) << 24) + (static_cast<std::uint32_t>(b) << 16)
44 + (static_cast<std::uint32_t>(g) << 8) + r;
45 }
46
54 template <typename T>
55 requires std::is_arithmetic_v<T>
56 constexpr auto normalize(T min, T max) const noexcept {
57 constexpr auto source_range =
58 std::numeric_limits<std::uint8_t>::max() - std::numeric_limits<std::uint8_t>::min();
59 auto convert = [&](std::uint8_t value) { return value * (max - min) / static_cast<T>(source_range) + min; };
60
61 struct normalized_color {
62 T r;
63 T g;
64 T b;
65 T alpha;
66 } result{convert(r), convert(g), convert(b), convert(alpha)};
67
68 return result;
69 }
70 };
71
77 constexpr argb_color make_argb_color(std::uint32_t color) noexcept {
78 return argb_color{
79 .r = static_cast<std::uint8_t>(color),
80 .g = static_cast<std::uint8_t>(color >> 8),
81 .b = static_cast<std::uint8_t>(color >> 16),
82 .alpha = static_cast<std::uint8_t>(color >> 24),
83 };
84 }
85
90 struct argb_colors {
91 static constexpr argb_color alice_blue{
92 .r = 240,
93 .g = 248,
94 .b = 255,
95 };
96
97 static constexpr argb_color light_salmon{
98 .r = 255,
99 .g = 160,
100 .b = 122,
101 };
102
103 static constexpr argb_color antique_white{
104 .r = 250,
105 .g = 235,
106 .b = 215,
107 };
108
109 static constexpr argb_color light_sea_green{
110 .r = 32,
111 .g = 178,
112 .b = 170,
113 };
114
115 static constexpr argb_color aqua{
116 .r = 0,
117 .g = 255,
118 .b = 255,
119 };
120
121 static constexpr argb_color light_sky_blue{
122 .r = 135,
123 .g = 206,
124 .b = 250,
125 };
126
127 static constexpr argb_color aquamarine{
128 .r = 127,
129 .g = 255,
130 .b = 212,
131 };
132
133 static constexpr argb_color light_slate_gray{
134 .r = 119,
135 .g = 136,
136 .b = 153,
137 };
138
139 static constexpr argb_color azure{
140 .r = 240,
141 .g = 255,
142 .b = 255,
143 };
144
145 static constexpr argb_color light_steel_blue{
146 .r = 176,
147 .g = 196,
148 .b = 222,
149 };
150
151 static constexpr argb_color beige{
152 .r = 245,
153 .g = 245,
154 .b = 220,
155 };
156
157 static constexpr argb_color light_yellow{
158 .r = 255,
159 .g = 255,
160 .b = 224,
161 };
162
163 static constexpr argb_color bisque{
164 .r = 255,
165 .g = 228,
166 .b = 196,
167 };
168
169 static constexpr argb_color lime{
170 .r = 0,
171 .g = 255,
172 .b = 0,
173 };
174
175 static constexpr argb_color black{
176 .r = 0,
177 .g = 0,
178 .b = 0,
179 };
180
181 static constexpr argb_color lime_green{
182 .r = 50,
183 .g = 205,
184 .b = 50,
185 };
186
187 static constexpr argb_color blanched_almond{
188 .r = 255,
189 .g = 255,
190 .b = 205,
191 };
192
193 static constexpr argb_color linen{
194 .r = 250,
195 .g = 240,
196 .b = 230,
197 };
198
199 static constexpr argb_color blue{
200 .r = 0,
201 .g = 0,
202 .b = 255,
203 };
204
205 static constexpr argb_color magenta{
206 .r = 255,
207 .g = 0,
208 .b = 255,
209 };
210
211 static constexpr argb_color blue_violet{
212 .r = 138,
213 .g = 43,
214 .b = 226,
215 };
216
217 static constexpr argb_color maroon{
218 .r = 128,
219 .g = 0,
220 .b = 0,
221 };
222
223 static constexpr argb_color brown{
224 .r = 165,
225 .g = 42,
226 .b = 42,
227 };
228
229 static constexpr argb_color medium_aquamarine{
230 .r = 102,
231 .g = 205,
232 .b = 170,
233 };
234
235 static constexpr argb_color burly_wood{
236 .r = 222,
237 .g = 184,
238 .b = 135,
239 };
240
241 static constexpr argb_color medium_blue{
242 .r = 0,
243 .g = 0,
244 .b = 205,
245 };
246
247 static constexpr argb_color cadet_blue{
248 .r = 95,
249 .g = 158,
250 .b = 160,
251 };
252
253 static constexpr argb_color medium_orchid{
254 .r = 186,
255 .g = 85,
256 .b = 211,
257 };
258
259 static constexpr argb_color chartreuse{
260 .r = 127,
261 .g = 255,
262 .b = 0,
263 };
264
265 static constexpr argb_color medium_purple{
266 .r = 147,
267 .g = 112,
268 .b = 219,
269 };
270
271 static constexpr argb_color chocolate{
272 .r = 210,
273 .g = 105,
274 .b = 30,
275 };
276
277 static constexpr argb_color medium_sea_green{
278 .r = 60,
279 .g = 179,
280 .b = 113,
281 };
282
283 static constexpr argb_color coral{
284 .r = 255,
285 .g = 127,
286 .b = 80,
287 };
288
289 static constexpr argb_color medium_slate_blue{
290 .r = 123,
291 .g = 104,
292 .b = 238,
293 };
294
295 static constexpr argb_color cornflower_blue{
296 .r = 100,
297 .g = 149,
298 .b = 237,
299 };
300
301 static constexpr argb_color medium_spring_green{
302 .r = 0,
303 .g = 250,
304 .b = 154,
305 };
306
307 static constexpr argb_color cornsilk{
308 .r = 255,
309 .g = 248,
310 .b = 220,
311 };
312
313 static constexpr argb_color medium_turquoise{
314 .r = 72,
315 .g = 209,
316 .b = 204,
317 };
318
319 static constexpr argb_color crimson{
320 .r = 220,
321 .g = 20,
322 .b = 60,
323 };
324
325 static constexpr argb_color medium_violet_red{
326 .r = 199,
327 .g = 21,
328 .b = 112,
329 };
330
331 static constexpr argb_color cyan{
332 .r = 0,
333 .g = 255,
334 .b = 255,
335 };
336
337 static constexpr argb_color midnight_blue{
338 .r = 25,
339 .g = 25,
340 .b = 112,
341 };
342
343 static constexpr argb_color dark_blue{
344 .r = 0,
345 .g = 0,
346 .b = 139,
347 };
348
349 static constexpr argb_color mint_cream{
350 .r = 245,
351 .g = 255,
352 .b = 250,
353 };
354
355 static constexpr argb_color dark_cyan{
356 .r = 0,
357 .g = 139,
358 .b = 139,
359 };
360
361 static constexpr argb_color misty_rose{
362 .r = 255,
363 .g = 228,
364 .b = 225,
365 };
366
367 static constexpr argb_color dark_goldenrod{
368 .r = 184,
369 .g = 134,
370 .b = 11,
371 };
372
373 static constexpr argb_color moccasin{
374 .r = 255,
375 .g = 228,
376 .b = 181,
377 };
378
379 static constexpr argb_color dark_gray{
380 .r = 169,
381 .g = 169,
382 .b = 169,
383 };
384
385 static constexpr argb_color navajo_white{
386 .r = 255,
387 .g = 222,
388 .b = 173,
389 };
390
391 static constexpr argb_color dark_green{
392 .r = 0,
393 .g = 100,
394 .b = 0,
395 };
396
397 static constexpr argb_color navy{
398 .r = 0,
399 .g = 0,
400 .b = 128,
401 };
402
403 static constexpr argb_color dark_khaki{
404 .r = 189,
405 .g = 183,
406 .b = 107,
407 };
408
409 static constexpr argb_color old_lace{
410 .r = 253,
411 .g = 245,
412 .b = 230,
413 };
414
415 static constexpr argb_color dark_magena{
416 .r = 139,
417 .g = 0,
418 .b = 139,
419 };
420
421 static constexpr argb_color olive{
422 .r = 128,
423 .g = 128,
424 .b = 0,
425 };
426
427 static constexpr argb_color dark_olive_green{
428 .r = 85,
429 .g = 107,
430 .b = 47,
431 };
432
433 static constexpr argb_color olive_drab{
434 .r = 107,
435 .g = 142,
436 .b = 45,
437 };
438
439 static constexpr argb_color dark_orange{
440 .r = 255,
441 .g = 140,
442 .b = 0,
443 };
444
445 static constexpr argb_color orange{
446 .r = 255,
447 .g = 165,
448 .b = 0,
449 };
450
451 static constexpr argb_color dark_orchid{
452 .r = 153,
453 .g = 50,
454 .b = 204,
455 };
456
457 static constexpr argb_color orange_red{
458 .r = 255,
459 .g = 69,
460 .b = 0,
461 };
462
463 static constexpr argb_color dark_red{
464 .r = 139,
465 .g = 0,
466 .b = 0,
467 };
468
469 static constexpr argb_color orchid{
470 .r = 218,
471 .g = 112,
472 .b = 214,
473 };
474
475 static constexpr argb_color dark_salmon{
476 .r = 233,
477 .g = 150,
478 .b = 122,
479 };
480
481 static constexpr argb_color pale_goldenrod{
482 .r = 238,
483 .g = 232,
484 .b = 170,
485 };
486
487 static constexpr argb_color dark_sea_green{
488 .r = 143,
489 .g = 188,
490 .b = 143,
491 };
492
493 static constexpr argb_color pale_green{
494 .r = 152,
495 .g = 251,
496 .b = 152,
497 };
498
499 static constexpr argb_color dark_slate_blue{
500 .r = 72,
501 .g = 61,
502 .b = 139,
503 };
504
505 static constexpr argb_color pale_turquoise{
506 .r = 175,
507 .g = 238,
508 .b = 238,
509 };
510
511 static constexpr argb_color dark_slate_gray{
512 .r = 40,
513 .g = 79,
514 .b = 79,
515 };
516
517 static constexpr argb_color pale_violet_red{
518 .r = 219,
519 .g = 112,
520 .b = 147,
521 };
522
523 static constexpr argb_color dark_turquoise{
524 .r = 0,
525 .g = 206,
526 .b = 209,
527 };
528
529 static constexpr argb_color papaya_whip{
530 .r = 255,
531 .g = 239,
532 .b = 213,
533 };
534
535 static constexpr argb_color dark_violet{
536 .r = 148,
537 .g = 0,
538 .b = 211,
539 };
540
541 static constexpr argb_color peach_puff{
542 .r = 255,
543 .g = 218,
544 .b = 155,
545 };
546
547 static constexpr argb_color deep_pink{
548 .r = 255,
549 .g = 20,
550 .b = 147,
551 };
552
553 static constexpr argb_color peru{
554 .r = 205,
555 .g = 133,
556 .b = 63,
557 };
558
559 static constexpr argb_color deep_sky_blue{
560 .r = 0,
561 .g = 191,
562 .b = 255,
563 };
564
565 static constexpr argb_color pink{
566 .r = 255,
567 .g = 192,
568 .b = 203,
569 };
570
571 static constexpr argb_color dim_gray{
572 .r = 105,
573 .g = 105,
574 .b = 105,
575 };
576
577 static constexpr argb_color plum{
578 .r = 221,
579 .g = 160,
580 .b = 221,
581 };
582
583 static constexpr argb_color dodger_blue{
584 .r = 30,
585 .g = 144,
586 .b = 255,
587 };
588
589 static constexpr argb_color powder_blue{
590 .r = 176,
591 .g = 224,
592 .b = 230,
593 };
594
595 static constexpr argb_color firebrick{
596 .r = 178,
597 .g = 34,
598 .b = 34,
599 };
600
601 static constexpr argb_color purple{
602 .r = 128,
603 .g = 0,
604 .b = 128,
605 };
606
607 static constexpr argb_color floral_white{
608 .r = 255,
609 .g = 250,
610 .b = 240,
611 };
612
613 static constexpr argb_color red{
614 .r = 255,
615 .g = 0,
616 .b = 0,
617 };
618
619 static constexpr argb_color forest_green{
620 .r = 34,
621 .g = 139,
622 .b = 34,
623 };
624
625 static constexpr argb_color rosy_brown{
626 .r = 188,
627 .g = 143,
628 .b = 143,
629 };
630
631 static constexpr argb_color fuschia{
632 .r = 255,
633 .g = 0,
634 .b = 255,
635 };
636
637 static constexpr argb_color royal_blue{
638 .r = 65,
639 .g = 105,
640 .b = 225,
641 };
642
643 static constexpr argb_color gainsboro{
644 .r = 220,
645 .g = 220,
646 .b = 220,
647 };
648
649 static constexpr argb_color saddle_brown{
650 .r = 139,
651 .g = 69,
652 .b = 19,
653 };
654
655 static constexpr argb_color ghost_white{
656 .r = 248,
657 .g = 248,
658 .b = 255,
659 };
660
661 static constexpr argb_color salmon{
662 .r = 250,
663 .g = 128,
664 .b = 114,
665 };
666
667 static constexpr argb_color gold{
668 .r = 255,
669 .g = 215,
670 .b = 0,
671 };
672
673 static constexpr argb_color sandy_brown{
674 .r = 244,
675 .g = 164,
676 .b = 96,
677 };
678
679 static constexpr argb_color goldenrod{
680 .r = 218,
681 .g = 165,
682 .b = 32,
683 };
684
685 static constexpr argb_color sea_green{
686 .r = 46,
687 .g = 139,
688 .b = 87,
689 };
690
691 static constexpr argb_color gray{
692 .r = 128,
693 .g = 128,
694 .b = 128,
695 };
696
697 static constexpr argb_color seashell{
698 .r = 255,
699 .g = 245,
700 .b = 238,
701 };
702
703 static constexpr argb_color green{
704 .r = 0,
705 .g = 128,
706 .b = 0,
707 };
708
709 static constexpr argb_color sienna{
710 .r = 160,
711 .g = 82,
712 .b = 45,
713 };
714
715 static constexpr argb_color green_yellow{
716 .r = 173,
717 .g = 255,
718 .b = 47,
719 };
720
721 static constexpr argb_color silver{
722 .r = 192,
723 .g = 192,
724 .b = 192,
725 };
726
727 static constexpr argb_color honeydew{
728 .r = 240,
729 .g = 255,
730 .b = 240,
731 };
732
733 static constexpr argb_color sky_blue{
734 .r = 135,
735 .g = 206,
736 .b = 235,
737 };
738
739 static constexpr argb_color hot_pink{
740 .r = 255,
741 .g = 105,
742 .b = 180,
743 };
744
745 static constexpr argb_color slate_blue{
746 .r = 106,
747 .g = 90,
748 .b = 205,
749 };
750
751 static constexpr argb_color indian_red{
752 .r = 205,
753 .g = 92,
754 .b = 92,
755 };
756
757 static constexpr argb_color slate_gray{
758 .r = 112,
759 .g = 128,
760 .b = 144,
761 };
762
763 static constexpr argb_color indigo{
764 .r = 75,
765 .g = 0,
766 .b = 130,
767 };
768
769 static constexpr argb_color snow{
770 .r = 255,
771 .g = 250,
772 .b = 250,
773 };
774
775 static constexpr argb_color ivory{
776 .r = 255,
777 .g = 240,
778 .b = 240,
779 };
780
781 static constexpr argb_color spring_green{
782 .r = 0,
783 .g = 255,
784 .b = 127,
785 };
786
787 static constexpr argb_color khaki{
788 .r = 240,
789 .g = 230,
790 .b = 140,
791 };
792
793 static constexpr argb_color steel_blue{
794 .r = 70,
795 .g = 130,
796 .b = 180,
797 };
798
799 static constexpr argb_color lavender{
800 .r = 230,
801 .g = 230,
802 .b = 250,
803 };
804
805 static constexpr argb_color tan{
806 .r = 210,
807 .g = 180,
808 .b = 140,
809 };
810
811 static constexpr argb_color lavender_blush{
812 .r = 255,
813 .g = 240,
814 .b = 245,
815 };
816
817 static constexpr argb_color teal{
818 .r = 0,
819 .g = 128,
820 .b = 128,
821 };
822
823 static constexpr argb_color lawn_green{
824 .r = 124,
825 .g = 252,
826 .b = 0,
827 };
828
829 static constexpr argb_color thistle{
830 .r = 216,
831 .g = 191,
832 .b = 216,
833 };
834
835 static constexpr argb_color lemon_chiffon{
836 .r = 255,
837 .g = 250,
838 .b = 205,
839 };
840
841 static constexpr argb_color tomato{
842 .r = 253,
843 .g = 99,
844 .b = 71,
845 };
846
847 static constexpr argb_color light_blue{
848 .r = 173,
849 .g = 216,
850 .b = 230,
851 };
852
853 static constexpr argb_color turquoise{
854 .r = 64,
855 .g = 224,
856 .b = 208,
857 };
858
859 static constexpr argb_color light_coral{
860 .r = 240,
861 .g = 128,
862 .b = 128,
863 };
864
865 static constexpr argb_color violet{
866 .r = 238,
867 .g = 130,
868 .b = 238,
869 };
870
871 static constexpr argb_color light_cyan{
872 .r = 224,
873 .g = 255,
874 .b = 255,
875 };
876
877 static constexpr argb_color wheat{
878 .r = 245,
879 .g = 222,
880 .b = 179,
881 };
882
883 static constexpr argb_color light_goldenrod_yellow{
884 .r = 250,
885 .g = 250,
886 .b = 210,
887 };
888
889 static constexpr argb_color white{
890 .r = 255,
891 .g = 255,
892 .b = 255,
893 };
894
895 static constexpr argb_color light_green{
896 .r = 144,
897 .g = 238,
898 .b = 144,
899 };
900
901 static constexpr argb_color white_smoke{
902 .r = 245,
903 .g = 245,
904 .b = 245,
905 };
906
907 static constexpr argb_color light_gray{
908 .r = 211,
909 .g = 211,
910 .b = 211,
911 };
912
913 static constexpr argb_color yellow{
914 .r = 255,
915 .g = 255,
916 .b = 0,
917 };
918
919 static constexpr argb_color light_pink{
920 .r = 255,
921 .g = 182,
922 .b = 193,
923 };
924
925 static constexpr argb_color yellow_green{
926 .r = 154,
927 .g = 205,
928 .b = 50,
929 };
930 };
931} // namespace essence
Describes a ARGB color.
Definition argb_color.hpp:33
constexpr auto normalize(T min, T max) const noexcept
Normalizes the data to a new range.
Definition argb_color.hpp:56
Common predefined colors.
Definition argb_color.hpp:90