diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-12 03:35:31 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-12 03:35:31 +0300 |
commit | 7ba370f2311ab2e36aa00408e5cfae4c25aa0bca (patch) | |
tree | 8cf2c6c38f0e54ddbf71a3ba95814a096b055c26 /src/resources/dye | |
parent | 12433d426970de3d7785a5b77908f74ed5fd7093 (diff) | |
download | mv-7ba370f2311ab2e36aa00408e5cfae4c25aa0bca.tar.gz mv-7ba370f2311ab2e36aa00408e5cfae4c25aa0bca.tar.bz2 mv-7ba370f2311ab2e36aa00408e5cfae4c25aa0bca.tar.xz mv-7ba370f2311ab2e36aa00408e5cfae4c25aa0bca.zip |
Simplify dyepalette parsing and fix issue with parsing gimp colors in palette.
Diffstat (limited to 'src/resources/dye')
-rw-r--r-- | src/resources/dye/dyepalette.cpp | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/src/resources/dye/dyepalette.cpp b/src/resources/dye/dyepalette.cpp index a35d28437..a290805b6 100644 --- a/src/resources/dye/dyepalette.cpp +++ b/src/resources/dye/dyepalette.cpp @@ -28,6 +28,8 @@ #include "resources/db/palettedb.h" #endif +#include "utils/stringutils.h" + #include <cmath> #include <SDL_endian.h> @@ -42,49 +44,33 @@ DyePalette::DyePalette(const std::string &restrict description, if (size == 0) return; + StringVect parts; + splitToStringVector(parts, description.substr(1), ','); if (description[0] == '#') { - size_t pos = 1; - for ( ; ; ) + FOR_EACH (StringVectCIter, it, parts) { - if (pos + blockSize > size) - break; - DyeColor color(0, 0, 0, 0); + const std::string str = *it; - for (size_t i = 0, colorIdx = 0; i < blockSize && colorIdx < 4; + for (size_t i = 0, colorIdx = 0; + i < blockSize && colorIdx < 4; i += 2, colorIdx ++) { color.value[colorIdx] = static_cast<unsigned char>(( - hexDecode(description[pos + i]) << 4) - + hexDecode(description[pos + i + 1])); + hexDecode(str[i]) << 4) + + hexDecode(str[i + 1])); } mColors.push_back(color); - pos += blockSize; - - if (pos == size) - return; - if (description[pos] != ',') - break; - - ++pos; } + return; } #ifndef DYECMD else if (description[0] == '@') { - size_t pos = 1; - for ( ; pos < size ; ) - { - const size_t idx = description.find(',', pos); - if (idx == std::string::npos) - return; - if (idx == pos) - break; - mColors.push_back(PaletteDB::getColor( - description.substr(pos, idx - pos))); - pos = idx + 1; - } + FOR_EACH (StringVectCIter, it, parts) + mColors.push_back(PaletteDB::getColor(*it)); + return; } #endif logger->log("Error, invalid embedded palette: %s", description.c_str()); |