From 07e401fb2335d2372a93f37317f144449f7e872b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 16 Jul 2012 18:18:22 +0300 Subject: Add new dye type A. Same as type S for colors + alpha channel. Example: equipment/feet/boots.png|A:#3c3c3cff,40332d40,4d4d4dff,5e4a3d40 here colors in format RRGGBBAA. --- src/resources/sdlimagehelper.cpp | 71 ++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 24 deletions(-) (limited to 'src/resources/sdlimagehelper.cpp') 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(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(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(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(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; } } -- cgit v1.2.3-70-g09d2