summaryrefslogtreecommitdiff
path: root/src/resources/sdlimagehelper.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-16 18:18:22 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-16 18:18:22 +0300
commit07e401fb2335d2372a93f37317f144449f7e872b (patch)
treebe531ab11e3f57705d1167f1f8d693906208b87a /src/resources/sdlimagehelper.cpp
parent7cd117790755de302be9f750b95b5bd18a5636bd (diff)
downloadmanaverse-07e401fb2335d2372a93f37317f144449f7e872b.tar.gz
manaverse-07e401fb2335d2372a93f37317f144449f7e872b.tar.bz2
manaverse-07e401fb2335d2372a93f37317f144449f7e872b.tar.xz
manaverse-07e401fb2335d2372a93f37317f144449f7e872b.zip
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.
Diffstat (limited to 'src/resources/sdlimagehelper.cpp')
-rw-r--r--src/resources/sdlimagehelper.cpp71
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;
}
}