decode one 64-entry block--
| 2207 | |
| 2208 | // decode one 64-entry block-- |
| 2209 | static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi__uint16 *dequant) |
| 2210 | { |
| 2211 | int diff,dc,k; |
| 2212 | int t; |
| 2213 | |
| 2214 | if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); |
| 2215 | t = stbi__jpeg_huff_decode(j, hdc); |
| 2216 | if (t < 0 || t > 15) return stbi__err("bad huffman code","Corrupt JPEG"); |
| 2217 | |
| 2218 | // 0 all the ac values now so we can do it 32-bits at a time |
| 2219 | memset(data,0,64*sizeof(data[0])); |
| 2220 | |
| 2221 | diff = t ? stbi__extend_receive(j, t) : 0; |
| 2222 | if (!stbi__addints_valid(j->img_comp[b].dc_pred, diff)) return stbi__err("bad delta","Corrupt JPEG"); |
| 2223 | dc = j->img_comp[b].dc_pred + diff; |
| 2224 | j->img_comp[b].dc_pred = dc; |
| 2225 | if (!stbi__mul2shorts_valid(dc, dequant[0])) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); |
| 2226 | data[0] = (short) (dc * dequant[0]); |
| 2227 | |
| 2228 | // decode AC components, see JPEG spec |
| 2229 | k = 1; |
| 2230 | do { |
| 2231 | unsigned int zig; |
| 2232 | int c,r,s; |
| 2233 | if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); |
| 2234 | c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); |
| 2235 | r = fac[c]; |
| 2236 | if (r) { // fast-AC path |
| 2237 | k += (r >> 4) & 15; // run |
| 2238 | s = r & 15; // combined length |
| 2239 | if (s > j->code_bits) return stbi__err("bad huffman code", "Combined length longer than code bits available"); |
| 2240 | j->code_buffer <<= s; |
| 2241 | j->code_bits -= s; |
| 2242 | // decode into unzigzag'd location |
| 2243 | zig = stbi__jpeg_dezigzag[k++]; |
| 2244 | data[zig] = (short) ((r >> 8) * dequant[zig]); |
| 2245 | } else { |
| 2246 | int rs = stbi__jpeg_huff_decode(j, hac); |
| 2247 | if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); |
| 2248 | s = rs & 15; |
| 2249 | r = rs >> 4; |
| 2250 | if (s == 0) { |
| 2251 | if (rs != 0xf0) break; // end block |
| 2252 | k += 16; |
| 2253 | } else { |
| 2254 | k += r; |
| 2255 | // decode into unzigzag'd location |
| 2256 | zig = stbi__jpeg_dezigzag[k++]; |
| 2257 | data[zig] = (short) (stbi__extend_receive(j,s) * dequant[zig]); |
| 2258 | } |
| 2259 | } |
| 2260 | } while (k < 64); |
| 2261 | return 1; |
| 2262 | } |
| 2263 | |
| 2264 | static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__huffman *hdc, int b) |
| 2265 | { |
no test coverage detected