summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-16 00:59:25 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-16 00:59:25 +0300
commit7cd117790755de302be9f750b95b5bd18a5636bd (patch)
tree7740d5c4ae3eb4830ae2a56c6a388f7c01a2a964 /src
parent0079782d58f97cf3a931a0d7e23677588834363e (diff)
downloadplus-7cd117790755de302be9f750b95b5bd18a5636bd.tar.gz
plus-7cd117790755de302be9f750b95b5bd18a5636bd.tar.bz2
plus-7cd117790755de302be9f750b95b5bd18a5636bd.tar.xz
plus-7cd117790755de302be9f750b95b5bd18a5636bd.zip
Simplify dye palette parsing.
Diffstat (limited to 'src')
-rw-r--r--src/resources/dye.cpp55
-rw-r--r--src/resources/dye.h2
2 files changed, 23 insertions, 34 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 59d8f18df..954817103 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -31,7 +31,7 @@
DyePalette::DyePalette(const std::string &description)
{
- int size = static_cast<int>(description.length());
+ const int size = static_cast<int>(description.length());
if (size == 0)
return;
if (description[0] != '#')
@@ -46,42 +46,17 @@ DyePalette::DyePalette(const std::string &description)
if (pos + 6 > size)
break;
- int v = 0;
- for (int i = 0; i < 6; ++i)
+ Color color =
{
- char c = description[pos + i];
- int n;
-
- if ('0' <= c && c <= '9')
- {
- n = c - '0';
- }
- else if ('A' <= c && c <= 'F')
- {
- n = c - 'A' + 10;
- }
- else if ('a' <= c && c <= 'f')
- {
- n = c - 'a' + 10;
- }
- else
- {
- logger->log("Error, invalid embedded palette: %s",
- description.c_str());
- return;
- }
+ {0, 0, 0}
+ };
- v = (v << 4) | n;
- }
- Color c =
+ for (int i = 0, colorIdx = 0; i < 6; i +=2, colorIdx ++)
{
- {
- static_cast<unsigned char>(v >> 16),
- static_cast<unsigned char>(v >> 8),
- static_cast<unsigned char>(v)
- }
- };
- mColors.push_back(c);
+ color.value[colorIdx] = (hexDecode(description[pos + i]) << 4)
+ + hexDecode(description[pos + i + 1]);
+ }
+ mColors.push_back(color);
pos += 6;
if (pos == size)
@@ -95,6 +70,18 @@ DyePalette::DyePalette(const std::string &description)
logger->log("Error, invalid embedded palette: %s", description.c_str());
}
+int DyePalette::hexDecode(char c)
+{
+ if ('0' <= c && c <= '9')
+ return c - '0';
+ else if ('A' <= c && c <= 'F')
+ return c - 'A' + 10;
+ else if ('a' <= c && c <= 'f')
+ return c - 'a' + 10;
+ else
+ return 0;
+}
+
/*
void DyePalette::addFirstColor(const int color[3])
{
diff --git a/src/resources/dye.h b/src/resources/dye.h
index 26135d82e..7fe4869ef 100644
--- a/src/resources/dye.h
+++ b/src/resources/dye.h
@@ -65,6 +65,8 @@ class DyePalette
void replaceOGLColor(uint8_t *color) const;
+ int hexDecode(char c);
+
private:
struct Color
{ unsigned char value[3]; };