From f93aa1c4a5dc334a437ad8bc6c7ffa7a5417d19c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 19 Aug 2013 00:09:48 +0300 Subject: fix dye for big endian system again. --- src/resources/dye.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/resources/dye.cpp') diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index c21a20305..785c15ab9 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -206,12 +206,25 @@ void DyePalette::replaceSColor(uint32_t *pixels, const int bufSize) const if (sz % 2) -- it_end; + int c = 0; for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels) { + c ++; uint8_t *const p = reinterpret_cast(pixels); - const int alpha = *p & 255; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const int alpha = *pixels & 0xff000000; + const unsigned int data = (*pixels) & 0x00ffffff; +#else + const int alpha = *p & 0xff; + const unsigned int data = (*pixels) & 0xffffff00; +#endif +// logger->log("c:%04d %08x", c, *pixels); +// logger->log("data: %08x", data); if (!alpha) + { +// logger->log("skip: %08x", *pixels); continue; + } std::vector::const_iterator it = mColors.begin(); while (it != it_end) @@ -221,16 +234,16 @@ void DyePalette::replaceSColor(uint32_t *pixels, const int bufSize) const const DyeColor &col2 = *it; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (*pixels) & 0x00ffffff; const unsigned int coldata = (col.value[2] << 16) | (col.value[1] << 8) | (col.value[0]); #else - const unsigned int data = (*pixels) & 0xffffff00; const unsigned int coldata = (col.value[2] << 8) | (col.value[1] << 16) | (col.value[0] << 24); #endif +// logger->log("coldata: %08x", coldata); if (data == coldata) { +// logger->log("correct"); p[3] = col2.value[0]; p[2] = col2.value[1]; p[1] = col2.value[2]; @@ -254,6 +267,7 @@ void DyePalette::replaceAColor(uint32_t *pixels, const int bufSize) const for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels) { uint8_t *const p = reinterpret_cast(pixels); + const unsigned int data = *pixels; std::vector::const_iterator it = mColors.begin(); while (it != it_end) @@ -263,11 +277,9 @@ void DyePalette::replaceAColor(uint32_t *pixels, const int bufSize) const const DyeColor &col2 = *it; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = *pixels; const unsigned int coldata = (col.value[3] << 24) | (col.value[2] << 16) | (col.value[1] << 8) | (col.value[0]); #else - const unsigned int data = *pixels; const unsigned int coldata = (col.value[3]) | (col.value[2] << 8) | (col.value[1] << 16) | (col.value[0] << 24); #endif @@ -298,7 +310,14 @@ void DyePalette::replaceSOGLColor(uint32_t *pixels, const int bufSize) const for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels) { uint8_t *const p = reinterpret_cast(pixels); - if (!(*pixels & 0xff000000)) +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const int alpha = *p & 0xff; + const unsigned int data = (*pixels) & 0xffffff00; +#else + const int alpha = *pixels & 0xff000000; + const unsigned int data = (*pixels) & 0x00ffffff; +#endif + if (!alpha) continue; std::vector::const_iterator it = mColors.begin(); @@ -309,11 +328,9 @@ void DyePalette::replaceSOGLColor(uint32_t *pixels, const int bufSize) const const DyeColor &col2 = *it; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (*pixels) & 0xffffff00; const unsigned int coldata = (col.value[0] << 24) | (col.value[1] << 16) | (col.value[2] << 8); #else - const unsigned int data = (*pixels) & 0x00ffffff; const unsigned int coldata = (col.value[0]) | (col.value[1] << 8) | (col.value[2] << 16); #endif @@ -342,6 +359,7 @@ void DyePalette::replaceAOGLColor(uint32_t *pixels, const int bufSize) const for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels) { uint8_t *const p = reinterpret_cast(pixels); + const unsigned int data = *pixels; std::vector::const_iterator it = mColors.begin(); while (it != it_end) @@ -351,11 +369,9 @@ void DyePalette::replaceAOGLColor(uint32_t *pixels, const int bufSize) const const DyeColor &col2 = *it; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = *pixels; const unsigned int coldata = (col.value[0] << 24) | (col.value[1] << 16) | (col.value[2] << 8) | col.value[3]; #else - const unsigned int data = *pixels; const unsigned int coldata = (col.value[0]) | (col.value[1] << 8) | (col.value[2] << 16) | (col.value[3] << 24); #endif -- cgit v1.2.3-60-g2f50