diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-06-03 17:26:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-06-03 17:26:04 +0300 |
commit | 57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534 (patch) | |
tree | 4677cd003c75753536dd90b864959b0982ca42d7 /src | |
parent | a1e8fc08282d11b0132670cf1bfde2b7fe989dc2 (diff) | |
download | manaverse-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.gz manaverse-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.bz2 manaverse-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.xz manaverse-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.zip |
Improve dye speed.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/dye.cpp | 12 | ||||
-rw-r--r-- | src/resources/dye.h | 16 | ||||
-rw-r--r-- | src/resources/image.cpp | 41 |
3 files changed, 46 insertions, 23 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index a4e101ff8..50972c6d6 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -205,7 +205,7 @@ void DyePalette::getColor(double intensity, int color[3]) const color[2] = static_cast<int>(rest * b1 + intensity * b2); } -void DyePalette::replaceColor(int color[3]) const +void DyePalette::replaceColor(Uint8 *color) const { std::vector<Color>::const_iterator it = mColors.begin(); std::vector<Color>::const_iterator it_end = mColors.end(); @@ -219,9 +219,9 @@ void DyePalette::replaceColor(int color[3]) const if (color[0] == col.value[0] && color[1] == col.value[1] && color[2] == col.value[2]) { - color[0] = col2.value[0]; + color[2] = col2.value[0]; color[1] = col2.value[1]; - color[2] = col2.value[2]; + color[0] = col2.value[2]; return; } ++ it; @@ -285,12 +285,6 @@ 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; diff --git a/src/resources/dye.h b/src/resources/dye.h index 34afcf8ed..03aec71cb 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -26,6 +26,8 @@ #include <string> #include <vector> +#include <SDL_stdinc.h> + const int dyePalateSize = 8; /** @@ -59,7 +61,7 @@ class DyePalette */ void getColor(double intensity, int color[3]) const; - void replaceColor(int color[3]) const; + void replaceColor(Uint8 *color) const; private: struct Color @@ -99,6 +101,18 @@ class Dye static void instantiate(std::string &target, const std::string &palettes); + /** + * Check if dye is special dye (S) + */ + bool isSpecialDye() const + { return mDyePalettes[dyePalateSize - 1]; } + + /** + * Return special dye palete (S) + */ + DyePalette *getSPalete() const + { return mDyePalettes[dyePalateSize - 1]; } + private: /** diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 34a2e22b7..da20719ac 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -164,19 +164,34 @@ Resource *Image::load(SDL_RWops *rw, Dye const &dye) SDL_FreeSurface(tmpImage); Uint32 *pixels = static_cast<Uint32 *>(surf->pixels); - for (Uint32 *p_end = pixels + surf->w * surf->h; pixels != p_end; ++pixels) - { - const Uint32 p = *pixels; - - int alpha = p & 255; - if (!alpha) - continue; - int v[3]; - v[0] = (p >> 24) & 255; - v[1] = (p >> 16) & 255; - v[2] = (p >> 8 ) & 255; - dye.update(v); - *pixels = (v[0] << 24) | (v[1] << 16) | (v[2] << 8) | alpha; + DyePalette *pal = dye.getSPalete(); + + if (pal) + { + for (Uint32 *p_end = pixels + surf->w * surf->h; pixels != p_end; ++pixels) + { + Uint8 *p = (Uint8 *)pixels; + const int alpha = *p & 255; + if (!alpha) + continue; + pal->replaceColor(p + 1); + } + } + else + { + for (Uint32 *p_end = pixels + surf->w * surf->h; pixels != p_end; ++pixels) + { + const Uint32 p = *pixels; + const int alpha = p & 255; + if (!alpha) + continue; + int v[3]; + v[0] = (p >> 24) & 255; + v[1] = (p >> 16) & 255; + v[2] = (p >> 8 ) & 255; + dye.update(v); + *pixels = (v[0] << 24) | (v[1] << 16) | (v[2] << 8) | alpha; + } } Image *image = load(surf); |