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

Function stbi__build_huffman

lite/example/cpp_example/mge/cv/stb_image.h:2148–2188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2146} stbi__jpeg;
2147
2148static int stbi__build_huffman(stbi__huffman* h, int* count) {
2149 int i, j, k = 0;
2150 unsigned int code;
2151 // build size list for each symbol (from JPEG spec)
2152 for (i = 0; i < 16; ++i)
2153 for (j = 0; j < count[i]; ++j)
2154 h->size[k++] = (stbi_uc)(i + 1);
2155 h->size[k] = 0;
2156
2157 // compute actual symbols (from jpeg spec)
2158 code = 0;
2159 k = 0;
2160 for (j = 1; j <= 16; ++j) {
2161 // compute delta to add to code to compute symbol id
2162 h->delta[j] = k - code;
2163 if (h->size[k] == j) {
2164 while (h->size[k] == j)
2165 h->code[k++] = (stbi__uint16)(code++);
2166 if (code - 1 >= (1u << j))
2167 return stbi__err("bad code lengths", "Corrupt JPEG");
2168 }
2169 // compute largest code + 1 for this size, preshifted as needed later
2170 h->maxcode[j] = code << (16 - j);
2171 code <<= 1;
2172 }
2173 h->maxcode[j] = 0xffffffff;
2174
2175 // build non-spec acceleration table; 255 is flag for not-accelerated
2176 memset(h->fast, 255, 1 << FAST_BITS);
2177 for (i = 0; i < k; ++i) {
2178 int s = h->size[i];
2179 if (s <= FAST_BITS) {
2180 int c = h->code[i] << (FAST_BITS - s);
2181 int m = 1 << (FAST_BITS - s);
2182 for (j = 0; j < m; ++j) {
2183 h->fast[c + j] = (stbi_uc)i;
2184 }
2185 }
2186 }
2187 return 1;
2188}
2189
2190// build a table that decodes both magnitude and value of small ACs in
2191// one go.

Callers 1

stbi__process_markerFunction · 0.85

Calls 1

stbi__errFunction · 0.85

Tested by

no test coverage detected