diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-20 23:00:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-20 23:05:09 +0300 |
commit | 52f78717dae3cb02eb1539841dd2a6bd351f74c1 (patch) | |
tree | 78b6bb12fcbb5e1624a76531ef43a25d263b3c79 /src/resources/dye.cpp | |
parent | e50c6b9fbcd7713b990012f17665efeb2a284dd2 (diff) | |
download | mv-52f78717dae3cb02eb1539841dd2a6bd351f74c1.tar.gz mv-52f78717dae3cb02eb1539841dd2a6bd351f74c1.tar.bz2 mv-52f78717dae3cb02eb1539841dd2a6bd351f74c1.tar.xz mv-52f78717dae3cb02eb1539841dd2a6bd351f74c1.zip |
add support for GIMP palettes for dye colors.
Palette file must be named palette.gpl and contain
colors with correct names.
To use it in dye string can be used character @.
Example:
<color id="2" name="black" value="@Untitled7,Untitled8,Untitled6"/>
in all dye string it not tested.
Diffstat (limited to 'src/resources/dye.cpp')
-rw-r--r-- | src/resources/dye.cpp | 100 |
1 files changed, 56 insertions, 44 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 960ac36ae..9997fc6ae 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -24,6 +24,8 @@ #include "logger.h" +#include "resources/palettedb.h" + #include <math.h> #include <sstream> @@ -33,42 +35,52 @@ DyePalette::DyePalette(const std::string &description, const int8_t blockSize) : mColors() { - const int size = static_cast<int>(description.length()); + const size_t size = static_cast<int>(description.length()); if (size == 0) return; - if (description[0] != '#') - { - // TODO: load palette from file. - return; - } - int pos = 1; - for ( ; ; ) + if (description[0] == '#') { - if (pos + blockSize > size) - break; - - Color color = + size_t pos = 1; + for ( ; ; ) { - {0, 0, 0, 0} - }; + if (pos + blockSize > size) + break; - for (int 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])); - } - mColors.push_back(color); - pos += blockSize; + DyeColor color(0, 0, 0, 0); - if (pos == size) - return; - if (description[pos] != ',') - break; + for (int 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])); + } + mColors.push_back(color); + pos += blockSize; - ++pos; + if (pos == size) + return; + if (description[pos] != ',') + break; + + ++pos; + } + } + 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; + } } logger->log("Error, invalid embedded palette: %s", description.c_str()); @@ -185,15 +197,15 @@ void DyePalette::getColor(double intensity, int color[3]) const void DyePalette::replaceSColor(uint8_t *const color) const { - std::vector<Color>::const_iterator it = mColors.begin(); - const std::vector<Color>::const_iterator it_end = mColors.end(); + std::vector<DyeColor>::const_iterator it = mColors.begin(); + const std::vector<DyeColor>::const_iterator it_end = mColors.end(); while (it != it_end) { - const Color &col = *it; + const DyeColor &col = *it; ++ it; if (it == it_end) return; - const Color &col2 = *it; + const DyeColor &col2 = *it; if (color[0] == col.value[0] && color[1] == col.value[1] && color[2] == col.value[2]) { @@ -208,15 +220,15 @@ void DyePalette::replaceSColor(uint8_t *const color) const void DyePalette::replaceAColor(uint8_t *const color) const { - std::vector<Color>::const_iterator it = mColors.begin(); - const std::vector<Color>::const_iterator it_end = mColors.end(); + std::vector<DyeColor>::const_iterator it = mColors.begin(); + const std::vector<DyeColor>::const_iterator it_end = mColors.end(); while (it != it_end) { - const Color &col = *it; + const DyeColor &col = *it; ++ it; if (it == it_end) return; - const Color &col2 = *it; + const DyeColor &col2 = *it; if (color[1] == col.value[0] && color[2] == col.value[1] && color[3] == col.value[2] && color[0] == col.value[3]) { @@ -232,15 +244,15 @@ void DyePalette::replaceAColor(uint8_t *const color) const void DyePalette::replaceSOGLColor(uint8_t *const color) const { - std::vector<Color>::const_iterator it = mColors.begin(); - const std::vector<Color>::const_iterator it_end = mColors.end(); + std::vector<DyeColor>::const_iterator it = mColors.begin(); + const std::vector<DyeColor>::const_iterator it_end = mColors.end(); while (it != it_end) { - const Color &col = *it; + const DyeColor &col = *it; ++ it; if (it == it_end) return; - const Color &col2 = *it; + const DyeColor &col2 = *it; if (color[2] == col.value[0] && color[1] == col.value[1] && color[0] == col.value[2]) { @@ -255,15 +267,15 @@ void DyePalette::replaceSOGLColor(uint8_t *const color) const void DyePalette::replaceAOGLColor(uint8_t *const color) const { - std::vector<Color>::const_iterator it = mColors.begin(); - const std::vector<Color>::const_iterator it_end = mColors.end(); + std::vector<DyeColor>::const_iterator it = mColors.begin(); + const std::vector<DyeColor>::const_iterator it_end = mColors.end(); while (it != it_end) { - const Color &col = *it; + const DyeColor &col = *it; ++ it; if (it == it_end) return; - const Color &col2 = *it; + const DyeColor &col2 = *it; if (color[2] == col.value[0] && color[1] == col.value[1] && color[0] == col.value[2] && color[3] == col.value[3]) { |