From c86c0832a5908ae6a4c11b9da1747259efc2f9be Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 24 Apr 2015 03:07:28 +0300 Subject: Add CilkPlus support into dyepallete.cpp --- src/resources/dyepalette.cpp | 176 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 1 deletion(-) diff --git a/src/resources/dyepalette.cpp b/src/resources/dyepalette.cpp index f413b468a..9bc5aef7c 100644 --- a/src/resources/dyepalette.cpp +++ b/src/resources/dyepalette.cpp @@ -207,9 +207,58 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels, if (sz % 2) -- it_end; +#ifdef ENABLE_CILKPLUS + cilk_for (int ptr = 0; ptr < bufSize; ptr ++) + { + uint8_t *const p = reinterpret_cast(&pixels[ptr]); +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const int alpha = pixels[ptr] & 0xff000000; + const unsigned int data = pixels[ptr] & 0x00ffffff; +#else + const int alpha = *p & 0xff; + const unsigned int data = pixels[ptr] & 0xffffff00; +#endif +// logger->log("c:%04d %08x", c, *pixels); +// logger->log("data: %08x", data); + if (!alpha) + { +// logger->log("skip: %08x", *pixels); + //continue; + } + else + { + std::vector::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const unsigned int coldata = (col.value[2] << 16U) + | (col.value[1] << 8U) | (col.value[0]); +#else + const unsigned int coldata = (col.value[2] << 8U) + | (col.value[1] << 16U) | (col.value[0] << 24U); +#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]; + break; + } + ++ it; + } + } + } +#else // ENABLE_CILKPLUS + for (uint32_t *p_end = pixels + static_cast(bufSize); pixels != p_end; - ++pixels) + ++ pixels) { uint8_t *const p = reinterpret_cast(pixels); #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -254,6 +303,7 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels, ++ it; } } +#endif // ENABLE_CILKPLUS } void DyePalette::replaceAColor(uint32_t *restrict pixels, @@ -266,6 +316,46 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels, if (sz % 2) -- it_end; +#ifdef ENABLE_CILKPLUS + cilk_for (int ptr = 0; ptr < bufSize; ptr ++) + { + uint8_t *const p = reinterpret_cast(&pixels[ptr]); + const unsigned int data = pixels[ptr]; + + std::vector::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const unsigned int coldata = (col.value[3] << 24U) + | (col.value[2] << 16U) + | (col.value[1] << 8U) + | (col.value[0]); +#else + const unsigned int coldata = (col.value[3]) + | (col.value[2] << 8U) + | (col.value[1] << 16U) | + (col.value[0] << 24U); +#endif + + if (data == coldata) + { + p[3] = col2.value[0]; + p[2] = col2.value[1]; + p[1] = col2.value[2]; + p[0] = col2.value[3]; + break; + } + + ++ it; + } + } + +#else // ENABLE_CILKPLUS + for (uint32_t *p_end = pixels + static_cast(bufSize); pixels != p_end; ++pixels) @@ -304,6 +394,7 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels, ++ it; } } +#endif // ENABLE_CILKPLUS } void DyePalette::replaceSOGLColor(uint32_t *restrict pixels, @@ -316,6 +407,48 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels, if (sz % 2) -- it_end; +#ifdef ENABLE_CILKPLUS + cilk_for (int ptr = 0; ptr < bufSize; ptr ++) + { + uint8_t *const p = reinterpret_cast(&pixels[ptr]); +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const int alpha = *p & 0xff; + const unsigned int data = (pixels[ptr]) & 0xffffff00; +#else + const int alpha = pixels[ptr] & 0xff000000; + const unsigned int data = (pixels[ptr]) & 0x00ffffff; +#endif + if (alpha) + { + std::vector::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const unsigned int coldata = (col.value[0] << 24) + | (col.value[1] << 16) | (col.value[2] << 8); +#else + const unsigned int coldata = (col.value[0]) + | (col.value[1] << 8) | (col.value[2] << 16); +#endif + if (data == coldata) + { + p[0] = col2.value[0]; + p[1] = col2.value[1]; + p[2] = col2.value[2]; + break; + } + + ++ it; + } + } + } + +#else // ENABLE_CILKPLUS + for (uint32_t *p_end = pixels + static_cast(bufSize); pixels != p_end; ++pixels) @@ -356,6 +489,7 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels, ++ it; } } +#endif // ENABLE_CILKPLUS } void DyePalette::replaceAOGLColor(uint32_t *restrict pixels, @@ -368,6 +502,45 @@ void DyePalette::replaceAOGLColor(uint32_t *restrict pixels, if (sz % 2) -- it_end; +#ifdef ENABLE_CILKPLUS + cilk_for (int ptr = 0; ptr < bufSize; ptr ++) + { + uint8_t *const p = reinterpret_cast(&pixels[ptr]); + const unsigned int data = pixels[ptr]; + + std::vector::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const unsigned int coldata = (col.value[0] << 24U) + | (col.value[1] << 16U) + | (col.value[2] << 8U) + | col.value[3]; +#else + const unsigned int coldata = (col.value[0]) + | (col.value[1] << 8U) + | (col.value[2] << 16U) + | (col.value[3] << 24U); +#endif + if (data == coldata) + { + p[0] = col2.value[0]; + p[1] = col2.value[1]; + p[2] = col2.value[2]; + p[3] = col2.value[3]; + break; + } + + ++ it; + } + } + +#else // ENABLE_CILKPLUS + for (uint32_t *p_end = pixels + static_cast(bufSize); pixels != p_end; ++pixels) @@ -405,4 +578,5 @@ void DyePalette::replaceAOGLColor(uint32_t *restrict pixels, ++ it; } } +#endif // ENABLE_CILKPLUS } -- cgit v1.2.3-70-g09d2