From 23d03762194a8c91f509f06dc420c78d22c42cd7 Mon Sep 17 00:00:00 2001 From: Rafael Barreto Date: Tue, 22 Jun 2010 14:23:16 +0000 Subject: [PATCH] brightskin blocker fix git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5211 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/texture.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/source/src/texture.cpp b/source/src/texture.cpp index d46b20af..8654efeb 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -211,13 +211,14 @@ bool checkgrayscale(SDL_Surface *s) return true; } -void fixcolor(SDL_Surface *s) +bool fixcolor(SDL_Surface *s, bool check = false, Uint8 mlimit = 255) { Uint32 pixel = 0; + int bpp = s->format->BytesPerPixel; + long R = 0, G = 0, B = 0; loopi(s->w) { - loopj(s->h) { - int bpp = s->format->BytesPerPixel; - Uint8 *p = (Uint8 *)s->pixels + j * s->pitch + i * bpp; + loopj(s->h * bpp) { + Uint8 *p = (Uint8 *)s->pixels + j * s->w + i; switch (bpp) { case 1: pixel = *p; break; case 2: pixel = *(Uint16 *)p; break; @@ -232,12 +233,18 @@ void fixcolor(SDL_Surface *s) } Uint8 r = 0, g = 0, b = 0, a = 0; SDL_GetRGBA(pixel, s->format, &r, &g, &b, &a); -#define UMIN(x) x>128?128:x - r = UMIN(r); g = UMIN(g); b = UMIN(b); // FIXME -#undef UMIN - *p = SDL_MapRGBA(s->format, r,g,b,a); + if ( !check ) { + r >>= 1; g >>= 1; b >>= 1; + *p = SDL_MapRGBA(s->format, r,g,b,a); + } + else { + R += r; G += g; B += b; + } } } + int N = s->w * s->h * bpp; + if ( R > mlimit * N || G > mlimit * N || B > mlimit * N ) return true; + return false; } SDL_Surface *fixsurfaceformat(SDL_Surface *s) @@ -318,9 +325,8 @@ GLuint loadsurface(const char *texname, int &xs, int &ys, int &bpp, int clamp = if(!s) s = IMG_Load(findfile(file, "rb")); if(!s) { conoutf("couldn't load texture %s", texname); return 0; } s = fixsurfaceformat(s); - if ( strstr(texname,"playermodel") || - ( strstr(texname,"textures") && !strstr(texname,"skymaps") ) || - ( strstr(texname,"skin") && strstr(texname,"weapon") ) ) fixcolor(s); + if ( strstr(texname,"playermodel") && fixcolor(s,true,25) ) fixcolor(s); + else if ( strstr(texname,"skin") && strstr(texname,"weapon") && fixcolor(s,true,50) ) fixcolor(s); GLenum format = texformat(s->format->BitsPerPixel); if(!format)