diff --git a/client/renderSDL/SDL_Extensions.cpp b/client/renderSDL/SDL_Extensions.cpp index 33c36e21e..406b7f5c7 100644 --- a/client/renderSDL/SDL_Extensions.cpp +++ b/client/renderSDL/SDL_Extensions.cpp @@ -543,7 +543,7 @@ void CSDL_Ext::putPixelWithoutRefreshIfInSurf(SDL_Surface *ekran, const int & x, } template -void CSDL_Ext::convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect ) +void loopOverPixel(SDL_Surface * surf, const Rect & rect, std::function func) { uint8_t * pixels = static_cast(surf->pixels); @@ -560,16 +560,27 @@ void CSDL_Ext::convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect ) int g = Channels::px::g.get(pixel); int b = Channels::px::b.get(pixel); - int gray = static_cast(0.299 * r + 0.587 * g + 0.114 *b); + func(r, g, b); - Channels::px::r.set(pixel, gray); - Channels::px::g.set(pixel, gray); - Channels::px::b.set(pixel, gray); + Channels::px::r.set(pixel, r); + Channels::px::g.set(pixel, g); + Channels::px::b.set(pixel, b); } } }); } +template +void CSDL_Ext::convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect ) +{ + loopOverPixel(surf, rect, [](int &r, int &g, int &b){ + int gray = static_cast(0.299 * r + 0.587 * g + 0.114 * b); + r = gray; + g = gray; + b = gray; + }); +} + void CSDL_Ext::convertToGrayscale( SDL_Surface * surf, const Rect & rect ) { switch(surf->format->BytesPerPixel) @@ -582,38 +593,18 @@ void CSDL_Ext::convertToGrayscale( SDL_Surface * surf, const Rect & rect ) template void CSDL_Ext::convertToH2SchemeBpp(SDL_Surface * surf, const Rect & rect ) { - uint8_t * pixels = static_cast(surf->pixels); + loopOverPixel(surf, rect, [](int &r, int &g, int &b){ + double gray = 0.3 * r + 0.59 * g + 0.11 * b; + double factor = 2.0; - tbb::parallel_for(tbb::blocked_range(rect.top(), rect.bottom()), [&](const tbb::blocked_range& r) - { - for(int yp = r.begin(); yp != r.end(); ++yp) - { - uint8_t * pixel_from = pixels + yp * surf->pitch + rect.left() * surf->format->BytesPerPixel; - uint8_t * pixel_dest = pixels + yp * surf->pitch + rect.right() * surf->format->BytesPerPixel; + //fast approximation instead of colorspace conversion + r = static_cast(gray + (r - gray) * factor); + g = static_cast(gray + (g - gray) * factor); + b = static_cast(gray + (b - gray) * factor); - for (uint8_t * pixel = pixel_from; pixel < pixel_dest; pixel += surf->format->BytesPerPixel) - { - int r = Channels::px::r.get(pixel); - int g = Channels::px::g.get(pixel); - int b = Channels::px::b.get(pixel); - - double gray = 0.3 * r + 0.59 * g + 0.11 * b; - double factor = 2.0; - - //fast approximation instead of colorspace conversion - r = static_cast(gray + (r - gray) * factor); - g = static_cast(gray + (g - gray) * factor); - b = static_cast(gray + (b - gray) * factor); - - r = std::clamp(r, 0, 255); - g = std::clamp(g, 0, 255); - b = std::clamp(b, 0, 255); - - Channels::px::r.set(pixel, r); - Channels::px::g.set(pixel, g); - Channels::px::b.set(pixel, b); - } - } + r = std::clamp(r, 0, 255); + g = std::clamp(g, 0, 255); + b = std::clamp(b, 0, 255); }); }