SGL
gcolor.h
1 /*
2  * File: gcolor.h
3  * --------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/03
7  * - removed dependency on custom collections
8  * @version 2019/05/05
9  * - added getLuminance
10  * @version 2018/09/16
11  * - added splitRGB/ARGB, hasAlpha; better ARGB support
12  * @version 2018/09/07
13  * - added doc comments for new documentation generation
14  * @version 2018/08/23
15  * - renamed to gcolor.h to replace Java version
16  * @version 2018/06/30
17  * - initial version
18  */
19 
20 
21 #ifndef _gcolor_h
22 #define _gcolor_h
23 
24 #include <map>
25 #include <string>
26 #include <QColor>
27 
70 class GColor {
71 public:
75  enum {
76  BLACK = 0x000000,
77  BLUE = 0x0000FF,
78  BROWN = 0x926239,
79  CYAN = 0x00FFFF,
80  DARKGRAY = 0x595959,
81  GRAY = 0x999999,
82  GREEN = 0x00FF00,
83  LIGHTGRAY = 0xBFBFBF,
84  MAGENTA = 0xFF00FF,
85  ORANGE = 0xFFC800,
86  PINK = 0xFFAFAF,
87  PURPLE = 0xFF00FF,
88  RED = 0xFF0000,
89  WHITE = 0xFFFFFF,
90  YELLOW = 0xFFFF00
91  } Color;
92 
100  static string convertARGBToColor(int a, int r, int g, int b);
101 
106  static string convertARGBToColor(int argb);
107 
115  static int convertARGBToARGB(int a, int r, int g, int b);
116 
121  static int convertColorToARGB(const string& colorName);
122 
128  static int convertColorToRGB(const string& colorName);
129 
134  static string convertQColorToColor(const QColor& color);
135 
140  static int convertQColorToRGB(const QColor& color);
141 
147  static string convertRGBToColor(int rgb);
148 
156  static string convertRGBToColor(int r, int g, int b);
157 
164  static int convertRGBToRGB(int r, int g, int b);
165 
171  static int fixAlpha(int argb);
172 
179  static double getLuminance(int rgb);
180 
187  static double getLuminance(const string& color);
188 
194  static bool hasAlpha(const string& color);
195 
202  static void splitARGB(int argb, int& a, int& r, int& g, int& b);
203 
210  static void splitRGB(int rgb, int& r, int& g, int& b);
211 
216  static QColor toQColor(const string& color);
217 
222  static QColor toQColorARGB(int argb);
223 
224 private:
225  GColor(); // forbid construction
226 
230  static string canonicalColorName(const string& str);
231 
236  static const std::map<string, int>& colorTable();
237 
242  static const std::map<string, string>& colorNameTable();
243 
244  // internal color tables
245  static std::map<string, int> _colorTable;
246  static std::map<string, string> _colorNameTable;
247 };
248 
249 #endif // _gcolor_h
static QColor toQColorARGB(int argb)
Converts an ARGB integer into a Qt color object.
Definition: gcolor.cpp:240
static bool hasAlpha(string color)
Returns true if the given color string is of the 8-hex-character form that contains an alpha channel ...
Definition: gcolor.cpp:210
Definition: gcolor.h:81
static string convertARGBToColor(int a, int r, int g, int b)
Converts four integer RGB values from 0-255 into a color name in the form "#aarrggbb".
Definition: gcolor.cpp:103
static QColor toQColor(string color)
Converts a color string into a Qt color object.
Definition: gcolor.cpp:228
enum GColor::@0 Color
Constants representing common system color names.
static int convertColorToARGB(string colorName)
Converts a color name into an ARGB integer that encodes the alpha (opacity), red, green...
Definition: gcolor.cpp:122
static string convertRGBToColor(int rgb)
Converts an RGB integer value into a color name in the form "#rrggbb".
Definition: gcolor.cpp:154
static int convertQColorToRGB(const QColor &color)
Converts a Qt color object into an RGB integer.
Definition: gcolor.cpp:150
Definition: gcolor.h:80
This class provides static methods for dealing with colors.
Definition: gcolor.h:70
static int convertRGBToRGB(int r, int g, int b)
Converts three integer RGB values from 0-255 into a single RGB integer.
Definition: gcolor.cpp:187
static int fixAlpha(int argb)
Sets the &#39;alpha&#39; (high order bits) of the given integer to ff.
Definition: gcolor.cpp:191
Definition: gcolor.h:79
static string convertQColorToColor(const QColor &color)
Converts a Qt RGB color object into a color string.
Definition: gcolor.cpp:146
Definition: gcolor.h:77
Definition: gcolor.h:89
Definition: gcolor.h:86
static void splitARGB(int argb, int &a, int &r, int &g, int &b)
Splits the given ARGB integer into four integer RGB values from 0-255.
Definition: gcolor.cpp:215
Definition: gcolor.h:78
static int convertARGBToARGB(int a, int r, int g, int b)
Converts four integer RGB values from 0-255 into an ARGB integer of the form 0xaarrggbb.
Definition: gcolor.cpp:99
Definition: gcolor.h:85
Definition: gcolor.h:76
Definition: gcolor.h:84
static double getLuminance(int rgb)
Returns the photometric luminance of the given RGB integer, which is a measure of how bright the colo...
Definition: gcolor.cpp:199
static int convertColorToRGB(string colorName)
Converts a color name into an integer that encodes the red, green, and blue components of the color...
Definition: gcolor.cpp:126
Definition: gcolor.h:87
Definition: gcolor.h:82
static void splitRGB(int rgb, int &r, int &g, int &b)
Splits the given RGB integer into three integer RGB values from 0-255.
Definition: gcolor.cpp:222
Definition: gcolor.h:90
Definition: gcolor.h:88
Definition: gcolor.h:83