summaryrefslogtreecommitdiff
path: root/src/resources/image.cpp
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 /src/resources/image.cpp
parenta1e8fc08282d11b0132670cf1bfde2b7fe989dc2 (diff)
downloadplus-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.gz
plus-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.bz2
plus-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.tar.xz
plus-57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534.zip
Improve dye speed.
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r--src/resources/image.cpp41
1 files changed, 28 insertions, 13 deletions
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);