00001 #ifndef IONFLUX_TOOLS_COLOR
00002 #define IONFLUX_TOOLS_COLOR
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <string>
00030 #include <sstream>
00031 #include <iomanip>
00032 #include <map>
00033 #include <math.h>
00034
00035 namespace Ionflux
00036 {
00037
00038 namespace Tools
00039 {
00040
00048
00049 struct Color
00050 {
00052 const char* name;
00054 double red;
00056 double green;
00058 double blue;
00060 double alpha;
00061 };
00062
00064 struct Color8bpp
00065 {
00067 const char* name;
00069 unsigned char red;
00071 unsigned char green;
00073 unsigned char blue;
00075 unsigned char alpha;
00076 };
00077
00079 typedef std::map<const std::string, const Color*> ColorMap;
00080
00084 const Color COLOR_ALICEBLUE = { "aliceblue",
00085 0.941176, 0.972549, 1.000000, 1.000000 };
00086 const Color COLOR_ANTIQUEWHITE = { "antiquewhite",
00087 0.980392, 0.921569, 0.843137, 1.000000 };
00088 const Color COLOR_AQUA = { "aqua",
00089 0.000000, 1.000000, 1.000000, 1.000000 };
00090 const Color COLOR_AQUAMARINE = { "aquamarine",
00091 0.498039, 1.000000, 0.831373, 1.000000 };
00092 const Color COLOR_AZURE = { "azure",
00093 0.941176, 1.000000, 1.000000, 1.000000 };
00094 const Color COLOR_BEIGE = { "beige",
00095 0.960784, 0.960784, 0.862745, 1.000000 };
00096 const Color COLOR_BISQUE = { "bisque",
00097 1.000000, 0.894118, 0.768627, 1.000000 };
00098 const Color COLOR_BLACK = { "black",
00099 0.000000, 0.000000, 0.000000, 1.000000 };
00100 const Color COLOR_BLANCHEDALMOND = { "blanchedalmond",
00101 1.000000, 0.921569, 0.803922, 1.000000 };
00102 const Color COLOR_BLUE = { "blue",
00103 0.000000, 0.000000, 1.000000, 1.000000 };
00104 const Color COLOR_BLUEVIOLET = { "blueviolet",
00105 0.541176, 0.168627, 0.886275, 1.000000 };
00106 const Color COLOR_BROWN = { "brown",
00107 0.647059, 0.164706, 0.164706, 1.000000 };
00108 const Color COLOR_BURLYWOOD = { "burlywood",
00109 0.870588, 0.721569, 0.529412, 1.000000 };
00110 const Color COLOR_CADETBLUE = { "cadetblue",
00111 0.372549, 0.619608, 0.627451, 1.000000 };
00112 const Color COLOR_CHARTREUSE = { "chartreuse",
00113 0.498039, 1.000000, 0.000000, 1.000000 };
00114 const Color COLOR_CHOCOLATE = { "chocolate",
00115 0.823529, 0.411765, 0.117647, 1.000000 };
00116 const Color COLOR_CORAL = { "coral",
00117 1.000000, 0.498039, 0.313725, 1.000000 };
00118 const Color COLOR_CORNFLOWERBLUE = { "cornflowerblue",
00119 0.392157, 0.584314, 0.929412, 1.000000 };
00120 const Color COLOR_CORNSILK = { "cornsilk",
00121 1.000000, 0.972549, 0.862745, 1.000000 };
00122 const Color COLOR_CRIMSON = { "crimson",
00123 0.862745, 0.078431, 0.235294, 1.000000 };
00124 const Color COLOR_CYAN = { "cyan",
00125 0.000000, 1.000000, 1.000000, 1.000000 };
00126 const Color COLOR_DARKBLUE = { "darkblue",
00127 0.000000, 0.000000, 0.545098, 1.000000 };
00128 const Color COLOR_DARKCYAN = { "darkcyan",
00129 0.000000, 0.545098, 0.545098, 1.000000 };
00130 const Color COLOR_DARKGOLDENROD = { "darkgoldenrod",
00131 0.721569, 0.525490, 0.043137, 1.000000 };
00132 const Color COLOR_DARKGRAY = { "darkgray",
00133 0.662745, 0.662745, 0.662745, 1.000000 };
00134 const Color COLOR_DARKGREEN = { "darkgreen",
00135 0.000000, 0.392157, 0.000000, 1.000000 };
00136 const Color COLOR_DARKGREY = { "darkgrey",
00137 0.662745, 0.662745, 0.662745, 1.000000 };
00138 const Color COLOR_DARKKHAKI = { "darkkhaki",
00139 0.741176, 0.717647, 0.419608, 1.000000 };
00140 const Color COLOR_DARKMAGENTA = { "darkmagenta",
00141 0.545098, 0.000000, 0.545098, 1.000000 };
00142 const Color COLOR_DARKOLIVEGREEN = { "darkolivegreen",
00143 0.333333, 0.419608, 0.184314, 1.000000 };
00144 const Color COLOR_DARKORANGE = { "darkorange",
00145 1.000000, 0.549020, 0.000000, 1.000000 };
00146 const Color COLOR_DARKORCHID = { "darkorchid",
00147 0.600000, 0.196078, 0.800000, 1.000000 };
00148 const Color COLOR_DARKRED = { "darkred",
00149 0.545098, 0.000000, 0.000000, 1.000000 };
00150 const Color COLOR_DARKSALMON = { "darksalmon",
00151 0.913725, 0.588235, 0.478431, 1.000000 };
00152 const Color COLOR_DARKSEAGREEN = { "darkseagreen",
00153 0.560784, 0.737255, 0.560784, 1.000000 };
00154 const Color COLOR_DARKSLATEBLUE = { "darkslateblue",
00155 0.282353, 0.239216, 0.545098, 1.000000 };
00156 const Color COLOR_DARKSLATEGRAY = { "darkslategray",
00157 0.184314, 0.309804, 0.309804, 1.000000 };
00158 const Color COLOR_DARKSLATEGREY = { "darkslategrey",
00159 0.184314, 0.309804, 0.309804, 1.000000 };
00160 const Color COLOR_DARKTURQUOISE = { "darkturquoise",
00161 0.000000, 0.807843, 0.819608, 1.000000 };
00162 const Color COLOR_DARKVIOLET = { "darkviolet",
00163 0.580392, 0.000000, 0.827451, 1.000000 };
00164 const Color COLOR_DEEPPINK = { "deeppink",
00165 1.000000, 0.078431, 0.576471, 1.000000 };
00166 const Color COLOR_DEEPSKYBLUE = { "deepskyblue",
00167 0.000000, 0.749020, 1.000000, 1.000000 };
00168 const Color COLOR_DIMGRAY = { "dimgray",
00169 0.411765, 0.411765, 0.411765, 1.000000 };
00170 const Color COLOR_DIMGREY = { "dimgrey",
00171 0.411765, 0.411765, 0.411765, 1.000000 };
00172 const Color COLOR_DODGERBLUE = { "dodgerblue",
00173 0.117647, 0.564706, 1.000000, 1.000000 };
00174 const Color COLOR_FIREBRICK = { "firebrick",
00175 0.698039, 0.133333, 0.133333, 1.000000 };
00176 const Color COLOR_FLORALWHITE = { "floralwhite",
00177 1.000000, 0.980392, 0.941176, 1.000000 };
00178 const Color COLOR_FORESTGREEN = { "forestgreen",
00179 0.133333, 0.545098, 0.133333, 1.000000 };
00180 const Color COLOR_FUCHSIA = { "fuchsia",
00181 1.000000, 0.000000, 1.000000, 1.000000 };
00182 const Color COLOR_GAINSBORO = { "gainsboro",
00183 0.862745, 0.862745, 0.862745, 1.000000 };
00184 const Color COLOR_GHOSTWHITE = { "ghostwhite",
00185 0.972549, 0.972549, 1.000000, 1.000000 };
00186 const Color COLOR_GOLD = { "gold",
00187 1.000000, 0.843137, 0.000000, 1.000000 };
00188 const Color COLOR_GOLDENROD = { "goldenrod",
00189 0.854902, 0.647059, 0.125490, 1.000000 };
00190 const Color COLOR_GRAY = { "gray",
00191 0.501961, 0.501961, 0.501961, 1.000000 };
00192 const Color COLOR_GREY = { "grey",
00193 0.501961, 0.501961, 0.501961, 1.000000 };
00194 const Color COLOR_GREEN = { "green",
00195 0.000000, 0.501961, 0.000000, 1.000000 };
00196 const Color COLOR_GREENYELLOW = { "greenyellow",
00197 0.678431, 1.000000, 0.184314, 1.000000 };
00198 const Color COLOR_HONEYDEW = { "honeydew",
00199 0.941176, 1.000000, 0.941176, 1.000000 };
00200 const Color COLOR_HOTPINK = { "hotpink",
00201 1.000000, 0.411765, 0.705882, 1.000000 };
00202 const Color COLOR_INDIANRED = { "indianred",
00203 0.803922, 0.360784, 0.360784, 1.000000 };
00204 const Color COLOR_INDIGO = { "indigo",
00205 0.294118, 0.000000, 0.509804, 1.000000 };
00206 const Color COLOR_IVORY = { "ivory",
00207 1.000000, 1.000000, 0.941176, 1.000000 };
00208 const Color COLOR_KHAKI = { "khaki",
00209 0.941176, 0.901961, 0.549020, 1.000000 };
00210 const Color COLOR_LAVENDER = { "lavender",
00211 0.901961, 0.901961, 0.980392, 1.000000 };
00212 const Color COLOR_LAVENDERBLUSH = { "lavenderblush",
00213 1.000000, 0.941176, 0.960784, 1.000000 };
00214 const Color COLOR_LAWNGREEN = { "lawngreen",
00215 0.486275, 0.988235, 0.000000, 1.000000 };
00216 const Color COLOR_LEMONCHIFFON = { "lemonchiffon",
00217 1.000000, 0.980392, 0.803922, 1.000000 };
00218 const Color COLOR_LIGHTBLUE = { "lightblue",
00219 0.678431, 0.847059, 0.901961, 1.000000 };
00220 const Color COLOR_LIGHTCORAL = { "lightcoral",
00221 0.941176, 0.501961, 0.501961, 1.000000 };
00222 const Color COLOR_LIGHTCYAN = { "lightcyan",
00223 0.878431, 1.000000, 1.000000, 1.000000 };
00224 const Color COLOR_LIGHTGOLDENRODYELLOW = { "lightgoldenrodyellow",
00225 0.980392, 0.980392, 0.823529, 1.000000 };
00226 const Color COLOR_LIGHTGRAY = { "lightgray",
00227 0.827451, 0.827451, 0.827451, 1.000000 };
00228 const Color COLOR_LIGHTGREEN = { "lightgreen",
00229 0.564706, 0.933333, 0.564706, 1.000000 };
00230 const Color COLOR_LIGHTGREY = { "lightgrey",
00231 0.827451, 0.827451, 0.827451, 1.000000 };
00232 const Color COLOR_LIGHTPINK = { "lightpink",
00233 1.000000, 0.713725, 0.756863, 1.000000 };
00234 const Color COLOR_LIGHTSALMON = { "lightsalmon",
00235 1.000000, 0.627451, 0.478431, 1.000000 };
00236 const Color COLOR_LIGHTSEAGREEN = { "lightseagreen",
00237 0.125490, 0.698039, 0.666667, 1.000000 };
00238 const Color COLOR_LIGHTSKYBLUE = { "lightskyblue",
00239 0.529412, 0.807843, 0.980392, 1.000000 };
00240 const Color COLOR_LIGHTSLATEGRAY = { "lightslategray",
00241 0.466667, 0.533333, 0.600000, 1.000000 };
00242 const Color COLOR_LIGHTSLATEGREY = { "lightslategrey",
00243 0.466667, 0.533333, 0.600000, 1.000000 };
00244 const Color COLOR_LIGHTSTEELBLUE = { "lightsteelblue",
00245 0.690196, 0.768627, 0.870588, 1.000000 };
00246 const Color COLOR_LIGHTYELLOW = { "lightyellow",
00247 1.000000, 1.000000, 0.878431, 1.000000 };
00248 const Color COLOR_LIME = { "lime",
00249 0.000000, 1.000000, 0.000000, 1.000000 };
00250 const Color COLOR_LIMEGREEN = { "limegreen",
00251 0.196078, 0.803922, 0.196078, 1.000000 };
00252 const Color COLOR_LINEN = { "linen",
00253 0.980392, 0.941176, 0.901961, 1.000000 };
00254 const Color COLOR_MAGENTA = { "magenta",
00255 1.000000, 0.000000, 1.000000, 1.000000 };
00256 const Color COLOR_MAROON = { "maroon",
00257 0.501961, 0.000000, 0.000000, 1.000000 };
00258 const Color COLOR_MEDIUMAQUAMARINE = { "mediumaquamarine",
00259 0.400000, 0.803922, 0.666667, 1.000000 };
00260 const Color COLOR_MEDIUMBLUE = { "mediumblue",
00261 0.000000, 0.000000, 0.803922, 1.000000 };
00262 const Color COLOR_MEDIUMORCHID = { "mediumorchid",
00263 0.729412, 0.333333, 0.827451, 1.000000 };
00264 const Color COLOR_MEDIUMPURPLE = { "mediumpurple",
00265 0.576471, 0.439216, 0.858824, 1.000000 };
00266 const Color COLOR_MEDIUMSEAGREEN = { "mediumseagreen",
00267 0.235294, 0.701961, 0.443137, 1.000000 };
00268 const Color COLOR_MEDIUMSLATEBLUE = { "mediumslateblue",
00269 0.482353, 0.407843, 0.933333, 1.000000 };
00270 const Color COLOR_MEDIUMSPRINGGREEN = { "mediumspringgreen",
00271 0.000000, 0.980392, 0.603922, 1.000000 };
00272 const Color COLOR_MEDIUMTURQUOISE = { "mediumturquoise",
00273 0.282353, 0.819608, 0.800000, 1.000000 };
00274 const Color COLOR_MEDIUMVIOLETRED = { "mediumvioletred",
00275 0.780392, 0.082353, 0.521569, 1.000000 };
00276 const Color COLOR_MIDNIGHTBLUE = { "midnightblue",
00277 0.098039, 0.098039, 0.439216, 1.000000 };
00278 const Color COLOR_MINTCREAM = { "mintcream",
00279 0.960784, 1.000000, 0.980392, 1.000000 };
00280 const Color COLOR_MISTYROSE = { "mistyrose",
00281 1.000000, 0.894118, 0.882353, 1.000000 };
00282 const Color COLOR_MOCCASIN = { "moccasin",
00283 1.000000, 0.894118, 0.709804, 1.000000 };
00284 const Color COLOR_NAVAJOWHITE = { "navajowhite",
00285 1.000000, 0.870588, 0.678431, 1.000000 };
00286 const Color COLOR_NAVY = { "navy",
00287 0.000000, 0.000000, 0.501961, 1.000000 };
00288 const Color COLOR_OLDLACE = { "oldlace",
00289 0.992157, 0.960784, 0.901961, 1.000000 };
00290 const Color COLOR_OLIVE = { "olive",
00291 0.501961, 0.501961, 0.000000, 1.000000 };
00292 const Color COLOR_OLIVEDRAB = { "olivedrab",
00293 0.419608, 0.556863, 0.137255, 1.000000 };
00294 const Color COLOR_ORANGE = { "orange",
00295 1.000000, 0.647059, 0.000000, 1.000000 };
00296 const Color COLOR_ORANGERED = { "orangered",
00297 1.000000, 0.270588, 0.000000, 1.000000 };
00298 const Color COLOR_ORCHID = { "orchid",
00299 0.854902, 0.439216, 0.839216, 1.000000 };
00300 const Color COLOR_PALEGOLDENROD = { "palegoldenrod",
00301 0.933333, 0.909804, 0.666667, 1.000000 };
00302 const Color COLOR_PALEGREEN = { "palegreen",
00303 0.596078, 0.984314, 0.596078, 1.000000 };
00304 const Color COLOR_PALETURQUOISE = { "paleturquoise",
00305 0.686275, 0.933333, 0.933333, 1.000000 };
00306 const Color COLOR_PALEVIOLETRED = { "palevioletred",
00307 0.858824, 0.439216, 0.576471, 1.000000 };
00308 const Color COLOR_PAPAYAWHIP = { "papayawhip",
00309 1.000000, 0.937255, 0.835294, 1.000000 };
00310 const Color COLOR_PEACHPUFF = { "peachpuff",
00311 1.000000, 0.854902, 0.725490, 1.000000 };
00312 const Color COLOR_PERU = { "peru",
00313 0.803922, 0.521569, 0.247059, 1.000000 };
00314 const Color COLOR_PINK = { "pink",
00315 1.000000, 0.752941, 0.796078, 1.000000 };
00316 const Color COLOR_PLUM = { "plum",
00317 0.866667, 0.627451, 0.866667, 1.000000 };
00318 const Color COLOR_POWDERBLUE = { "powderblue",
00319 0.690196, 0.878431, 0.901961, 1.000000 };
00320 const Color COLOR_PURPLE = { "purple",
00321 0.501961, 0.000000, 0.501961, 1.000000 };
00322 const Color COLOR_RED = { "red",
00323 1.000000, 0.000000, 0.000000, 1.000000 };
00324 const Color COLOR_ROSYBROWN = { "rosybrown",
00325 0.737255, 0.560784, 0.560784, 1.000000 };
00326 const Color COLOR_ROYALBLUE = { "royalblue",
00327 0.254902, 0.411765, 0.882353, 1.000000 };
00328 const Color COLOR_SADDLEBROWN = { "saddlebrown",
00329 0.545098, 0.270588, 0.074510, 1.000000 };
00330 const Color COLOR_SALMON = { "salmon",
00331 0.980392, 0.501961, 0.447059, 1.000000 };
00332 const Color COLOR_SANDYBROWN = { "sandybrown",
00333 0.956863, 0.643137, 0.376471, 1.000000 };
00334 const Color COLOR_SEAGREEN = { "seagreen",
00335 0.180392, 0.545098, 0.341176, 1.000000 };
00336 const Color COLOR_SEASHELL = { "seashell",
00337 1.000000, 0.960784, 0.933333, 1.000000 };
00338 const Color COLOR_SIENNA = { "sienna",
00339 0.627451, 0.321569, 0.176471, 1.000000 };
00340 const Color COLOR_SILVER = { "silver",
00341 0.752941, 0.752941, 0.752941, 1.000000 };
00342 const Color COLOR_SKYBLUE = { "skyblue",
00343 0.529412, 0.807843, 0.921569, 1.000000 };
00344 const Color COLOR_SLATEBLUE = { "slateblue",
00345 0.415686, 0.352941, 0.803922, 1.000000 };
00346 const Color COLOR_SLATEGRAY = { "slategray",
00347 0.439216, 0.501961, 0.564706, 1.000000 };
00348 const Color COLOR_SLATEGREY = { "slategrey",
00349 0.439216, 0.501961, 0.564706, 1.000000 };
00350 const Color COLOR_SNOW = { "snow",
00351 1.000000, 0.980392, 0.980392, 1.000000 };
00352 const Color COLOR_SPRINGGREEN = { "springgreen",
00353 0.000000, 1.000000, 0.498039, 1.000000 };
00354 const Color COLOR_STEELBLUE = { "steelblue",
00355 0.274510, 0.509804, 0.705882, 1.000000 };
00356 const Color COLOR_TAN = { "tan",
00357 0.823529, 0.705882, 0.549020, 1.000000 };
00358 const Color COLOR_TEAL = { "teal",
00359 0.000000, 0.501961, 0.501961, 1.000000 };
00360 const Color COLOR_THISTLE = { "thistle",
00361 0.847059, 0.749020, 0.847059, 1.000000 };
00362 const Color COLOR_TOMATO = { "tomato",
00363 1.000000, 0.388235, 0.278431, 1.000000 };
00364 const Color COLOR_TURQUOISE = { "turquoise",
00365 0.250980, 0.878431, 0.815686, 1.000000 };
00366 const Color COLOR_VIOLET = { "violet",
00367 0.933333, 0.509804, 0.933333, 1.000000 };
00368 const Color COLOR_WHEAT = { "wheat",
00369 0.960784, 0.870588, 0.701961, 1.000000 };
00370 const Color COLOR_WHITE = { "white",
00371 1.000000, 1.000000, 1.000000, 1.000000 };
00372 const Color COLOR_WHITESMOKE = { "whitesmoke",
00373 0.960784, 0.960784, 0.960784, 1.000000 };
00374 const Color COLOR_YELLOW = { "yellow",
00375 1.000000, 1.000000, 0.000000, 1.000000 };
00376 const Color COLOR_YELLOWGREEN = { "yellowgreen",
00377 0.603922, 0.803922, 0.196078, 1.000000 };
00378
00380 const Color COLOR_NONE = { "<none>",
00381 0.000000, 0.000000, 0.000000, 0.000000 };
00382 const Color COLOR_GREY_10 = { "grey_10",
00383 0.900000, 0.900000, 0.900000, 1.000000 };
00384 const Color COLOR_GREY_20 = { "grey_20",
00385 0.800000, 0.800000, 0.800000, 1.000000 };
00386 const Color COLOR_GREY_30 = { "grey_30",
00387 0.700000, 0.700000, 0.700000, 1.000000 };
00388 const Color COLOR_GREY_40 = { "grey_40",
00389 0.600000, 0.600000, 0.600000, 1.000000 };
00390 const Color COLOR_GREY_50 = { "grey_50",
00391 0.500000, 0.500000, 0.500000, 1.000000 };
00392 const Color COLOR_GREY_60 = { "grey_60",
00393 0.400000, 0.400000, 0.400000, 1.000000 };
00394 const Color COLOR_GREY_70 = { "grey_70",
00395 0.300000, 0.300000, 0.300000, 1.000000 };
00396 const Color COLOR_GREY_80 = { "grey_80",
00397 0.200000, 0.200000, 0.200000, 1.000000 };
00398 const Color COLOR_GREY_90 = { "grey_90",
00399 0.100000, 0.100000, 0.100000, 1.000000 };
00400
00409 Color8bpp to8bpp(const Color& color);
00410
00419 std::string toHex(const Color& color);
00420
00429 Color createColorFromHex(const std::string& hexColor);
00430
00437 void addBasicColors(ColorMap& colorMap);
00438
00448 const Color* getByName(const std::string& colorName, ColorMap& colorMap);
00449
00451
00452 }
00453
00454 }
00455
00459 #endif