summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-03 17:26:04 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-03 17:26:04 +0300
commit57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534 (patch)
tree4677cd003c75753536dd90b864959b0982ca42d7
parenta1e8fc08282d11b0132670cf1bfde2b7fe989dc2 (diff)
downloadmv-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.gz
mv-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.bz2
mv-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.xz
mv-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.zip
Improve dye speed.
-rw-r--r--src/resources/dye.cpp12
-rw-r--r--src/resources/dye.h16
-rw-r--r--src/resources/image.cpp41
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);