summaryrefslogtreecommitdiff
path: root/src/resources/dye/dyepalette.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/dye/dyepalette.cpp')
-rw-r--r--src/resources/dye/dyepalette.cpp40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/resources/dye/dyepalette.cpp b/src/resources/dye/dyepalette.cpp
index a290805b6..048b350e3 100644
--- a/src/resources/dye/dyepalette.cpp
+++ b/src/resources/dye/dyepalette.cpp
@@ -51,16 +51,7 @@ DyePalette::DyePalette(const std::string &restrict description,
FOR_EACH (StringVectCIter, it, parts)
{
DyeColor color(0, 0, 0, 0);
- const std::string str = *it;
-
- for (size_t i = 0, colorIdx = 0;
- i < blockSize && colorIdx < 4;
- i += 2, colorIdx ++)
- {
- color.value[colorIdx] = static_cast<unsigned char>((
- hexDecode(str[i]) << 4)
- + hexDecode(str[i + 1]));
- }
+ hexToColor(*it, blockSize, color);
mColors.push_back(color);
}
return;
@@ -69,13 +60,40 @@ DyePalette::DyePalette(const std::string &restrict description,
else if (description[0] == '@')
{
FOR_EACH (StringVectCIter, it, parts)
- mColors.push_back(PaletteDB::getColor(*it));
+ {
+ const std::string str = *it;
+ const DyeColor *const color = PaletteDB::getColor(str);
+ if (color)
+ {
+ mColors.push_back(*color);
+ }
+ else
+ {
+ DyeColor color(0, 0, 0, 0);
+ hexToColor(str, blockSize, color);
+ mColors.push_back(color);
+ }
+ }
return;
}
#endif
logger->log("Error, invalid embedded palette: %s", description.c_str());
}
+void DyePalette::hexToColor(const std::string &hexStr,
+ const int blockSize,
+ DyeColor &color)
+{
+ for (size_t i = 0, colorIdx = 0;
+ i < blockSize && colorIdx < 4;
+ i += 2, colorIdx ++)
+ {
+ color.value[colorIdx] = static_cast<unsigned char>((
+ hexDecode(hexStr[i]) << 4)
+ + hexDecode(hexStr[i + 1]));
+ }
+}
+
unsigned int DyePalette::hexDecode(const signed char c)
{
if ('0' <= c && c <= '9')