diff options
Diffstat (limited to 'src/resources/sdlimagehelper.cpp')
-rw-r--r-- | src/resources/sdlimagehelper.cpp | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp index 6c281514e..78094b211 100644 --- a/src/resources/sdlimagehelper.cpp +++ b/src/resources/sdlimagehelper.cpp @@ -66,35 +66,58 @@ Resource *SDLImageHelper::load(SDL_RWops *rw, Dye const &dye) SDL_FreeSurface(tmpImage); uint32_t *pixels = static_cast<uint32_t *>(surf->pixels); - DyePalette *pal = dye.getSPalete(); + int type = dye.getType(); - if (pal) + switch (type) { - for (uint32_t *p_end = pixels + surf->w * surf->h; - pixels != p_end; ++pixels) + case 1: { - uint8_t *p = reinterpret_cast<uint8_t *>(pixels); - const int alpha = *p & 255; - if (!alpha) - continue; - pal->replaceColor(p + 1); + DyePalette *pal = dye.getSPalete(); + if (pal) + { + for (uint32_t *p_end = pixels + surf->w * surf->h; + pixels != p_end; ++pixels) + { + uint8_t *p = reinterpret_cast<uint8_t *>(pixels); + const int alpha = *p & 255; + if (!alpha) + continue; + pal->replaceSColor(p + 1); + } + } + break; } - } - else - { - for (uint32_t *p_end = pixels + surf->w * surf->h; - pixels != p_end; ++pixels) + case 2: { - 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; + DyePalette *pal = dye.getAPalete(); + if (pal) + { + for (uint32_t *p_end = pixels + surf->w * surf->h; + pixels != p_end; ++pixels) + { + pal->replaceAColor(reinterpret_cast<uint8_t *>(pixels)); + } + } + break; + } + 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; + } + break; } } |