1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

code review

This commit is contained in:
Laserlicht
2025-05-23 20:26:17 +02:00
parent 263ba46da6
commit 9f937e9791
4 changed files with 16 additions and 44 deletions

View File

@@ -542,8 +542,8 @@ void CSDL_Ext::putPixelWithoutRefreshIfInSurf(SDL_Surface *ekran, const int & x,
CSDL_Ext::putPixelWithoutRefresh(ekran, x, y, R, G, B, A);
}
template<int bpp>
void loopOverPixel(SDL_Surface * surf, const Rect & rect, std::function<void(int &r, int &g, int &b)> func)
template<typename Functor>
void loopOverPixel(SDL_Surface * surf, const Rect & rect, Functor functor)
{
uint8_t * pixels = static_cast<uint8_t*>(surf->pixels);
@@ -556,24 +556,23 @@ void loopOverPixel(SDL_Surface * surf, const Rect & rect, std::function<void(int
for (uint8_t * pixel = pixel_from; pixel < pixel_dest; pixel += surf->format->BytesPerPixel)
{
int r = Channels::px<bpp>::r.get(pixel);
int g = Channels::px<bpp>::g.get(pixel);
int b = Channels::px<bpp>::b.get(pixel);
int r = Channels::px<4>::r.get(pixel);
int g = Channels::px<4>::g.get(pixel);
int b = Channels::px<4>::b.get(pixel);
func(r, g, b);
functor(r, g, b);
Channels::px<bpp>::r.set(pixel, r);
Channels::px<bpp>::g.set(pixel, g);
Channels::px<bpp>::b.set(pixel, b);
Channels::px<4>::r.set(pixel, r);
Channels::px<4>::g.set(pixel, g);
Channels::px<4>::b.set(pixel, b);
}
}
});
}
template<int bpp>
void CSDL_Ext::convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect )
void CSDL_Ext::convertToGrayscale(SDL_Surface * surf, const Rect & rect )
{
loopOverPixel<bpp>(surf, rect, [](int &r, int &g, int &b){
loopOverPixel(surf, rect, [](int &r, int &g, int &b){
int gray = static_cast<int>(0.299 * r + 0.587 * g + 0.114 * b);
r = gray;
g = gray;
@@ -581,19 +580,9 @@ void CSDL_Ext::convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect )
});
}
void CSDL_Ext::convertToGrayscale( SDL_Surface * surf, const Rect & rect )
void CSDL_Ext::convertToH2Scheme(SDL_Surface * surf, const Rect & rect )
{
switch(surf->format->BytesPerPixel)
{
case 3: convertToGrayscaleBpp<3>(surf, rect); break;
case 4: convertToGrayscaleBpp<4>(surf, rect); break;
}
}
template<int bpp>
void CSDL_Ext::convertToH2SchemeBpp(SDL_Surface * surf, const Rect & rect )
{
loopOverPixel<bpp>(surf, rect, [](int &r, int &g, int &b){
loopOverPixel(surf, rect, [](int &r, int &g, int &b){
double gray = 0.3 * r + 0.59 * g + 0.11 * b;
double factor = 2.0;
@@ -608,15 +597,6 @@ void CSDL_Ext::convertToH2SchemeBpp(SDL_Surface * surf, const Rect & rect )
});
}
void CSDL_Ext::convertToH2Scheme( SDL_Surface * surf, const Rect & rect )
{
switch(surf->format->BytesPerPixel)
{
case 3: convertToH2SchemeBpp<3>(surf, rect); break;
case 4: convertToH2SchemeBpp<4>(surf, rect); break;
}
}
void CSDL_Ext::blitSurface(SDL_Surface * src, const Rect & srcRectInput, SDL_Surface * dst, const Point & dstPoint)
{
SDL_Rect srcRect = CSDL_Ext::toSDL(srcRectInput);