| 225 | } |
| 226 | |
| 227 | int 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 | |
| 257 | SDL_Surface *fixsurfaceformat(SDL_Surface *s) |
| 258 | { |
no test coverage detected