build a table that decodes both magnitude and value of small ACs in one go.
| 2047 | // build a table that decodes both magnitude and value of small ACs in |
| 2048 | // one go. |
| 2049 | static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h) |
| 2050 | { |
| 2051 | int i; |
| 2052 | for (i=0; i < (1 << FAST_BITS); ++i) { |
| 2053 | stbi_uc fast = h->fast[i]; |
| 2054 | fast_ac[i] = 0; |
| 2055 | if (fast < 255) { |
| 2056 | int rs = h->values[fast]; |
| 2057 | int run = (rs >> 4) & 15; |
| 2058 | int magbits = rs & 15; |
| 2059 | int len = h->size[fast]; |
| 2060 | |
| 2061 | if (magbits && len + magbits <= FAST_BITS) { |
| 2062 | // magnitude code followed by receive_extend code |
| 2063 | int k = ((i << len) & ((1 << FAST_BITS) - 1)) >> (FAST_BITS - magbits); |
| 2064 | int m = 1 << (magbits - 1); |
| 2065 | if (k < m) k += (~0U << magbits) + 1; |
| 2066 | // if the result is small enough, we can fit it in fast_ac table |
| 2067 | if (k >= -128 && k <= 127) |
| 2068 | fast_ac[i] = (stbi__int16) ((k * 256) + (run * 16) + (len + magbits)); |
| 2069 | } |
| 2070 | } |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | static void stbi__grow_buffer_unsafe(stbi__jpeg *j) |
| 2075 | { |
no outgoing calls
no test coverage detected