kodi
ColorUtils.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "utils/Map.h"
12 
13 #include <cstdint>
14 #include <string>
15 #include <utility>
16 #include <vector>
17 
18 namespace UTILS
19 {
20 namespace COLOR
21 {
22 
23 typedef uint32_t Color;
24 
25 // Custom colors
26 
27 constexpr Color NONE = 0x00000000;
28 constexpr Color LIMITED_BLACK = 0xFF101010;
29 
30 // W3C HTML color list
31 
32 constexpr Color WHITE = 0xFFFFFFFF;
33 constexpr Color SILVER = 0xFFC0C0C0;
34 constexpr Color GRAY = 0xFF808080;
35 constexpr Color BLACK = 0xFF000000;
36 constexpr Color RED = 0xFFFF0000;
37 constexpr Color MAROON = 0xFF800000;
38 constexpr Color YELLOW = 0xFFFFFF00;
39 constexpr Color OLIVE = 0xFF808000;
40 constexpr Color LIME = 0xFF00FF00;
41 constexpr Color GREEN = 0xFF008000;
42 constexpr Color AQUA = 0xFF00FFFF;
43 constexpr Color TEAL = 0xFF008080;
44 constexpr Color BLUE = 0xFF0000FF;
45 constexpr Color NAVY = 0xFF000080;
46 constexpr Color FUCHSIA = 0xFFFF00FF;
47 constexpr Color PURPLE = 0xFF800080;
48 constexpr Color MAGENTA = 0xFFFF00FF;
49 constexpr Color CYAN = 0xFF00FFFF;
50 
51 struct ColorInfo
52 {
53  Color colorARGB;
54  double hue;
55  double saturation;
56  double lightness;
57 };
58 
60 {
61  float red;
62  float green;
63  float blue;
64  float alpha;
65 };
66 
68 constexpr auto HTML_BASIC_COLORS = make_map<std::string_view, Color>({{"white", WHITE},
69  {"silver", SILVER},
70  {"gray", GRAY},
71  {"black", BLACK},
72  {"red", RED},
73  {"maroon", MAROON},
74  {"yellow", YELLOW},
75  {"olive", OLIVE},
76  {"lime", LIME},
77  {"green", GREEN},
78  {"aqua", AQUA},
79  {"teal", TEAL},
80  {"blue", BLUE},
81  {"navy", NAVY},
82  {"fuchsia", FUCHSIA},
83  {"purple", PURPLE}});
84 
91 Color ChangeOpacity(const Color argb, const float opacity);
92 
98 Color ConvertToRGBA(const Color argb);
99 
105 Color ConvertToARGB(const Color rgba);
106 
112 Color ConvertToBGR(const Color argb);
113 
119 Color ConvertHexToColor(const std::string& hexColor);
120 
128 Color ConvertIntToRGB(int r, int g, int b);
129 
137 ColorInfo MakeColorInfo(const Color& argb);
138 
146 ColorInfo MakeColorInfo(const std::string& hexColor);
147 
151 bool comparePairColorInfo(const std::pair<std::string, ColorInfo>& a,
152  const std::pair<std::string, ColorInfo>& b);
153 
159 ColorFloats ConvertToFloats(const Color argb);
160 
166 std::string ConvertToHexRGB(const Color argb);
167 
168 } // namespace COLOR
169 } // namespace UTILS
Definition: Texture.h:21
Definition: ColorUtils.h:51
Definition: ColorUtils.h:18
Definition: ColorUtils.h:59