forked from Makuna/NeoPixelBus
Merge pull request #114 from Makuna/HtmlColorImprovements
Html String Improvements
This commit is contained in:
@@ -25,348 +25,361 @@ License along with NeoPixel. If not, see
|
||||
-------------------------------------------------------------------------*/
|
||||
#include "HtmlColor.h"
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// HtmlColorPair represents an association between a name and a HTML color code
|
||||
// ------------------------------------------------------------------------
|
||||
struct HtmlColorPair
|
||||
{
|
||||
PGM_P Name;
|
||||
uint32_t Color;
|
||||
};
|
||||
|
||||
/* HTML4 color names */
|
||||
static const char name_aqua[] PROGMEM = "aqua";
|
||||
static const char name_black[] PROGMEM = "black";
|
||||
static const char name_blue[] PROGMEM = "blue";
|
||||
static const char name_fuchsia[] PROGMEM = "fuchsia";
|
||||
static const char name_gray[] PROGMEM = "gray";
|
||||
static const char name_green[] PROGMEM = "green";
|
||||
static const char name_lime[] PROGMEM = "lime";
|
||||
static const char name_maroon[] PROGMEM = "maroon";
|
||||
static const char name_navy[] PROGMEM = "navy";
|
||||
static const char name_olive[] PROGMEM = "olive";
|
||||
static const char name_orange[] PROGMEM = "orange";
|
||||
static const char name_purple[] PROGMEM = "purple";
|
||||
static const char name_red[] PROGMEM = "red";
|
||||
static const char name_silver[] PROGMEM = "silver";
|
||||
static const char name_teal[] PROGMEM = "teal";
|
||||
static const char name_white[] PROGMEM = "white";
|
||||
static const char name_yellow[] PROGMEM = "yellow";
|
||||
static const char c_HtmlNameAqua[] PROGMEM = "aqua";
|
||||
static const char c_HtmlNameBlack[] PROGMEM = "black";
|
||||
static const char c_HtmlNameBlue[] PROGMEM = "blue";
|
||||
static const char c_HtmlNameFuchsia[] PROGMEM = "fuchsia";
|
||||
static const char c_HtmlNameGray[] PROGMEM = "gray";
|
||||
static const char c_HtmlNameGreen[] PROGMEM = "green";
|
||||
static const char c_HtmlNameLime[] PROGMEM = "lime";
|
||||
static const char c_HtmlNameMaroon[] PROGMEM = "maroon";
|
||||
static const char c_HtmlNameNavy[] PROGMEM = "navy";
|
||||
static const char c_HtmlNameOlive[] PROGMEM = "olive";
|
||||
static const char c_HtmlNameOrange[] PROGMEM = "orange";
|
||||
static const char c_HtmlNamePurple[] PROGMEM = "purple";
|
||||
static const char c_HtmlNameRed[] PROGMEM = "red";
|
||||
static const char c_HtmlNameSilver[] PROGMEM = "silver";
|
||||
static const char c_HtmlNameTeal[] PROGMEM = "teal";
|
||||
static const char c_HtmlNameWhite[] PROGMEM = "white";
|
||||
static const char c_HtmlNameYellow[] PROGMEM = "yellow";
|
||||
|
||||
#if defined(USE_CSS3_COLORS)
|
||||
/* Additional CSS3 color names */
|
||||
static const char name_aliceblue[] PROGMEM = "aliceblue";
|
||||
static const char name_antiquewhite[] PROGMEM = "antiquewhite";
|
||||
static const char name_aquamarine[] PROGMEM = "aquamarine";
|
||||
static const char name_azure[] PROGMEM = "azure";
|
||||
static const char name_beige[] PROGMEM = "beige";
|
||||
static const char name_bisque[] PROGMEM = "bisque";
|
||||
static const char name_blanchedalmond[] PROGMEM = "blanchedalmond";
|
||||
static const char name_blueviolet[] PROGMEM = "blueviolet";
|
||||
static const char name_brown[] PROGMEM = "brown";
|
||||
static const char name_burlywood[] PROGMEM = "burlywood";
|
||||
static const char name_cadetblue[] PROGMEM = "cadetblue";
|
||||
static const char name_chartreuse[] PROGMEM = "chartreuse";
|
||||
static const char name_chocolate[] PROGMEM = "chocolate";
|
||||
static const char name_coral[] PROGMEM = "coral";
|
||||
static const char name_cornflowerblue[] PROGMEM = "cornflowerblue";
|
||||
static const char name_cornsilk[] PROGMEM = "cornsilk";
|
||||
static const char name_crimson[] PROGMEM = "crimson";
|
||||
static const char name_cyan[] PROGMEM = "cyan";
|
||||
static const char name_darkblue[] PROGMEM = "darkblue";
|
||||
static const char name_darkcyan[] PROGMEM = "darkcyan";
|
||||
static const char name_darkgoldenrod[] PROGMEM = "darkgoldenrod";
|
||||
static const char name_darkgray[] PROGMEM = "darkgray";
|
||||
static const char name_darkgreen[] PROGMEM = "darkgreen";
|
||||
static const char name_darkgrey[] PROGMEM = "darkgrey";
|
||||
static const char name_darkkhaki[] PROGMEM = "darkkhaki";
|
||||
static const char name_darkmagenta[] PROGMEM = "darkmagenta";
|
||||
static const char name_darkolivegreen[] PROGMEM = "darkolivegreen";
|
||||
static const char name_darkorange[] PROGMEM = "darkorange";
|
||||
static const char name_darkorchid[] PROGMEM = "darkorchid";
|
||||
static const char name_darkred[] PROGMEM = "darkred";
|
||||
static const char name_darksalmon[] PROGMEM = "darksalmon";
|
||||
static const char name_darkseagreen[] PROGMEM = "darkseagreen";
|
||||
static const char name_darkslateblue[] PROGMEM = "darkslateblue";
|
||||
static const char name_darkslategray[] PROGMEM = "darkslategray";
|
||||
static const char name_darkslategrey[] PROGMEM = "darkslategrey";
|
||||
static const char name_darkturquoise[] PROGMEM = "darkturquoise";
|
||||
static const char name_darkviolet[] PROGMEM = "darkviolet";
|
||||
static const char name_deeppink[] PROGMEM = "deeppink";
|
||||
static const char name_deepskyblue[] PROGMEM = "deepskyblue";
|
||||
static const char name_dimgray[] PROGMEM = "dimgray";
|
||||
static const char name_dimgrey[] PROGMEM = "dimgrey";
|
||||
static const char name_dodgerblue[] PROGMEM = "dodgerblue";
|
||||
static const char name_firebrick[] PROGMEM = "firebrick";
|
||||
static const char name_floralwhite[] PROGMEM = "floralwhite";
|
||||
static const char name_forestgreen[] PROGMEM = "forestgreen";
|
||||
static const char name_gainsboro[] PROGMEM = "gainsboro";
|
||||
static const char name_ghostwhite[] PROGMEM = "ghostwhite";
|
||||
static const char name_gold[] PROGMEM = "gold";
|
||||
static const char name_goldenrod[] PROGMEM = "goldenrod";
|
||||
static const char name_greenyellow[] PROGMEM = "greenyellow";
|
||||
static const char name_grey[] PROGMEM = "grey";
|
||||
static const char name_honeydew[] PROGMEM = "honeydew";
|
||||
static const char name_hotpink[] PROGMEM = "hotpink";
|
||||
static const char name_indianred[] PROGMEM = "indianred";
|
||||
static const char name_indigo[] PROGMEM = "indigo";
|
||||
static const char name_ivory[] PROGMEM = "ivory";
|
||||
static const char name_khaki[] PROGMEM = "khaki";
|
||||
static const char name_lavender[] PROGMEM = "lavender";
|
||||
static const char name_lavenderblush[] PROGMEM = "lavenderblush";
|
||||
static const char name_lawngreen[] PROGMEM = "lawngreen";
|
||||
static const char name_lemonchiffon[] PROGMEM = "lemonchiffon";
|
||||
static const char name_lightblue[] PROGMEM = "lightblue";
|
||||
static const char name_lightcoral[] PROGMEM = "lightcoral";
|
||||
static const char name_lightcyan[] PROGMEM = "lightcyan";
|
||||
static const char name_lightgoldenrodyellow[] PROGMEM = "lightgoldenrodyellow";
|
||||
static const char name_lightgray[] PROGMEM = "lightgray";
|
||||
static const char name_lightgreen[] PROGMEM = "lightgreen";
|
||||
static const char name_lightgrey[] PROGMEM = "lightgrey";
|
||||
static const char name_lightpink[] PROGMEM = "lightpink";
|
||||
static const char name_lightsalmon[] PROGMEM = "lightsalmon";
|
||||
static const char name_lightseagreen[] PROGMEM = "lightseagreen";
|
||||
static const char name_lightskyblue[] PROGMEM = "lightskyblue";
|
||||
static const char name_lightslategray[] PROGMEM = "lightslategray";
|
||||
static const char name_lightslategrey[] PROGMEM = "lightslategrey";
|
||||
static const char name_lightsteelblue[] PROGMEM = "lightsteelblue";
|
||||
static const char name_lightyellow[] PROGMEM = "lightyellow";
|
||||
static const char name_limegreen[] PROGMEM = "limegreen";
|
||||
static const char name_linen[] PROGMEM = "linen";
|
||||
static const char name_magenta[] PROGMEM = "magenta";
|
||||
static const char name_mediumaquamarine[] PROGMEM = "mediumaquamarine";
|
||||
static const char name_mediumblue[] PROGMEM = "mediumblue";
|
||||
static const char name_mediumorchid[] PROGMEM = "mediumorchid";
|
||||
static const char name_mediumpurple[] PROGMEM = "mediumpurple";
|
||||
static const char name_mediumseagreen[] PROGMEM = "mediumseagreen";
|
||||
static const char name_mediumslateblue[] PROGMEM = "mediumslateblue";
|
||||
static const char name_mediumspringgreen[] PROGMEM = "mediumspringgreen";
|
||||
static const char name_mediumturquoise[] PROGMEM = "mediumturquoise";
|
||||
static const char name_mediumvioletred[] PROGMEM = "mediumvioletred";
|
||||
static const char name_midnightblue[] PROGMEM = "midnightblue";
|
||||
static const char name_mintcream[] PROGMEM = "mintcream";
|
||||
static const char name_mistyrose[] PROGMEM = "mistyrose";
|
||||
static const char name_moccasin[] PROGMEM = "moccasin";
|
||||
static const char name_navajowhite[] PROGMEM = "navajowhite";
|
||||
static const char name_oldlace[] PROGMEM = "oldlace";
|
||||
static const char name_olivedrab[] PROGMEM = "olivedrab";
|
||||
static const char name_orangered[] PROGMEM = "orangered";
|
||||
static const char name_orchid[] PROGMEM = "orchid";
|
||||
static const char name_palegoldenrod[] PROGMEM = "palegoldenrod";
|
||||
static const char name_palegreen[] PROGMEM = "palegreen";
|
||||
static const char name_paleturquoise[] PROGMEM = "paleturquoise";
|
||||
static const char name_palevioletred[] PROGMEM = "palevioletred";
|
||||
static const char name_papayawhip[] PROGMEM = "papayawhip";
|
||||
static const char name_peachpuff[] PROGMEM = "peachpuff";
|
||||
static const char name_peru[] PROGMEM = "peru";
|
||||
static const char name_pink[] PROGMEM = "pink";
|
||||
static const char name_plum[] PROGMEM = "plum";
|
||||
static const char name_powderblue[] PROGMEM = "powderblue";
|
||||
static const char name_rosybrown[] PROGMEM = "rosybrown";
|
||||
static const char name_royalblue[] PROGMEM = "royalblue";
|
||||
static const char name_saddlebrown[] PROGMEM = "saddlebrown";
|
||||
static const char name_salmon[] PROGMEM = "salmon";
|
||||
static const char name_sandybrown[] PROGMEM = "sandybrown";
|
||||
static const char name_seagreen[] PROGMEM = "seagreen";
|
||||
static const char name_seashell[] PROGMEM = "seashell";
|
||||
static const char name_sienna[] PROGMEM = "sienna";
|
||||
static const char name_skyblue[] PROGMEM = "skyblue";
|
||||
static const char name_slateblue[] PROGMEM = "slateblue";
|
||||
static const char name_slategray[] PROGMEM = "slategray";
|
||||
static const char name_slategrey[] PROGMEM = "slategrey";
|
||||
static const char name_snow[] PROGMEM = "snow";
|
||||
static const char name_springgreen[] PROGMEM = "springgreen";
|
||||
static const char name_steelblue[] PROGMEM = "steelblue";
|
||||
static const char name_tan[] PROGMEM = "tan";
|
||||
static const char name_thistle[] PROGMEM = "thistle";
|
||||
static const char name_tomato[] PROGMEM = "tomato";
|
||||
static const char name_turquoise[] PROGMEM = "turquoise";
|
||||
static const char name_violet[] PROGMEM = "violet";
|
||||
static const char name_wheat[] PROGMEM = "wheat";
|
||||
static const char name_whitesmoke[] PROGMEM = "whitesmoke";
|
||||
static const char name_yellowgreen[] PROGMEM = "yellowgreen";
|
||||
static const char c_HtmlNameAliceBlue[] PROGMEM = "aliceblue";
|
||||
static const char c_HtmlNameAntiqueWhite[] PROGMEM = "antiquewhite";
|
||||
static const char c_HtmlNameAquamarine[] PROGMEM = "aquamarine";
|
||||
static const char c_HtmlNameAzure[] PROGMEM = "azure";
|
||||
static const char c_HtmlNameBeige[] PROGMEM = "beige";
|
||||
static const char c_HtmlNameBisque[] PROGMEM = "bisque";
|
||||
static const char c_HtmlNameBlanchedAlmond[] PROGMEM = "blanchedalmond";
|
||||
static const char c_HtmlNameBlueViolet[] PROGMEM = "blueviolet";
|
||||
static const char c_HtmlNameBrown[] PROGMEM = "brown";
|
||||
static const char c_HtmlNameBurlyWood[] PROGMEM = "burlywood";
|
||||
static const char c_HtmlNameCadetBlue[] PROGMEM = "cadetblue";
|
||||
static const char c_HtmlNameChartreuse[] PROGMEM = "chartreuse";
|
||||
static const char c_HtmlNameChocolate[] PROGMEM = "chocolate";
|
||||
static const char c_HtmlNameCoral[] PROGMEM = "coral";
|
||||
static const char c_HtmlNameCornflowerBlue[] PROGMEM = "cornflowerblue";
|
||||
static const char c_HtmlNameCornsilk[] PROGMEM = "cornsilk";
|
||||
static const char c_HtmlNameCrimson[] PROGMEM = "crimson";
|
||||
static const char c_HtmlNameCyan[] PROGMEM = "cyan";
|
||||
static const char c_HtmlNameDarkBlue[] PROGMEM = "darkblue";
|
||||
static const char c_HtmlNameDarkCyan[] PROGMEM = "darkcyan";
|
||||
static const char c_HtmlNameDarkGoldenrod[] PROGMEM = "darkgoldenrod";
|
||||
static const char c_HtmlNameDarkGray[] PROGMEM = "darkgray";
|
||||
static const char c_HtmlNameDarkGreen[] PROGMEM = "darkgreen";
|
||||
static const char c_HtmlNameDarkGrey[] PROGMEM = "darkgrey";
|
||||
static const char c_HtmlNameDarkKhaki[] PROGMEM = "darkkhaki";
|
||||
static const char c_HtmlNameDarkMagenta[] PROGMEM = "darkmagenta";
|
||||
static const char c_HtmlNameDarkOliveGreen[] PROGMEM = "darkolivegreen";
|
||||
static const char c_HtmlNameDarkOrange[] PROGMEM = "darkorange";
|
||||
static const char c_HtmlNameDarkOrchid[] PROGMEM = "darkorchid";
|
||||
static const char c_HtmlNameDarkRed[] PROGMEM = "darkred";
|
||||
static const char c_HtmlNameDarkSalmon[] PROGMEM = "darksalmon";
|
||||
static const char c_HtmlNameDarkSeaGreen[] PROGMEM = "darkseagreen";
|
||||
static const char c_HtmlNameDarkSlateBlue[] PROGMEM = "darkslateblue";
|
||||
static const char c_HtmlNameDarkSlateGray[] PROGMEM = "darkslategray";
|
||||
static const char c_HtmlNameDarkSlateGrey[] PROGMEM = "darkslategrey";
|
||||
static const char c_HtmlNameDarkTurquoise[] PROGMEM = "darkturquoise";
|
||||
static const char c_HtmlNameDarkViolet[] PROGMEM = "darkviolet";
|
||||
static const char c_HtmlNameDeepPink[] PROGMEM = "deeppink";
|
||||
static const char c_HtmlNameDeepSkyBlue[] PROGMEM = "deepskyblue";
|
||||
static const char c_HtmlNameDimGray[] PROGMEM = "dimgray";
|
||||
static const char c_HtmlNameDimGrey[] PROGMEM = "dimgrey";
|
||||
static const char c_HtmlNameDodgerBlue[] PROGMEM = "dodgerblue";
|
||||
static const char c_HtmlNameFirebrick[] PROGMEM = "firebrick";
|
||||
static const char c_HtmlNameFloralWhite[] PROGMEM = "floralwhite";
|
||||
static const char c_HtmlNameForestGreen[] PROGMEM = "forestgreen";
|
||||
static const char c_HtmlNameGainsboro[] PROGMEM = "gainsboro";
|
||||
static const char c_HtmlNameGhostWhite[] PROGMEM = "ghostwhite";
|
||||
static const char c_HtmlNameGold[] PROGMEM = "gold";
|
||||
static const char c_HtmlNameGoldenrod[] PROGMEM = "goldenrod";
|
||||
static const char c_HtmlNameGreenYellow[] PROGMEM = "greenyellow";
|
||||
static const char c_HtmlNameGrey[] PROGMEM = "grey";
|
||||
static const char c_HtmlNameHoneydew[] PROGMEM = "honeydew";
|
||||
static const char c_HtmlNameHotPink[] PROGMEM = "hotpink";
|
||||
static const char c_HtmlNameIndianRed[] PROGMEM = "indianred";
|
||||
static const char c_HtmlNameIndigo[] PROGMEM = "indigo";
|
||||
static const char c_HtmlNameIvory[] PROGMEM = "ivory";
|
||||
static const char c_HtmlNameKhaki[] PROGMEM = "khaki";
|
||||
static const char c_HtmlNameLavender[] PROGMEM = "lavender";
|
||||
static const char c_HtmlNameLavenderBlush[] PROGMEM = "lavenderblush";
|
||||
static const char c_HtmlNameLawnGreen[] PROGMEM = "lawngreen";
|
||||
static const char c_HtmlNameLemonChiffon[] PROGMEM = "lemonchiffon";
|
||||
static const char c_HtmlNameLightBlue[] PROGMEM = "lightblue";
|
||||
static const char c_HtmlNameLightCoral[] PROGMEM = "lightcoral";
|
||||
static const char c_HtmlNameLightCyan[] PROGMEM = "lightcyan";
|
||||
static const char c_HtmlNameLightGoldenrodYellow[] PROGMEM = "lightgoldenrodyellow";
|
||||
static const char c_HtmlNameLightGray[] PROGMEM = "lightgray";
|
||||
static const char c_HtmlNameLightGreen[] PROGMEM = "lightgreen";
|
||||
static const char c_HtmlNameLightGrey[] PROGMEM = "lightgrey";
|
||||
static const char c_HtmlNameLightPink[] PROGMEM = "lightpink";
|
||||
static const char c_HtmlNameLightSalmon[] PROGMEM = "lightsalmon";
|
||||
static const char c_HtmlNameLightSeaGreen[] PROGMEM = "lightseagreen";
|
||||
static const char c_HtmlNameLightSkyBlue[] PROGMEM = "lightskyblue";
|
||||
static const char c_HtmlNameLightSlateGray[] PROGMEM = "lightslategray";
|
||||
static const char c_HtmlNameLightSlateGrey[] PROGMEM = "lightslategrey";
|
||||
static const char c_HtmlNameLightSteelBlue[] PROGMEM = "lightsteelblue";
|
||||
static const char c_HtmlNameLightYellow[] PROGMEM = "lightyellow";
|
||||
static const char c_HtmlNameLimeGreen[] PROGMEM = "limegreen";
|
||||
static const char c_HtmlNameLinen[] PROGMEM = "linen";
|
||||
static const char c_HtmlNameMagenta[] PROGMEM = "magenta";
|
||||
static const char c_HtmlNameMediumAquamarine[] PROGMEM = "mediumaquamarine";
|
||||
static const char c_HtmlNameMediumBlue[] PROGMEM = "mediumblue";
|
||||
static const char c_HtmlNameMediumOrchid[] PROGMEM = "mediumorchid";
|
||||
static const char c_HtmlNameMediumPurple[] PROGMEM = "mediumpurple";
|
||||
static const char c_HtmlNameMediumSeagreen[] PROGMEM = "mediumseagreen";
|
||||
static const char c_HtmlNameMediumSlateBlue[] PROGMEM = "mediumslateblue";
|
||||
static const char c_HtmlNameMediumSpringGreen[] PROGMEM = "mediumspringgreen";
|
||||
static const char c_HtmlNameMediumTurquoise[] PROGMEM = "mediumturquoise";
|
||||
static const char c_HtmlNameMediumVioletRed[] PROGMEM = "mediumvioletred";
|
||||
static const char c_HtmlNameMidnightBlue[] PROGMEM = "midnightblue";
|
||||
static const char c_HtmlNameMintCream[] PROGMEM = "mintcream";
|
||||
static const char c_HtmlNameMistyRose[] PROGMEM = "mistyrose";
|
||||
static const char c_HtmlNameMoccasin[] PROGMEM = "moccasin";
|
||||
static const char c_HtmlNameNavajoWhite[] PROGMEM = "navajowhite";
|
||||
static const char c_HtmlNameOldLace[] PROGMEM = "oldlace";
|
||||
static const char c_HtmlNameOliveDrab[] PROGMEM = "olivedrab";
|
||||
static const char c_HtmlNameOrangeRed[] PROGMEM = "orangered";
|
||||
static const char c_HtmlNameOrchid[] PROGMEM = "orchid";
|
||||
static const char c_HtmlNamePaleGoldenrod[] PROGMEM = "palegoldenrod";
|
||||
static const char c_HtmlNamePaleGreen[] PROGMEM = "palegreen";
|
||||
static const char c_HtmlNamePaleTurquoise[] PROGMEM = "paleturquoise";
|
||||
static const char c_HtmlNamePaleVioletRed[] PROGMEM = "palevioletred";
|
||||
static const char c_HtmlNamePapayaWhip[] PROGMEM = "papayawhip";
|
||||
static const char c_HtmlNamePeachPuff[] PROGMEM = "peachpuff";
|
||||
static const char c_HtmlNamePeru[] PROGMEM = "peru";
|
||||
static const char c_HtmlNamePink[] PROGMEM = "pink";
|
||||
static const char c_HtmlNamePlum[] PROGMEM = "plum";
|
||||
static const char c_HtmlNamePowderBlue[] PROGMEM = "powderblue";
|
||||
static const char c_HtmlNameRosyBrown[] PROGMEM = "rosybrown";
|
||||
static const char c_HtmlNameRoyalBlue[] PROGMEM = "royalblue";
|
||||
static const char c_HtmlNameSaddleBrown[] PROGMEM = "saddlebrown";
|
||||
static const char c_HtmlNameSalmon[] PROGMEM = "salmon";
|
||||
static const char c_HtmlNameSandyBrown[] PROGMEM = "sandybrown";
|
||||
static const char c_HtmlNameSeaGreen[] PROGMEM = "seagreen";
|
||||
static const char c_HtmlNameSeaShell[] PROGMEM = "seashell";
|
||||
static const char c_HtmlNameSienna[] PROGMEM = "sienna";
|
||||
static const char c_HtmlNameSkyBlue[] PROGMEM = "skyblue";
|
||||
static const char c_HtmlNameSlateBlue[] PROGMEM = "slateblue";
|
||||
static const char c_HtmlNameSlateGray[] PROGMEM = "slategray";
|
||||
static const char c_HtmlNameSlateGrey[] PROGMEM = "slategrey";
|
||||
static const char c_HtmlNameSnow[] PROGMEM = "snow";
|
||||
static const char c_HtmlNameSpringGreen[] PROGMEM = "springgreen";
|
||||
static const char c_HtmlNameSteelBlue[] PROGMEM = "steelblue";
|
||||
static const char c_HtmlNameTan[] PROGMEM = "tan";
|
||||
static const char c_HtmlNameThistle[] PROGMEM = "thistle";
|
||||
static const char c_HtmlNameTomato[] PROGMEM = "tomato";
|
||||
static const char c_HtmlNameTurquoise[] PROGMEM = "turquoise";
|
||||
static const char c_HtmlNameViolet[] PROGMEM = "violet";
|
||||
static const char c_HtmlNameWheat[] PROGMEM = "wheat";
|
||||
static const char c_HtmlNameWhiteSmoke[] PROGMEM = "whitesmoke";
|
||||
static const char c_HtmlNameYellowGreen[] PROGMEM = "yellowgreen";
|
||||
#endif
|
||||
|
||||
const HtmlColorName HtmlColor::ColorNames[] PROGMEM = {
|
||||
const HtmlColorPair c_ColorNames[] PROGMEM = {
|
||||
#if defined(USE_CSS3_COLORS)
|
||||
{ name_aliceblue, 0xf0f8ff},
|
||||
{ name_antiquewhite, 0xfaebd7},
|
||||
{ name_aqua, 0xffff},
|
||||
{ name_aquamarine, 0x7fffd4},
|
||||
{ name_azure, 0xf0ffff},
|
||||
{ name_beige, 0xf5f5dc},
|
||||
{ name_bisque, 0xffe4c4},
|
||||
{ name_black, 0x0},
|
||||
{ name_blanchedalmond, 0xffebcd},
|
||||
{ name_blue, 0xff},
|
||||
{ name_blueviolet, 0x8a2be2},
|
||||
{ name_brown, 0xa52a2a},
|
||||
{ name_burlywood, 0xdeb887},
|
||||
{ name_cadetblue, 0x5f9ea0},
|
||||
{ name_chartreuse, 0x7fff00},
|
||||
{ name_chocolate, 0xd2691e},
|
||||
{ name_coral, 0xff7f50},
|
||||
{ name_cornflowerblue, 0x6495ed},
|
||||
{ name_cornsilk, 0xfff8dc},
|
||||
{ name_crimson, 0xdc143c},
|
||||
{ name_cyan, 0xffff},
|
||||
{ name_darkblue, 0x8b},
|
||||
{ name_darkcyan, 0x8b8b},
|
||||
{ name_darkgoldenrod, 0xb8860b},
|
||||
{ name_darkgray, 0xa9a9a9},
|
||||
{ name_darkgreen, 0x6400},
|
||||
{ name_darkgrey, 0xa9a9a9},
|
||||
{ name_darkkhaki, 0xbdb76b},
|
||||
{ name_darkmagenta, 0x8b008b},
|
||||
{ name_darkolivegreen, 0x556b2f},
|
||||
{ name_darkorange, 0xff8c00},
|
||||
{ name_darkorchid, 0x9932cc},
|
||||
{ name_darkred, 0x8b0000},
|
||||
{ name_darksalmon, 0xe9967a},
|
||||
{ name_darkseagreen, 0x8fbc8f},
|
||||
{ name_darkslateblue, 0x483d8b},
|
||||
{ name_darkslategray, 0x2f4f4f},
|
||||
{ name_darkslategrey, 0x2f4f4f},
|
||||
{ name_darkturquoise, 0xced1},
|
||||
{ name_darkviolet, 0x9400d3},
|
||||
{ name_deeppink, 0xff1493},
|
||||
{ name_deepskyblue, 0xbfff},
|
||||
{ name_dimgray, 0x696969},
|
||||
{ name_dimgrey, 0x696969},
|
||||
{ name_dodgerblue, 0x1e90ff},
|
||||
{ name_firebrick, 0xb22222},
|
||||
{ name_floralwhite, 0xfffaf0},
|
||||
{ name_forestgreen, 0x228b22},
|
||||
{ name_fuchsia, 0xff00ff},
|
||||
{ name_gainsboro, 0xdcdcdc},
|
||||
{ name_ghostwhite, 0xf8f8ff},
|
||||
{ name_gold, 0xffd700},
|
||||
{ name_goldenrod, 0xdaa520},
|
||||
{ name_gray, 0x808080},
|
||||
{ name_green, 0x8000},
|
||||
{ name_greenyellow, 0xadff2f},
|
||||
{ name_grey, 0x808080},
|
||||
{ name_honeydew, 0xf0fff0},
|
||||
{ name_hotpink, 0xff69b4},
|
||||
{ name_indianred, 0xcd5c5c},
|
||||
{ name_indigo, 0x4b0082},
|
||||
{ name_ivory, 0xfffff0},
|
||||
{ name_khaki, 0xf0e68c},
|
||||
{ name_lavender, 0xe6e6fa},
|
||||
{ name_lavenderblush, 0xfff0f5},
|
||||
{ name_lawngreen, 0x7cfc00},
|
||||
{ name_lemonchiffon, 0xfffacd},
|
||||
{ name_lightblue, 0xadd8e6},
|
||||
{ name_lightcoral, 0xf08080},
|
||||
{ name_lightcyan, 0xe0ffff},
|
||||
{ name_lightgoldenrodyellow, 0xfafad2},
|
||||
{ name_lightgray, 0xd3d3d3},
|
||||
{ name_lightgreen, 0x90ee90},
|
||||
{ name_lightgrey, 0xd3d3d3},
|
||||
{ name_lightpink, 0xffb6c1},
|
||||
{ name_lightsalmon, 0xffa07a},
|
||||
{ name_lightseagreen, 0x20b2aa},
|
||||
{ name_lightskyblue, 0x87cefa},
|
||||
{ name_lightslategray, 0x778899},
|
||||
{ name_lightslategrey, 0x778899},
|
||||
{ name_lightsteelblue, 0xb0c4de},
|
||||
{ name_lightyellow, 0xffffe0},
|
||||
{ name_lime, 0xff00},
|
||||
{ name_limegreen, 0x32cd32},
|
||||
{ name_linen, 0xfaf0e6},
|
||||
{ name_magenta, 0xff00ff},
|
||||
{ name_maroon, 0x800000},
|
||||
{ name_mediumaquamarine, 0x66cdaa},
|
||||
{ name_mediumblue, 0xcd},
|
||||
{ name_mediumorchid, 0xba55d3},
|
||||
{ name_mediumpurple, 0x9370d8},
|
||||
{ name_mediumseagreen, 0x3cb371},
|
||||
{ name_mediumslateblue, 0x7b68ee},
|
||||
{ name_mediumspringgreen, 0xfa9a},
|
||||
{ name_mediumturquoise, 0x48d1cc},
|
||||
{ name_mediumvioletred, 0xc71585},
|
||||
{ name_midnightblue, 0x191970},
|
||||
{ name_mintcream, 0xf5fffa},
|
||||
{ name_mistyrose, 0xffe4e1},
|
||||
{ name_moccasin, 0xffe4b5},
|
||||
{ name_navajowhite, 0xffdead},
|
||||
{ name_navy, 0x80},
|
||||
{ name_oldlace, 0xfdf5e6},
|
||||
{ name_olive, 0x808000},
|
||||
{ name_olivedrab, 0x6b8e23},
|
||||
{ name_orange, 0xffa500},
|
||||
{ name_orangered, 0xff4500},
|
||||
{ name_orchid, 0xda70d6},
|
||||
{ name_palegoldenrod, 0xeee8aa},
|
||||
{ name_palegreen, 0x98fb98},
|
||||
{ name_paleturquoise, 0xafeeee},
|
||||
{ name_palevioletred, 0xd87093},
|
||||
{ name_papayawhip, 0xffefd5},
|
||||
{ name_peachpuff, 0xffdab9},
|
||||
{ name_peru, 0xcd853f},
|
||||
{ name_pink, 0xffc0cb},
|
||||
{ name_plum, 0xdda0dd},
|
||||
{ name_powderblue, 0xb0e0e6},
|
||||
{ name_purple, 0x800080},
|
||||
{ name_red, 0xff0000},
|
||||
{ name_rosybrown, 0xbc8f8f},
|
||||
{ name_royalblue, 0x4169e1},
|
||||
{ name_saddlebrown, 0x8b4513},
|
||||
{ name_salmon, 0xfa8072},
|
||||
{ name_sandybrown, 0xf4a460},
|
||||
{ name_seagreen, 0x2e8b57},
|
||||
{ name_seashell, 0xfff5ee},
|
||||
{ name_sienna, 0xa0522d},
|
||||
{ name_silver, 0xc0c0c0},
|
||||
{ name_skyblue, 0x87ceeb},
|
||||
{ name_slateblue, 0x6a5acd},
|
||||
{ name_slategray, 0x708090},
|
||||
{ name_slategrey, 0x708090},
|
||||
{ name_snow, 0xfffafa},
|
||||
{ name_springgreen, 0xff7f},
|
||||
{ name_steelblue, 0x4682b4},
|
||||
{ name_tan, 0xd2b48c},
|
||||
{ name_teal, 0x8080},
|
||||
{ name_thistle, 0xd8bfd8},
|
||||
{ name_tomato, 0xff6347},
|
||||
{ name_turquoise, 0x40e0d0},
|
||||
{ name_violet, 0xee82ee},
|
||||
{ name_wheat, 0xf5deb3},
|
||||
{ name_white, 0xffffff},
|
||||
{ name_whitesmoke, 0xf5f5f5},
|
||||
{ name_yellow, 0xffff00},
|
||||
{ name_yellowgreen, 0x9acd32},
|
||||
{ c_HtmlNameAliceBlue, 0xf0f8ff},
|
||||
{ c_HtmlNameAntiqueWhite, 0xfaebd7},
|
||||
{ c_HtmlNameAqua, 0xffff},
|
||||
{ c_HtmlNameAquamarine, 0x7fffd4},
|
||||
{ c_HtmlNameAzure, 0xf0ffff},
|
||||
{ c_HtmlNameBeige, 0xf5f5dc},
|
||||
{ c_HtmlNameBisque, 0xffe4c4},
|
||||
{ c_HtmlNameBlack, 0x0},
|
||||
{ c_HtmlNameBlanchedAlmond, 0xffebcd},
|
||||
{ c_HtmlNameBlue, 0xff},
|
||||
{ c_HtmlNameBlueViolet, 0x8a2be2},
|
||||
{ c_HtmlNameBrown, 0xa52a2a},
|
||||
{ c_HtmlNameBurlyWood, 0xdeb887},
|
||||
{ c_HtmlNameCadetBlue, 0x5f9ea0},
|
||||
{ c_HtmlNameChartreuse, 0x7fff00},
|
||||
{ c_HtmlNameChocolate, 0xd2691e},
|
||||
{ c_HtmlNameCoral, 0xff7f50},
|
||||
{ c_HtmlNameCornflowerBlue, 0x6495ed},
|
||||
{ c_HtmlNameCornsilk, 0xfff8dc},
|
||||
{ c_HtmlNameCrimson, 0xdc143c},
|
||||
{ c_HtmlNameCyan, 0xffff},
|
||||
{ c_HtmlNameDarkBlue, 0x8b},
|
||||
{ c_HtmlNameDarkCyan, 0x8b8b},
|
||||
{ c_HtmlNameDarkGoldenrod, 0xb8860b},
|
||||
{ c_HtmlNameDarkGray, 0xa9a9a9},
|
||||
{ c_HtmlNameDarkGreen, 0x6400},
|
||||
{ c_HtmlNameDarkGrey, 0xa9a9a9},
|
||||
{ c_HtmlNameDarkKhaki, 0xbdb76b},
|
||||
{ c_HtmlNameDarkMagenta, 0x8b008b},
|
||||
{ c_HtmlNameDarkOliveGreen, 0x556b2f},
|
||||
{ c_HtmlNameDarkOrange, 0xff8c00},
|
||||
{ c_HtmlNameDarkOrchid, 0x9932cc},
|
||||
{ c_HtmlNameDarkRed, 0x8b0000},
|
||||
{ c_HtmlNameDarkSalmon, 0xe9967a},
|
||||
{ c_HtmlNameDarkSeaGreen, 0x8fbc8f},
|
||||
{ c_HtmlNameDarkSlateBlue, 0x483d8b},
|
||||
{ c_HtmlNameDarkSlateGray, 0x2f4f4f},
|
||||
{ c_HtmlNameDarkSlateGrey, 0x2f4f4f},
|
||||
{ c_HtmlNameDarkTurquoise, 0xced1},
|
||||
{ c_HtmlNameDarkViolet, 0x9400d3},
|
||||
{ c_HtmlNameDeepPink, 0xff1493},
|
||||
{ c_HtmlNameDeepSkyBlue, 0xbfff},
|
||||
{ c_HtmlNameDimGray, 0x696969},
|
||||
{ c_HtmlNameDimGrey, 0x696969},
|
||||
{ c_HtmlNameDodgerBlue, 0x1e90ff},
|
||||
{ c_HtmlNameFirebrick, 0xb22222},
|
||||
{ c_HtmlNameFloralWhite, 0xfffaf0},
|
||||
{ c_HtmlNameForestGreen, 0x228b22},
|
||||
{ c_HtmlNameFuchsia, 0xff00ff},
|
||||
{ c_HtmlNameGainsboro, 0xdcdcdc},
|
||||
{ c_HtmlNameGhostWhite, 0xf8f8ff},
|
||||
{ c_HtmlNameGold, 0xffd700},
|
||||
{ c_HtmlNameGoldenrod, 0xdaa520},
|
||||
{ c_HtmlNameGray, 0x808080},
|
||||
{ c_HtmlNameGreen, 0x8000},
|
||||
{ c_HtmlNameGreenYellow, 0xadff2f},
|
||||
{ c_HtmlNameGrey, 0x808080},
|
||||
{ c_HtmlNameHoneydew, 0xf0fff0},
|
||||
{ c_HtmlNameHotPink, 0xff69b4},
|
||||
{ c_HtmlNameIndianRed, 0xcd5c5c},
|
||||
{ c_HtmlNameIndigo, 0x4b0082},
|
||||
{ c_HtmlNameIvory, 0xfffff0},
|
||||
{ c_HtmlNameKhaki, 0xf0e68c},
|
||||
{ c_HtmlNameLavender, 0xe6e6fa},
|
||||
{ c_HtmlNameLavenderBlush, 0xfff0f5},
|
||||
{ c_HtmlNameLawnGreen, 0x7cfc00},
|
||||
{ c_HtmlNameLemonChiffon, 0xfffacd},
|
||||
{ c_HtmlNameLightBlue, 0xadd8e6},
|
||||
{ c_HtmlNameLightCoral, 0xf08080},
|
||||
{ c_HtmlNameLightCyan, 0xe0ffff},
|
||||
{ c_HtmlNameLightGoldenrodYellow, 0xfafad2},
|
||||
{ c_HtmlNameLightGray, 0xd3d3d3},
|
||||
{ c_HtmlNameLightGreen, 0x90ee90},
|
||||
{ c_HtmlNameLightGrey, 0xd3d3d3},
|
||||
{ c_HtmlNameLightPink, 0xffb6c1},
|
||||
{ c_HtmlNameLightSalmon, 0xffa07a},
|
||||
{ c_HtmlNameLightSeaGreen, 0x20b2aa},
|
||||
{ c_HtmlNameLightSkyBlue, 0x87cefa},
|
||||
{ c_HtmlNameLightSlateGray, 0x778899},
|
||||
{ c_HtmlNameLightSlateGrey, 0x778899},
|
||||
{ c_HtmlNameLightSteelBlue, 0xb0c4de},
|
||||
{ c_HtmlNameLightYellow, 0xffffe0},
|
||||
{ c_HtmlNameLime, 0xff00},
|
||||
{ c_HtmlNameLimeGreen, 0x32cd32},
|
||||
{ c_HtmlNameLinen, 0xfaf0e6},
|
||||
{ c_HtmlNameMagenta, 0xff00ff},
|
||||
{ c_HtmlNameMaroon, 0x800000},
|
||||
{ c_HtmlNameMediumAquamarine, 0x66cdaa},
|
||||
{ c_HtmlNameMediumBlue, 0xcd},
|
||||
{ c_HtmlNameMediumOrchid, 0xba55d3},
|
||||
{ c_HtmlNameMediumPurple, 0x9370d8},
|
||||
{ c_HtmlNameMediumSeagreen, 0x3cb371},
|
||||
{ c_HtmlNameMediumSlateBlue, 0x7b68ee},
|
||||
{ c_HtmlNameMediumSpringGreen, 0xfa9a},
|
||||
{ c_HtmlNameMediumTurquoise, 0x48d1cc},
|
||||
{ c_HtmlNameMediumVioletRed, 0xc71585},
|
||||
{ c_HtmlNameMidnightBlue, 0x191970},
|
||||
{ c_HtmlNameMintCream, 0xf5fffa},
|
||||
{ c_HtmlNameMistyRose, 0xffe4e1},
|
||||
{ c_HtmlNameMoccasin, 0xffe4b5},
|
||||
{ c_HtmlNameNavajoWhite, 0xffdead},
|
||||
{ c_HtmlNameNavy, 0x80},
|
||||
{ c_HtmlNameOldLace, 0xfdf5e6},
|
||||
{ c_HtmlNameOlive, 0x808000},
|
||||
{ c_HtmlNameOliveDrab, 0x6b8e23},
|
||||
{ c_HtmlNameOrange, 0xffa500},
|
||||
{ c_HtmlNameOrangeRed, 0xff4500},
|
||||
{ c_HtmlNameOrchid, 0xda70d6},
|
||||
{ c_HtmlNamePaleGoldenrod, 0xeee8aa},
|
||||
{ c_HtmlNamePaleGreen, 0x98fb98},
|
||||
{ c_HtmlNamePaleTurquoise, 0xafeeee},
|
||||
{ c_HtmlNamePaleVioletRed, 0xd87093},
|
||||
{ c_HtmlNamePapayaWhip, 0xffefd5},
|
||||
{ c_HtmlNamePeachPuff, 0xffdab9},
|
||||
{ c_HtmlNamePeru, 0xcd853f},
|
||||
{ c_HtmlNamePink, 0xffc0cb},
|
||||
{ c_HtmlNamePlum, 0xdda0dd},
|
||||
{ c_HtmlNamePowderBlue, 0xb0e0e6},
|
||||
{ c_HtmlNamePurple, 0x800080},
|
||||
{ c_HtmlNameRed, 0xff0000},
|
||||
{ c_HtmlNameRosyBrown, 0xbc8f8f},
|
||||
{ c_HtmlNameRoyalBlue, 0x4169e1},
|
||||
{ c_HtmlNameSaddleBrown, 0x8b4513},
|
||||
{ c_HtmlNameSalmon, 0xfa8072},
|
||||
{ c_HtmlNameSandyBrown, 0xf4a460},
|
||||
{ c_HtmlNameSeaGreen, 0x2e8b57},
|
||||
{ c_HtmlNameSeaShell, 0xfff5ee},
|
||||
{ c_HtmlNameSienna, 0xa0522d},
|
||||
{ c_HtmlNameSilver, 0xc0c0c0},
|
||||
{ c_HtmlNameSkyBlue, 0x87ceeb},
|
||||
{ c_HtmlNameSlateBlue, 0x6a5acd},
|
||||
{ c_HtmlNameSlateGray, 0x708090},
|
||||
{ c_HtmlNameSlateGrey, 0x708090},
|
||||
{ c_HtmlNameSnow, 0xfffafa},
|
||||
{ c_HtmlNameSpringGreen, 0xff7f},
|
||||
{ c_HtmlNameSteelBlue, 0x4682b4},
|
||||
{ c_HtmlNameTan, 0xd2b48c},
|
||||
{ c_HtmlNameTeal, 0x8080},
|
||||
{ c_HtmlNameThistle, 0xd8bfd8},
|
||||
{ c_HtmlNameTomato, 0xff6347},
|
||||
{ c_HtmlNameTurquoise, 0x40e0d0},
|
||||
{ c_HtmlNameViolet, 0xee82ee},
|
||||
{ c_HtmlNameWheat, 0xf5deb3},
|
||||
{ c_HtmlNameWhite, 0xffffff},
|
||||
{ c_HtmlNameWhiteSmoke, 0xf5f5f5},
|
||||
{ c_HtmlNameYellow, 0xffff00},
|
||||
{ c_HtmlNameYellowGreen, 0x9acd32},
|
||||
#else
|
||||
{ name_aqua, 0xffff},
|
||||
{ name_black, 0x0},
|
||||
{ name_blue, 0xff},
|
||||
{ name_fuchsia, 0xff00ff},
|
||||
{ name_gray, 0x808080},
|
||||
{ name_green, 0x8000},
|
||||
{ name_lime, 0xff00},
|
||||
{ name_maroon, 0x800000},
|
||||
{ name_navy, 0x80},
|
||||
{ name_olive, 0x808000},
|
||||
{ name_orange, 0xffa500},
|
||||
{ name_purple, 0x800080},
|
||||
{ name_red, 0xff0000},
|
||||
{ name_silver, 0xc0c0c0},
|
||||
{ name_teal, 0x8080},
|
||||
{ name_white, 0xffffff},
|
||||
{ name_yellow, 0xffff00},
|
||||
{ c_HtmlNameAqua, 0xffff},
|
||||
{ c_HtmlNameBlack, 0x0},
|
||||
{ c_HtmlNameBlue, 0xff},
|
||||
{ c_HtmlNameFuchsia, 0xff00ff},
|
||||
{ c_HtmlNameGray, 0x808080},
|
||||
{ c_HtmlNameGreen, 0x8000},
|
||||
{ c_HtmlNameLime, 0xff00},
|
||||
{ c_HtmlNameMaroon, 0x800000},
|
||||
{ c_HtmlNameNavy, 0x80},
|
||||
{ c_HtmlNameOlive, 0x808000},
|
||||
{ c_HtmlNameOrange, 0xffa500},
|
||||
{ c_HtmlNamePurple, 0x800080},
|
||||
{ c_HtmlNameRed, 0xff0000},
|
||||
{ c_HtmlNameSilver, 0xc0c0c0},
|
||||
{ c_HtmlNameTeal, 0x8080},
|
||||
{ c_HtmlNameWhite, 0xffffff},
|
||||
{ c_HtmlNameYellow, 0xffff00},
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef pgm_read_ptr
|
||||
// ESP8266 doesn't define this macro, but it doesn't need it either.
|
||||
// ESP8266 doesn't define this macro
|
||||
#define pgm_read_ptr(addr) (*reinterpret_cast<const void* const *>(addr))
|
||||
#endif
|
||||
|
||||
bool HtmlColor::Parse(const char* name, size_t namelen)
|
||||
#ifndef countof
|
||||
#define countof(array) (sizeof(array)/sizeof(array[0]))
|
||||
#endif
|
||||
|
||||
size_t HtmlColor::Parse(const char* name, size_t nameSize)
|
||||
{
|
||||
if (nameSize > 0)
|
||||
{
|
||||
if (name[0] == '#')
|
||||
{
|
||||
// Parse an hexadecimal notation "#rrbbgg" or "#rgb"
|
||||
if (namelen != 4 && namelen != 7)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//
|
||||
uint8_t temp[6]; // stores preconverted chars to hex values
|
||||
uint8_t tempSize = 0;
|
||||
|
||||
uint32_t color = 0;
|
||||
for (uint8_t i = 1; i < namelen; ++i)
|
||||
for (uint8_t indexChar = 1; indexChar < nameSize && indexChar < 8; ++indexChar)
|
||||
{
|
||||
char c = name[i];
|
||||
char c = name[indexChar];
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
c -= '0';
|
||||
@@ -382,32 +395,85 @@ bool HtmlColor::Parse(const char* name, size_t namelen)
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
// we found an non hexidecimal char
|
||||
// which could be null, deliminator, or other spacing
|
||||
break;
|
||||
}
|
||||
}
|
||||
color = color * 16 + c;
|
||||
if (namelen == 4)
|
||||
|
||||
temp[tempSize] = c;
|
||||
tempSize++;
|
||||
}
|
||||
|
||||
if (tempSize != 3 && tempSize != 6)
|
||||
{
|
||||
// invalid count of numerical chars
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t color = 0;
|
||||
for (uint8_t indexChar = 0; indexChar < tempSize; ++indexChar)
|
||||
{
|
||||
color = color * 16 + temp[indexChar];
|
||||
if (tempSize == 3)
|
||||
{
|
||||
// 3 digit hexadecimal notation can be supported easily
|
||||
// duplicating digits.
|
||||
color = color * 16 + c;
|
||||
color = color * 16 + temp[indexChar];
|
||||
}
|
||||
}
|
||||
Color = color;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(ColorNames)/sizeof(ColorNames[0]); ++i)
|
||||
{
|
||||
const HtmlColorName* cptr = &ColorNames[i];
|
||||
PGM_P cname = (PGM_P)pgm_read_ptr(&cptr->Name);
|
||||
if (strncasecmp_P(name, cname, namelen) == 0 && strlen_P(cname) == namelen)
|
||||
{
|
||||
Color = pgm_read_dword(&cptr->Color);
|
||||
return true;
|
||||
Color = color;
|
||||
return tempSize;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
else
|
||||
{
|
||||
// parse a standard name for the color
|
||||
//
|
||||
|
||||
// the normal list is small enough a binary search isn't interesting,
|
||||
for (uint8_t indexName = 0; indexName < countof(c_ColorNames); ++indexName)
|
||||
{
|
||||
const HtmlColorPair* colorPair = &c_ColorNames[indexName];
|
||||
PGM_P searchName = (PGM_P)pgm_read_ptr(&colorPair->Name);
|
||||
size_t str1Size = nameSize;
|
||||
const char* str1 = name;
|
||||
const char* str2P = searchName;
|
||||
|
||||
uint16_t result;
|
||||
|
||||
while (str1Size > 0)
|
||||
{
|
||||
char ch1 = tolower(*str1++);
|
||||
char ch2 = tolower(pgm_read_byte(str2P++));
|
||||
result = ch1 - ch2;
|
||||
if (result != 0 || ch2 == '\0')
|
||||
{
|
||||
if (ch2 == '\0' && !isalnum(ch1))
|
||||
{
|
||||
// the string continues but is not part of a
|
||||
// valid color name,
|
||||
// ends in white space, deliminator, etc
|
||||
result = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
result = -1; // have not reached the end of searchName;
|
||||
str1Size--;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
Color = pgm_read_dword(&colorPair->Color);
|
||||
return nameSize - str1Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline char hexdigit(uint8_t v)
|
||||
@@ -415,41 +481,46 @@ static inline char hexdigit(uint8_t v)
|
||||
return v + (v < 10 ? '0' : 'a' - 10);
|
||||
}
|
||||
|
||||
size_t HtmlColor::ToString(char* buf, size_t buflen) const
|
||||
size_t HtmlColor::ToString(char* buf, size_t bufSize) const
|
||||
{
|
||||
for (uint8_t i = 0; i < sizeof(ColorNames) / sizeof(ColorNames[0]); ++i)
|
||||
// search for a color value/name pairs first
|
||||
for (uint8_t indexName = 0; indexName < countof(c_ColorNames); ++indexName)
|
||||
{
|
||||
const HtmlColorName* cptr = &ColorNames[i];
|
||||
if (pgm_read_dword(&cptr->Color) == Color)
|
||||
const HtmlColorPair* colorPair = &c_ColorNames[indexName];
|
||||
if (pgm_read_dword(&colorPair->Color) == Color)
|
||||
{
|
||||
PGM_P name = (PGM_P)pgm_read_ptr(&cptr->Name);
|
||||
size_t namelen = strlen_P(name);
|
||||
if (buflen-- > 0)
|
||||
{
|
||||
buflen = min(buflen, namelen);
|
||||
memcpy_P(buf, name, buflen);
|
||||
buf[buflen] = 0;
|
||||
}
|
||||
return namelen;
|
||||
PGM_P name = (PGM_P)pgm_read_ptr(&colorPair->Name);
|
||||
strncpy_P(buf, name, bufSize);
|
||||
return strlen_P(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (buflen-- > 0)
|
||||
// no color name pair match, convert using numerical format
|
||||
return ToNumericalString(buf, bufSize);
|
||||
}
|
||||
|
||||
size_t HtmlColor::ToNumericalString(char* buf, size_t bufSize) const
|
||||
{
|
||||
size_t bufLen = bufSize - 1;
|
||||
|
||||
if (bufLen-- > 0)
|
||||
{
|
||||
if (buflen > 0)
|
||||
if (bufLen > 0)
|
||||
{
|
||||
buf[0] = '#';
|
||||
}
|
||||
|
||||
uint32_t color = Color;
|
||||
for (uint8_t i = 6; i > 0; i--)
|
||||
for (uint8_t indexDigit = 6; indexDigit > 0; indexDigit--)
|
||||
{
|
||||
if (buflen > i)
|
||||
if (bufLen > indexDigit)
|
||||
{
|
||||
buf[i] = hexdigit(color & 0x0000000f);
|
||||
buf[indexDigit] = hexdigit(color & 0x0000000f);
|
||||
}
|
||||
color >>= 4;
|
||||
}
|
||||
buf[min(buflen, 7)] = 0;
|
||||
|
||||
buf[min(bufLen, 7)] = 0;
|
||||
}
|
||||
return 7;
|
||||
}
|
||||
|
@@ -28,20 +28,9 @@ License along with NeoPixel. If not, see
|
||||
#include <Arduino.h>
|
||||
#include "RgbColor.h"
|
||||
|
||||
#if defined(USE_CSS3_COLORS)
|
||||
#define MAX_HTML_COLOR_NAME_LEN 21
|
||||
#else
|
||||
#define MAX_HTML_COLOR_NAME_LEN 8
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// HtmlColor represents an association between a name and a HTML color code
|
||||
// ------------------------------------------------------------------------
|
||||
struct HtmlColorName
|
||||
{
|
||||
PGM_P Name;
|
||||
uint32_t Color;
|
||||
};
|
||||
// Due to Arduino's lack of Project settings for symbols, library code (c,cpp)
|
||||
// files can't react to defines in sketch, so this must be defined here
|
||||
// #define USE_CSS3_COLORS 1
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// HtmlColor represents a color object that is represented by a single uint32
|
||||
@@ -93,7 +82,13 @@ struct HtmlColor
|
||||
// Parse a HTML4/CSS3 color name
|
||||
//
|
||||
// name - the color name
|
||||
// namelen - length of the name string
|
||||
// nameSize - the max size of name to check
|
||||
//
|
||||
// returns - zero if failed, or the number of chars parsed
|
||||
//
|
||||
// It will stop parsing name when a null terminator is reached,
|
||||
// nameSize is reached, no match is found in the name/color pair table, or
|
||||
// a non-alphanumeric is read like seperators or whitespace.
|
||||
//
|
||||
// It accepts all standard HTML4 names and, if USE_CSS3_COLORS macro is
|
||||
// defined, the extended color names defined in CSS3 standard also.
|
||||
@@ -103,27 +98,48 @@ struct HtmlColor
|
||||
//
|
||||
// See https://www.w3.org/TR/css3-color/#SRGB
|
||||
//
|
||||
// Name MUST be stripped of any leading or tailing whitespace.
|
||||
// name must point to the first non-whitespace character to be parsed
|
||||
// parsing will stop at the first non-alpha numeric
|
||||
//
|
||||
// Name MUST NOT be a PROGMEM pointer
|
||||
// ------------------------------------------------------------------------
|
||||
bool Parse(const char* name, size_t namelen);
|
||||
bool Parse(const char* name) { return Parse(name, strlen(name)); }
|
||||
bool Parse(String const &name) { return Parse(name.c_str(), name.length()); }
|
||||
size_t Parse(const char* name, size_t nameSize);
|
||||
|
||||
size_t Parse(const char* name)
|
||||
{
|
||||
return Parse(name, strlen(name) + 1);
|
||||
}
|
||||
|
||||
size_t Parse(String const &name)
|
||||
{
|
||||
return Parse(name.c_str(), name.length() + 1);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Converts this color code to its HTML4/CSS3 name
|
||||
//
|
||||
// buf - array of at least MAX_HTML_COLOR_NAME_LEN chars to store the name
|
||||
// len - actual length of buf array
|
||||
// buf - buffer to write the string
|
||||
// bufSize - actual size of buf array
|
||||
//
|
||||
// It returns the space needed to write the color name not including the
|
||||
// final NUL char.
|
||||
// It returns the number of chars required not including the NUL terminator.
|
||||
//
|
||||
// If there is not enough space in the buffer, it will write as many
|
||||
// characters as allowed and will always finish the buffer with a NUL char
|
||||
// ------------------------------------------------------------------------
|
||||
size_t ToString(char *buf, size_t len) const;
|
||||
size_t ToString(char *buf, size_t bufSize) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Converts this color code to its HTML4/CSS3 numerical name
|
||||
//
|
||||
// buf - buffer to write the string
|
||||
// bufSize - actual size of buf array
|
||||
//
|
||||
// It returns the number of chars required not including the NUL terminator.
|
||||
//
|
||||
// If there is not enough space in the buffer, it will write as many
|
||||
// characters as allowed and will always finish the buffer with a NUL char
|
||||
// ------------------------------------------------------------------------
|
||||
size_t ToNumericalString(char* buf, size_t bufSize) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// BilinearBlend between four colors by the amount defined by 2d variable
|
||||
@@ -151,12 +167,5 @@ struct HtmlColor
|
||||
// 0x0000ff is blue
|
||||
// ------------------------------------------------------------------------
|
||||
uint32_t Color;
|
||||
|
||||
private:
|
||||
// ------------------------------------------------------------------------
|
||||
// Array with all color names and its corresponding color codes
|
||||
// The array ends with a NULL color name.
|
||||
// ------------------------------------------------------------------------
|
||||
static const HtmlColorName ColorNames[] PROGMEM;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user