| 5377 | } |
| 5378 | |
| 5379 | static int stbi__bitcount(unsigned int a) |
| 5380 | { |
| 5381 | a = (a & 0x55555555) + ((a >> 1) & 0x55555555); // max 2 |
| 5382 | a = (a & 0x33333333) + ((a >> 2) & 0x33333333); // max 4 |
| 5383 | a = (a + (a >> 4)) & 0x0f0f0f0f; // max 8 per 4, now 8 bits |
| 5384 | a = (a + (a >> 8)); // max 16 per 8 bits |
| 5385 | a = (a + (a >> 16)); // max 32 per 8 bits |
| 5386 | return a & 0xff; |
| 5387 | } |
| 5388 | |
| 5389 | // extract an arbitrarily-aligned N-bit value (N=bits) |
| 5390 | // from v, and then make it 8-bits long and fractionally |