| 3336 | } |
| 3337 | |
| 3338 | static int stbi__process_marker(stbi__jpeg* z, int m) { |
| 3339 | int L; |
| 3340 | switch (m) { |
| 3341 | case STBI__MARKER_none: // no marker found |
| 3342 | return stbi__err("expected marker", "Corrupt JPEG"); |
| 3343 | |
| 3344 | case 0xDD: // DRI - specify restart interval |
| 3345 | if (stbi__get16be(z->s) != 4) |
| 3346 | return stbi__err("bad DRI len", "Corrupt JPEG"); |
| 3347 | z->restart_interval = stbi__get16be(z->s); |
| 3348 | return 1; |
| 3349 | |
| 3350 | case 0xDB: // DQT - define quantization table |
| 3351 | L = stbi__get16be(z->s) - 2; |
| 3352 | while (L > 0) { |
| 3353 | int q = stbi__get8(z->s); |
| 3354 | int p = q >> 4, sixteen = (p != 0); |
| 3355 | int t = q & 15, i; |
| 3356 | if (p != 0 && p != 1) |
| 3357 | return stbi__err("bad DQT type", "Corrupt JPEG"); |
| 3358 | if (t > 3) |
| 3359 | return stbi__err("bad DQT table", "Corrupt JPEG"); |
| 3360 | |
| 3361 | for (i = 0; i < 64; ++i) |
| 3362 | z->dequant[t][stbi__jpeg_dezigzag[i]] = |
| 3363 | (stbi__uint16)(sixteen ? stbi__get16be(z->s) : stbi__get8(z->s)); |
| 3364 | L -= (sixteen ? 129 : 65); |
| 3365 | } |
| 3366 | return L == 0; |
| 3367 | |
| 3368 | case 0xC4: // DHT - define huffman table |
| 3369 | L = stbi__get16be(z->s) - 2; |
| 3370 | while (L > 0) { |
| 3371 | stbi_uc* v; |
| 3372 | int sizes[16], i, n = 0; |
| 3373 | int q = stbi__get8(z->s); |
| 3374 | int tc = q >> 4; |
| 3375 | int th = q & 15; |
| 3376 | if (tc > 1 || th > 3) |
| 3377 | return stbi__err("bad DHT header", "Corrupt JPEG"); |
| 3378 | for (i = 0; i < 16; ++i) { |
| 3379 | sizes[i] = stbi__get8(z->s); |
| 3380 | n += sizes[i]; |
| 3381 | } |
| 3382 | L -= 17; |
| 3383 | if (tc == 0) { |
| 3384 | if (!stbi__build_huffman(z->huff_dc + th, sizes)) |
| 3385 | return 0; |
| 3386 | v = z->huff_dc[th].values; |
| 3387 | } else { |
| 3388 | if (!stbi__build_huffman(z->huff_ac + th, sizes)) |
| 3389 | return 0; |
| 3390 | v = z->huff_ac[th].values; |
| 3391 | } |
| 3392 | for (i = 0; i < n; ++i) |
| 3393 | v[i] = stbi__get8(z->s); |
| 3394 | if (tc != 0) |
| 3395 | stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th); |
no test coverage detected