MCPcopy Index your code
hub / github.com/assaultcube/AC / fixcl

Function fixcl

source/src/texture.cpp:227–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227int fixcl(SDL_Surface *s, int threshold)
228{
229 if(!s || !s->h || !s->w) return 0;
230 int sum = 0, w, a0 = *((uchar *) &s->format->Amask) ? 1 : 0;
231 if(s->format->palette || s->format->BytesPerPixel < 3) s = (SDL_Surface *)s->pixels;
232 for(int y = 0; y < s->h; y++)
233 {
234 uchar *pix = ((uchar *)s->pixels) + y * s->pitch + a0;
235 w = 0;
236 for(int x = 0; x < s->w; x++)
237 {
238 w += iabs(((pix[0] * pix[0]) | (pix[1] * pix[1]) | (pix[2] * pix[2])) - ((pix[0] * pix[1] * pix[2]) / 222));
239 pix += s->format->BytesPerPixel;
240 }
241 sum += w / s->w;
242 }
243 sum = sqrtf(sum / s->h);
244 int t = sum / threshold + 1;
245 if(t > 1) for(int y = 0; y < s->h; y++)
246 {
247 uchar *pix = ((uchar *)s->pixels) + y * s->pitch + a0;
248 for(int x = 0; x < s->w; x++)
249 {
250 loopi(3) pix[i] /= t;
251 pix += s->format->BytesPerPixel;
252 }
253 }
254 return t;
255}
256
257SDL_Surface *fixsurfaceformat(SDL_Surface *s)
258{

Callers 1

loadsurfaceFunction · 0.85

Calls 2

iabsFunction · 0.85
loopiFunction · 0.70

Tested by

no test coverage detected