summaryrefslogtreecommitdiff
path: root/src/resources/image.cpp
diff options
context:
space:
mode:
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);