diff options
Diffstat (limited to 'src/XPM.cxx')
-rw-r--r-- | src/XPM.cxx | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/XPM.cxx b/src/XPM.cxx index 0d57873ac..b2cb6776a 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -21,7 +21,9 @@ using namespace Scintilla; -static const char *NextField(const char *s) { +namespace { + +const char *NextField(const char *s) { // In case there are leading spaces in the string while (*s == ' ') { s++; @@ -36,13 +38,34 @@ static const char *NextField(const char *s) { } // Data lines in XPM can be terminated either with NUL or " -static size_t MeasureLength(const char *s) { +size_t MeasureLength(const char *s) { size_t i = 0; while (s[i] && (s[i] != '\"')) i++; return i; } +unsigned int ValueOfHex(const char ch) noexcept { + if (ch >= '0' && ch <= '9') + return ch - '0'; + else if (ch >= 'A' && ch <= 'F') + return ch - 'A' + 10; + else if (ch >= 'a' && ch <= 'f') + return ch - 'a' + 10; + else + return 0; +} + +ColourDesired ColourFromHex(const char *val) noexcept { + unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]); + unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]); + unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]); + return ColourDesired(r, g, b); +} + +} + + ColourDesired XPM::ColourFromCode(int ch) const { return colourCodeTable[ch]; } @@ -109,7 +132,7 @@ void XPM::Init(const char *const *linesForm) { colourDef += 4; ColourDesired colour(0xff, 0xff, 0xff); if (*colourDef == '#') { - colour.Set(colourDef); + colour = ColourFromHex(colourDef+1); } else { codeTransparent = code; } |