| 3650 | #define stbi__SOF_progressive(x) ((x) == 0xc2) |
| 3651 | |
| 3652 | static int stbi__decode_jpeg_header(stbi__jpeg* z, int scan) { |
| 3653 | int m; |
| 3654 | z->jfif = 0; |
| 3655 | z->app14_color_transform = -1; // valid values are 0,1,2 |
| 3656 | z->marker = STBI__MARKER_none; // initialize cached marker to empty |
| 3657 | m = stbi__get_marker(z); |
| 3658 | if (!stbi__SOI(m)) |
| 3659 | return stbi__err("no SOI", "Corrupt JPEG"); |
| 3660 | if (scan == STBI__SCAN_type) |
| 3661 | return 1; |
| 3662 | m = stbi__get_marker(z); |
| 3663 | while (!stbi__SOF(m)) { |
| 3664 | if (!stbi__process_marker(z, m)) |
| 3665 | return 0; |
| 3666 | m = stbi__get_marker(z); |
| 3667 | while (m == STBI__MARKER_none) { |
| 3668 | // some files have extra padding after their blocks, so ok, we'll scan |
| 3669 | if (stbi__at_eof(z->s)) |
| 3670 | return stbi__err("no SOF", "Corrupt JPEG"); |
| 3671 | m = stbi__get_marker(z); |
| 3672 | } |
| 3673 | } |
| 3674 | z->progressive = stbi__SOF_progressive(m); |
| 3675 | if (!stbi__process_frame_header(z, scan)) |
| 3676 | return 0; |
| 3677 | return 1; |
| 3678 | } |
| 3679 | |
| 3680 | // decode image to YCbCr format |
| 3681 | static int stbi__decode_jpeg_image(stbi__jpeg* j) { |
no test coverage detected