MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__shiftsigned

Function stbi__shiftsigned

Source/Utils/stb_image.h:5392–5410  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

5390// from v, and then make it 8-bits long and fractionally
5391// extend it to full full range.
5392static 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
5412typedef struct
5413{

Callers 1

stbi__bmp_loadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected