From 52f78717dae3cb02eb1539841dd2a6bd351f74c1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 20 Apr 2013 23:00:42 +0300 Subject: 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: in all dye string it not tested. --- src/resources/dye.cpp | 100 ++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 44 deletions(-) (limited to 'src/resources/dye.cpp') 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 #include @@ -33,42 +35,52 @@ DyePalette::DyePalette(const std::string &description, const int8_t blockSize) : mColors() { - const int size = static_cast(description.length()); + const size_t size = static_cast(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(( - 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(( + 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::const_iterator it = mColors.begin(); - const std::vector::const_iterator it_end = mColors.end(); + std::vector::const_iterator it = mColors.begin(); + const std::vector::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::const_iterator it = mColors.begin(); - const std::vector::const_iterator it_end = mColors.end(); + std::vector::const_iterator it = mColors.begin(); + const std::vector::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::const_iterator it = mColors.begin(); - const std::vector::const_iterator it_end = mColors.end(); + std::vector::const_iterator it = mColors.begin(); + const std::vector::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::const_iterator it = mColors.begin(); - const std::vector::const_iterator it_end = mColors.end(); + std::vector::const_iterator it = mColors.begin(); + const std::vector::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]) { -- cgit v1.2.3-70-g09d2