From f97a167c445790fb380c2f730c377271e80e0d97 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 4 Aug 2013 00:13:18 +0300 Subject: improve OpenGL A,S dye speed. --- src/resources/dye.cpp | 96 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 33 deletions(-) (limited to 'src/resources/dye.cpp') diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index b3ac8ea46..905f3bcab 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -272,50 +272,80 @@ void DyePalette::replaceAColor(uint32_t *pixels, const int bufSize) const } } -void DyePalette::replaceSOGLColor(uint8_t *const color) const +void DyePalette::replaceSOGLColor(uint32_t *pixels, const int bufSize) const { - std::vector::const_iterator it = mColors.begin(); - const std::vector::const_iterator it_end = mColors.end(); - while (it != it_end) + std::vector::const_iterator it_end = mColors.end(); + const int sz = mColors.size(); + if (!sz) + return; + if (sz % 2) + -- it_end; + + for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels) { - const DyeColor &col = *it; - ++ it; - if (it == it_end) - return; - const DyeColor &col2 = *it; - if (color[0] == col.value[0] && color[1] == col.value[1] - && color[2] == col.value[2]) + uint8_t *const p = reinterpret_cast(pixels); + if (!(*pixels & 0xff000000)) + continue; + + std::vector::const_iterator it = mColors.begin(); + while (it != it_end) { - color[0] = col2.value[0]; - color[1] = col2.value[1]; - color[2] = col2.value[2]; - return; + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + + const unsigned int data = (*pixels) & 0x00ffffff; + const unsigned int coldata = (col.value[0]) + | (col.value[1] << 8) | (col.value[2] << 16); + + if (data == coldata) + { + p[0] = col2.value[0]; + p[1] = col2.value[1]; + p[2] = col2.value[2]; + break; + } + + ++ it; } - ++ it; } } -void DyePalette::replaceAOGLColor(uint8_t *const color) const +void DyePalette::replaceAOGLColor(uint32_t *pixels, const int bufSize) const { - std::vector::const_iterator it = mColors.begin(); - const std::vector::const_iterator it_end = mColors.end(); - while (it != it_end) + std::vector::const_iterator it_end = mColors.end(); + const int sz = mColors.size(); + if (!sz) + return; + if (sz % 2) + -- it_end; + + for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels) { - const DyeColor &col = *it; - ++ it; - if (it == it_end) - return; - const DyeColor &col2 = *it; - if (color[0] == col.value[0] && color[1] == col.value[1] - && color[2] == col.value[2] && color[3] == col.value[3]) + uint8_t *const p = reinterpret_cast(pixels); + + std::vector::const_iterator it = mColors.begin(); + while (it != it_end) { - color[0] = col2.value[0]; - color[1] = col2.value[1]; - color[2] = col2.value[2]; - color[3] = col2.value[3]; - return; + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + + const unsigned int data = *pixels; + const unsigned int coldata = (col.value[0]) | (col.value[1] << 8) + | (col.value[2] << 16) | (col.value[3] << 24); + + 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; } - ++ it; } } -- cgit v1.2.3-70-g09d2