From e11249023c8945fb817469b3b4362dcd8c2fd9f0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 9 Mar 2012 03:22:25 +0300 Subject: Add new dye mode S. It simple colors replace dye method. Dye palate should be in format: source1,destination1,source2,destination2 etc --- src/resources/dye.cpp | 38 ++++++++++++++++++++++++++++++++++---- src/resources/dye.h | 14 +++++++++----- 2 files changed, 43 insertions(+), 9 deletions(-) (limited to 'src/resources') diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index eec5916c4..3b2d20054 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -205,9 +205,32 @@ void DyePalette::getColor(double intensity, int color[3]) const color[2] = static_cast(rest * b1 + intensity * b2); } +void DyePalette::replaceColor(int color[3]) const +{ + std::vector::const_iterator it = mColors.begin(); + std::vector::const_iterator it_end = mColors.end(); + while (it != it_end) + { + const Color &col = *it; + ++ it; + if (it == it_end) + return; + const Color &col2 = *it; + if (color[0] == col.value[0] && color[1] == col.value[1] + && color[2] == col.value[2]) + { + color[0] = col2.value[0]; + color[1] = col2.value[1]; + color[2] = col2.value[2]; + return; + } + ++ it; + } +} + Dye::Dye(const std::string &description) { - for (int i = 0; i < 7; ++i) + for (int i = 0; i < dyePalateSize; ++i) mDyePalettes[i] = nullptr; if (description.empty()) @@ -239,6 +262,7 @@ Dye::Dye(const std::string &description) case 'M': i = 4; break; case 'C': i = 5; break; case 'W': i = 6; break; + case 'S': i = 7; break; default: logger->log("Error, invalid dye: %s", description.c_str()); return; @@ -252,7 +276,7 @@ Dye::Dye(const std::string &description) Dye::~Dye() { - for (int i = 0; i < 7; ++i) + for (int i = 0; i < dyePalateSize; ++i) { delete mDyePalettes[i]; mDyePalettes[i] = nullptr; @@ -261,6 +285,12 @@ Dye::~Dye() void Dye::update(int color[3]) const { + if (mDyePalettes[dyePalateSize - 1]) + { + mDyePalettes[dyePalateSize - 1]->replaceColor(color); + return; + } + int cmax = std::max(color[0], std::max(color[1], color[2])); if (cmax == 0) return; @@ -268,8 +298,8 @@ void Dye::update(int color[3]) const int cmin = std::min(color[0], std::min(color[1], color[2])); int intensity = color[0] + color[1] + color[2]; - if (cmin != cmax && - (cmin != 0 || (intensity != cmax && intensity != 2 * cmax))) + if (cmin != cmax && (cmin != 0 || (intensity != cmax + && intensity != 2 * cmax))) { // not pure return; diff --git a/src/resources/dye.h b/src/resources/dye.h index 94bee3b58..34afcf8ed 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -26,6 +26,8 @@ #include #include +const int dyePalateSize = 8; + /** * Class for performing a linear interpolation between colors. */ @@ -57,11 +59,13 @@ class DyePalette */ void getColor(double intensity, int color[3]) const; - private: + void replaceColor(int color[3]) const; - struct Color { unsigned char value[3]; }; + private: + struct Color + { unsigned char value[3]; }; - std::vector< Color > mColors; + std::vector mColors; }; /** @@ -100,9 +104,9 @@ class Dye /** * The order of the palettes, as well as their uppercase letter, is: * - * Red, Green, Yellow, Blue, Magenta, White (or rather gray). + * Red, Green, Yellow, Blue, Magenta, White (or rather gray), Simple. */ - DyePalette *mDyePalettes[7]; + DyePalette *mDyePalettes[dyePalateSize]; }; #endif -- cgit v1.2.3-70-g09d2