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 ++++++++++++++++++++++++++---------- src/resources/sdlimagehelper.cpp | 16 ++++++++++++---- src/test/testlauncher.cpp | 7 ------- 3 files changed, 38 insertions(+), 21 deletions(-) (limited to 'src') 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 diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp index 678835edb..7cba9b0dc 100644 --- a/src/resources/sdlimagehelper.cpp +++ b/src/resources/sdlimagehelper.cpp @@ -53,10 +53,18 @@ Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const rgba.BytesPerPixel = 4; rgba.colorkey = 0; rgba.alpha = 255; - rgba.Rmask = 0xFF000000; rgba.Rloss = 0; rgba.Rshift = 24; - rgba.Gmask = 0x00FF0000; rgba.Gloss = 0; rgba.Gshift = 16; - rgba.Bmask = 0x0000FF00; rgba.Bloss = 0; rgba.Bshift = 8; - rgba.Amask = 0x000000FF; rgba.Aloss = 0; rgba.Ashift = 0; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rgba.Rmask = 0x000000FF; + rgba.Gmask = 0x0000FF00; + rgba.Bmask = 0x00FF0000; + rgba.Amask = 0xFF000000; +#else + rgba.Rmask = 0xFF000000; + rgba.Gmask = 0x00FF0000; + rgba.Bmask = 0x0000FF00; + rgba.Amask = 0x000000FF; +#endif SDL_Surface *const surf = SDL_ConvertSurface( tmpImage, &rgba, SDL_SWSURFACE); diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp index 34a126a4e..12f58dcd8 100644 --- a/src/test/testlauncher.cpp +++ b/src/test/testlauncher.cpp @@ -240,21 +240,17 @@ int TestLauncher::testDye() "graphics/sprites/arrow_up.png"); Dye *d = nullptr; - logger->log("test1"); if (rw) { - logger->log("test2"); Image *image = d ? sdlImageHelper->load(rw, *d) : sdlImageHelper->load(rw); if (image) { - logger->log("test3"); const SDL_Rect &rect = image->mBounds; SDL_Surface *surface = sdlImageHelper->create32BitSurface( rect.w, rect.h); if (surface) { - logger->log("test4"); SDL_gfxBlitRGBA(image->mSDLSurface, nullptr, surface, nullptr); ImageWriter::writePNG(image->mSDLSurface, Client::getTempDirectory() + "/testimage1.png"); @@ -262,7 +258,6 @@ int TestLauncher::testDye() Client::getTempDirectory() + "/testimage2.png"); } - logger->log("test5"); rw = PHYSFSRWOPS_openRead( "graphics/sprites/arrow_up.png"); d = new Dye("S:#0000ff,00ff00,5c5cff,ff0000"); @@ -270,12 +265,10 @@ int TestLauncher::testDye() : sdlImageHelper->load(rw); if (image) { - logger->log("test6"); surface = sdlImageHelper->create32BitSurface( rect.w, rect.h); if (surface) { - logger->log("test7"); SDL_gfxBlitRGBA(image->mSDLSurface, nullptr, surface, nullptr); ImageWriter::writePNG(image->mSDLSurface, -- cgit v1.2.3-60-g2f50