| 2262 | } |
| 2263 | |
| 2264 | static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__huffman *hdc, int b) |
| 2265 | { |
| 2266 | int diff,dc; |
| 2267 | int t; |
| 2268 | if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); |
| 2269 | |
| 2270 | if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); |
| 2271 | |
| 2272 | if (j->succ_high == 0) { |
| 2273 | // first scan for DC coefficient, must be first |
| 2274 | memset(data,0,64*sizeof(data[0])); // 0 all the ac values now |
| 2275 | t = stbi__jpeg_huff_decode(j, hdc); |
| 2276 | if (t < 0 || t > 15) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); |
| 2277 | diff = t ? stbi__extend_receive(j, t) : 0; |
| 2278 | |
| 2279 | if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff)) return stbi__err("bad delta", "Corrupt JPEG"); |
| 2280 | dc = j->img_comp[b].dc_pred + diff; |
| 2281 | j->img_comp[b].dc_pred = dc; |
| 2282 | if (!stbi__mul2shorts_valid(dc, 1 << j->succ_low)) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); |
| 2283 | data[0] = (short) (dc * (1 << j->succ_low)); |
| 2284 | } else { |
| 2285 | // refinement scan for DC coefficient |
| 2286 | if (stbi__jpeg_get_bit(j)) |
| 2287 | data[0] += (short) (1 << j->succ_low); |
| 2288 | } |
| 2289 | return 1; |
| 2290 | } |
| 2291 | |
| 2292 | // @OPTIMIZE: store non-zigzagged during the decode passes, |
| 2293 | // and only de-zigzag when dequantizing |
no test coverage detected