summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-19 22:17:05 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-19 22:17:55 +0300
commitfe9994c45c1e464125186ae14e482ae155d9ec53 (patch)
tree0eef772d50979f869138a80a8ca983de4e5da900 /src/resources
parent582900e6c698823fc95bc6653707a328e96dd075 (diff)
downloadplus-fe9994c45c1e464125186ae14e482ae155d9ec53.tar.gz
plus-fe9994c45c1e464125186ae14e482ae155d9ec53.tar.bz2
plus-fe9994c45c1e464125186ae14e482ae155d9ec53.tar.xz
plus-fe9994c45c1e464125186ae14e482ae155d9ec53.zip
improve a bit normal dye code.
move dye code to methods.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/dye.cpp99
-rw-r--r--src/resources/dye.h9
-rw-r--r--src/resources/openglimagehelper.cpp15
-rw-r--r--src/resources/sdlimagehelper.cpp15
4 files changed, 82 insertions, 56 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 785c15ab9..e57f4afe2 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -446,29 +446,6 @@ Dye::~Dye()
}
}
-void Dye::update(int color[3]) const
-{
- const int cmax = std::max(color[0], std::max(color[1], color[2]));
- if (cmax == 0)
- return;
-
- const int cmin = std::min(color[0], std::min(color[1], color[2]));
- const int intensity = color[0] + color[1] + color[2];
-
- if (cmin != cmax && (cmin != 0 || (intensity != cmax
- && intensity != 2 * cmax)))
- {
- // not pure
- return;
- }
-
- const int i = (color[0] != 0) | ((color[1] != 0) << 1)
- | ((color[2] != 0) << 2);
-
- if (mDyePalettes[i - 1])
- mDyePalettes[i - 1]->getColor(cmax, color);
-}
-
void Dye::instantiate(std::string &target, const std::string &palettes)
{
size_t next_pos = target.find('|');
@@ -527,3 +504,79 @@ int Dye::getType() const
return 2;
return 0;
}
+
+void Dye::normalDye(uint32_t *pixels, const int bufSize) const
+{
+ for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++ pixels)
+ {
+ const uint32_t p = *pixels;
+ const int alpha = p & 255;
+ if (!alpha)
+ continue;
+ int color[3];
+ color[0] = (p >> 24) & 255;
+ color[1] = (p >> 16) & 255;
+ color[2] = (p >> 8) & 255;
+
+ const int cmax = std::max(color[0], std::max(color[1], color[2]));
+ if (cmax == 0)
+ continue;
+
+ const int cmin = std::min(color[0], std::min(color[1], color[2]));
+ const int intensity = color[0] + color[1] + color[2];
+
+ if (cmin != cmax && (cmin != 0 || (intensity != cmax
+ && intensity != 2 * cmax)))
+ {
+ // not pure
+ continue;
+ }
+
+ const int i = (color[0] != 0) | ((color[1] != 0) << 1)
+ | ((color[2] != 0) << 2);
+
+ if (mDyePalettes[i - 1])
+ mDyePalettes[i - 1]->getColor(cmax, color);
+
+ *pixels = (color[0] << 24) | (color[1] << 16)
+ | (color[2] << 8) | alpha;
+ }
+}
+
+void Dye::normalOGLDye(uint32_t *pixels, const int bufSize) const
+{
+ for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++ pixels)
+ {
+ const uint32_t p = *pixels;
+ const int alpha = (p >> 24) & 255;
+ if (!alpha)
+ continue;
+ int color[3];
+ color[0] = (p) & 255;
+ color[1] = (p >> 8) & 255;
+ color[2] = (p >> 16) & 255;
+
+ const int cmax = std::max(color[0], std::max(color[1], color[2]));
+ if (cmax == 0)
+ continue;
+
+ const int cmin = std::min(color[0], std::min(color[1], color[2]));
+ const int intensity = color[0] + color[1] + color[2];
+
+ if (cmin != cmax && (cmin != 0 || (intensity != cmax
+ && intensity != 2 * cmax)))
+ {
+ // not pure
+ continue;
+ }
+
+ const int i = (color[0] != 0) | ((color[1] != 0) << 1)
+ | ((color[2] != 0) << 2);
+
+ if (mDyePalettes[i - 1])
+ mDyePalettes[i - 1]->getColor(cmax, color);
+
+ *pixels = (color[0]) | (color[1] << 8)
+ | (color[2] << 16) | (alpha << 24);
+ }
+}
diff --git a/src/resources/dye.h b/src/resources/dye.h
index e8b4ae94e..ba0b378d0 100644
--- a/src/resources/dye.h
+++ b/src/resources/dye.h
@@ -108,11 +108,6 @@ class Dye final
~Dye();
/**
- * Modifies a pixel color.
- */
- void update(int color[3]) const;
-
- /**
* Fills the blank in a dye placeholder with some palette names.
*/
static void instantiate(std::string &target,
@@ -135,6 +130,10 @@ class Dye final
*/
int getType() const A_WARN_UNUSED;
+ void normalDye(uint32_t *pixels, const int bufSize) const;
+
+ void normalOGLDye(uint32_t *pixels, const int bufSize) const;
+
private:
/**
* The order of the palettes, as well as their uppercase letter, is:
diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp
index d392fead1..1180135a0 100644
--- a/src/resources/openglimagehelper.cpp
+++ b/src/resources/openglimagehelper.cpp
@@ -85,20 +85,7 @@ Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const
case 0:
default:
{
- for (uint32_t *p_end = pixels + surf->w * surf->h;
- pixels != p_end; ++pixels)
- {
- const uint32_t p = *pixels;
- const int alpha = (p >> 24) & 255;
- if (!alpha)
- continue;
- int v[3];
- v[0] = (p) & 255;
- v[1] = (p >> 8) & 255;
- v[2] = (p >> 16) & 255;
- dye.update(v);
- *pixels = (v[0]) | (v[1] << 8) | (v[2] << 16) | (alpha << 24);
- }
+ dye.normalOGLDye(pixels, surf->w * surf->h);
break;
}
}
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp
index 7cba9b0dc..ab0b0663b 100644
--- a/src/resources/sdlimagehelper.cpp
+++ b/src/resources/sdlimagehelper.cpp
@@ -92,20 +92,7 @@ Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const
case 0:
default:
{
- for (uint32_t *p_end = pixels + surf->w * surf->h;
- pixels != p_end; ++pixels)
- {
- const uint32_t 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;
- }
+ dye.normalDye(pixels, surf->w * surf->h);
break;
}
}