MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / stbi__shiftsigned

Function stbi__shiftsigned

lite/example/cpp_example/mge/cv/stb_image.h:5944–5967  ·  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

5942// from v, and then make it 8-bits long and fractionally
5943// extend it to full full range.
5944static int stbi__shiftsigned(unsigned int v, int shift, int bits) {
5945 static unsigned int mul_table[9] = {
5946 0,
5947 0xff /*0b11111111*/,
5948 0x55 /*0b01010101*/,
5949 0x49 /*0b01001001*/,
5950 0x11 /*0b00010001*/,
5951 0x21 /*0b00100001*/,
5952 0x41 /*0b01000001*/,
5953 0x81 /*0b10000001*/,
5954 0x01 /*0b00000001*/,
5955 };
5956 static unsigned int shift_table[9] = {
5957 0, 0, 0, 1, 0, 2, 4, 6, 0,
5958 };
5959 if (shift < 0)
5960 v <<= -shift;
5961 else
5962 v >>= shift;
5963 STBI_ASSERT(v < 256);
5964 v >>= (8 - bits);
5965 STBI_ASSERT(bits >= 0 && bits <= 8);
5966 return (int)((unsigned)v * mul_table[bits]) >> shift_table[bits];
5967}
5968
5969typedef struct {
5970 int bpp, offset, hsz;

Callers 1

stbi__bmp_loadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected