decode image to YCbCr format
| 3679 | |
| 3680 | // decode image to YCbCr format |
| 3681 | static int stbi__decode_jpeg_image(stbi__jpeg* j) { |
| 3682 | int m; |
| 3683 | for (m = 0; m < 4; m++) { |
| 3684 | j->img_comp[m].raw_data = NULL; |
| 3685 | j->img_comp[m].raw_coeff = NULL; |
| 3686 | } |
| 3687 | j->restart_interval = 0; |
| 3688 | if (!stbi__decode_jpeg_header(j, STBI__SCAN_load)) |
| 3689 | return 0; |
| 3690 | m = stbi__get_marker(j); |
| 3691 | while (!stbi__EOI(m)) { |
| 3692 | if (stbi__SOS(m)) { |
| 3693 | if (!stbi__process_scan_header(j)) |
| 3694 | return 0; |
| 3695 | if (!stbi__parse_entropy_coded_data(j)) |
| 3696 | return 0; |
| 3697 | if (j->marker == STBI__MARKER_none) { |
| 3698 | // handle 0s at the end of image data from IP Kamera 9060 |
| 3699 | while (!stbi__at_eof(j->s)) { |
| 3700 | int x = stbi__get8(j->s); |
| 3701 | if (x == 255) { |
| 3702 | j->marker = stbi__get8(j->s); |
| 3703 | break; |
| 3704 | } |
| 3705 | } |
| 3706 | // if we reach eof without hitting a marker, stbi__get_marker() below |
| 3707 | // will fail and we'll eventually return 0 |
| 3708 | } |
| 3709 | } else if (stbi__DNL(m)) { |
| 3710 | int Ld = stbi__get16be(j->s); |
| 3711 | stbi__uint32 NL = stbi__get16be(j->s); |
| 3712 | if (Ld != 4) |
| 3713 | return stbi__err("bad DNL len", "Corrupt JPEG"); |
| 3714 | if (NL != j->s->img_y) |
| 3715 | return stbi__err("bad DNL height", "Corrupt JPEG"); |
| 3716 | } else { |
| 3717 | if (!stbi__process_marker(j, m)) |
| 3718 | return 0; |
| 3719 | } |
| 3720 | m = stbi__get_marker(j); |
| 3721 | } |
| 3722 | if (j->progressive) |
| 3723 | stbi__jpeg_finish(j); |
| 3724 | return 1; |
| 3725 | } |
| 3726 | |
| 3727 | // static jfif-centered resampling (across block boundaries) |
| 3728 |
no test coverage detected