extract an arbitrarily-aligned N-bit value (N=bits) from v, and then make it 8-bits long and fractionally extend it to full full range.
| 5390 | // from v, and then make it 8-bits long and fractionally |
| 5391 | // extend it to full full range. |
| 5392 | static int stbi__shiftsigned(unsigned int v, int shift, int bits) |
| 5393 | { |
| 5394 | static unsigned int mul_table[9] = { |
| 5395 | 0, |
| 5396 | 0xff/*0b11111111*/, 0x55/*0b01010101*/, 0x49/*0b01001001*/, 0x11/*0b00010001*/, |
| 5397 | 0x21/*0b00100001*/, 0x41/*0b01000001*/, 0x81/*0b10000001*/, 0x01/*0b00000001*/, |
| 5398 | }; |
| 5399 | static unsigned int shift_table[9] = { |
| 5400 | 0, 0,0,1,0,2,4,6,0, |
| 5401 | }; |
| 5402 | if (shift < 0) |
| 5403 | v <<= -shift; |
| 5404 | else |
| 5405 | v >>= shift; |
| 5406 | STBI_ASSERT(v < 256); |
| 5407 | v >>= (8-bits); |
| 5408 | STBI_ASSERT(bits >= 0 && bits <= 8); |
| 5409 | return (int) ((unsigned) v * mul_table[bits]) >> shift_table[bits]; |
| 5410 | } |
| 5411 | |
| 5412 | typedef struct |
| 5413 | { |