Merge pull request #26220 from 78andyp/blurayfixes
[xbmc.git] / xbmc / utils / ColorUtils.h
blobcfa8452282d21d52f02fac2ff0bf29d136234ef7
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "utils/Map.h"
13 #include <cstdint>
14 #include <string>
15 #include <utility>
16 #include <vector>
18 namespace KODI::UTILS::COLOR
21 typedef uint32_t Color;
23 // Custom colors
25 constexpr Color NONE = 0x00000000;
26 constexpr Color LIMITED_BLACK = 0xFF101010;
28 // W3C HTML color list
30 constexpr Color WHITE = 0xFFFFFFFF;
31 constexpr Color SILVER = 0xFFC0C0C0;
32 constexpr Color GRAY = 0xFF808080;
33 constexpr Color BLACK = 0xFF000000;
34 constexpr Color RED = 0xFFFF0000;
35 constexpr Color MAROON = 0xFF800000;
36 constexpr Color YELLOW = 0xFFFFFF00;
37 constexpr Color OLIVE = 0xFF808000;
38 constexpr Color LIME = 0xFF00FF00;
39 constexpr Color GREEN = 0xFF008000;
40 constexpr Color AQUA = 0xFF00FFFF;
41 constexpr Color TEAL = 0xFF008080;
42 constexpr Color BLUE = 0xFF0000FF;
43 constexpr Color NAVY = 0xFF000080;
44 constexpr Color FUCHSIA = 0xFFFF00FF;
45 constexpr Color PURPLE = 0xFF800080;
46 constexpr Color MAGENTA = 0xFFFF00FF;
47 constexpr Color CYAN = 0xFF00FFFF;
49 struct ColorInfo
51 Color colorARGB;
52 double hue;
53 double saturation;
54 double lightness;
57 struct ColorFloats
59 float red;
60 float green;
61 float blue;
62 float alpha;
65 //! \brief W3C HTML 16 basic color list
66 constexpr auto HTML_BASIC_COLORS = make_map<std::string_view, Color>({{"white", WHITE},
67 {"silver", SILVER},
68 {"gray", GRAY},
69 {"black", BLACK},
70 {"red", RED},
71 {"maroon", MAROON},
72 {"yellow", YELLOW},
73 {"olive", OLIVE},
74 {"lime", LIME},
75 {"green", GREEN},
76 {"aqua", AQUA},
77 {"teal", TEAL},
78 {"blue", BLUE},
79 {"navy", NAVY},
80 {"fuchsia", FUCHSIA},
81 {"purple", PURPLE}});
83 /*!
84 * \brief Change the opacity of a given ARGB color
85 * \param color The original color
86 * \param opacity The opacity value as a float
87 * \return the original color with the changed opacity/alpha value
89 Color ChangeOpacity(const Color argb, const float opacity);
91 /*!
92 * \brief Convert given ARGB color to RGBA color value
93 * \param color The original color
94 * \return the original color converted to RGBA value
96 Color ConvertToRGBA(const Color argb);
98 /*!
99 * \brief Convert given RGBA color to ARGB color value
100 * \param color The original color
101 * \return the original color converted to ARGB value
103 Color ConvertToARGB(const Color rgba);
106 * \brief Convert given ARGB color to BGR color value
107 * \param color The original color
108 * \return the original color converted to BGR value
110 Color ConvertToBGR(const Color argb);
113 * \brief Convert given hex value to Color value
114 * \param hexColor The original hex color
115 * \return the original hex color converted to Color value
117 Color ConvertHexToColor(const std::string& hexColor);
120 * \brief Convert given RGB int values to RGB color value
121 * \param r The red value
122 * \param g The green value
123 * \param b The blue value
124 * \return the color as RGB value
126 Color ConvertIntToRGB(int r, int g, int b);
129 * \brief Create a ColorInfo from an ARGB Color to
130 * get additional information of the color
131 * and allow to be sorted with a color comparer
132 * \param argb The original ARGB color
133 * \return the ColorInfo
135 ColorInfo MakeColorInfo(const Color& argb);
138 * \brief Create a ColorInfo from an HEX color value to
139 * get additional information of the color
140 * and allow to be sorted with a color comparer
141 * \param hexColor The original ARGB color
142 * \return the ColorInfo
144 ColorInfo MakeColorInfo(const std::string& hexColor);
147 * \brief Comparer for pair string/ColorInfo to sort colors in a hue scale
149 bool comparePairColorInfo(const std::pair<std::string, ColorInfo>& a,
150 const std::pair<std::string, ColorInfo>& b);
153 * \brief Convert given ARGB color to ColorFloats
154 * \param color The original color
155 * \return the original color converted to ColorFloats
157 ColorFloats ConvertToFloats(const Color argb);
160 * \brief Convert given ARGB color to hex RGB color value
161 * \param color The original color
162 * \return The original color converted to hex RGB
164 std::string ConvertToHexRGB(const Color argb);
166 } // namespace KODI::UTILS::COLOR