diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-13 00:29:08 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-13 00:29:08 +0300 |
commit | 99208e8f8aba695a6fb0e4ed9f5c51108dd539f4 (patch) | |
tree | aa4bbc7dcb656259e94daf907d339d264f1bcaa0 /src/resources/dye/dyepalette.cpp | |
parent | 1cde3ae4001db3e9bd1d233c64b299a65d55b8b4 (diff) | |
download | plus-99208e8f8aba695a6fb0e4ed9f5c51108dd539f4.tar.gz plus-99208e8f8aba695a6fb0e4ed9f5c51108dd539f4.tar.bz2 plus-99208e8f8aba695a6fb0e4ed9f5c51108dd539f4.tar.xz plus-99208e8f8aba695a6fb0e4ed9f5c51108dd539f4.zip |
Add support for hex colors in dye palettes from GIMP file.
Diffstat (limited to 'src/resources/dye/dyepalette.cpp')
-rw-r--r-- | src/resources/dye/dyepalette.cpp | 40 |
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') |