@OPTIMIZE: store non-zigzagged during the decode passes, and only de-zigzag when dequantizing
| 2292 | // @OPTIMIZE: store non-zigzagged during the decode passes, |
| 2293 | // and only de-zigzag when dequantizing |
| 2294 | static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__huffman *hac, stbi__int16 *fac) |
| 2295 | { |
| 2296 | int k; |
| 2297 | if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); |
| 2298 | |
| 2299 | if (j->succ_high == 0) { |
| 2300 | int shift = j->succ_low; |
| 2301 | |
| 2302 | if (j->eob_run) { |
| 2303 | --j->eob_run; |
| 2304 | return 1; |
| 2305 | } |
| 2306 | |
| 2307 | k = j->spec_start; |
| 2308 | do { |
| 2309 | unsigned int zig; |
| 2310 | int c,r,s; |
| 2311 | if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); |
| 2312 | c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); |
| 2313 | r = fac[c]; |
| 2314 | if (r) { // fast-AC path |
| 2315 | k += (r >> 4) & 15; // run |
| 2316 | s = r & 15; // combined length |
| 2317 | if (s > j->code_bits) return stbi__err("bad huffman code", "Combined length longer than code bits available"); |
| 2318 | j->code_buffer <<= s; |
| 2319 | j->code_bits -= s; |
| 2320 | zig = stbi__jpeg_dezigzag[k++]; |
| 2321 | data[zig] = (short) ((r >> 8) * (1 << shift)); |
| 2322 | } else { |
| 2323 | int rs = stbi__jpeg_huff_decode(j, hac); |
| 2324 | if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); |
| 2325 | s = rs & 15; |
| 2326 | r = rs >> 4; |
| 2327 | if (s == 0) { |
| 2328 | if (r < 15) { |
| 2329 | j->eob_run = (1 << r); |
| 2330 | if (r) |
| 2331 | j->eob_run += stbi__jpeg_get_bits(j, r); |
| 2332 | --j->eob_run; |
| 2333 | break; |
| 2334 | } |
| 2335 | k += 16; |
| 2336 | } else { |
| 2337 | k += r; |
| 2338 | zig = stbi__jpeg_dezigzag[k++]; |
| 2339 | data[zig] = (short) (stbi__extend_receive(j,s) * (1 << shift)); |
| 2340 | } |
| 2341 | } |
| 2342 | } while (k <= j->spec_end); |
| 2343 | } else { |
| 2344 | // refinement scan for these AC coefficients |
| 2345 | |
| 2346 | short bit = (short) (1 << j->succ_low); |
| 2347 | |
| 2348 | if (j->eob_run) { |
| 2349 | --j->eob_run; |
| 2350 | for (k = j->spec_start; k <= j->spec_end; ++k) { |
| 2351 | short *p = &data[stbi__jpeg_dezigzag[k]]; |
no test coverage detected