| 3042 | } |
| 3043 | |
| 3044 | static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { |
| 3045 | stbi__jpeg_reset(z); |
| 3046 | if (!z->progressive) { |
| 3047 | if (z->scan_n == 1) { |
| 3048 | int i, j; |
| 3049 | STBI_SIMD_ALIGN(short, data[64]); |
| 3050 | int n = z->order[0]; |
| 3051 | // non-interleaved data, we just need to process one block at a time, |
| 3052 | // in trivial scanline order |
| 3053 | // number of blocks to do just depends on how many actual "pixels" this |
| 3054 | // component has, independent of interleaved MCU blocking and such |
| 3055 | int w = (z->img_comp[n].x + 7) >> 3; |
| 3056 | int h = (z->img_comp[n].y + 7) >> 3; |
| 3057 | for (j = 0; j < h; ++j) { |
| 3058 | for (i = 0; i < w; ++i) { |
| 3059 | int ha = z->img_comp[n].ha; |
| 3060 | if (!stbi__jpeg_decode_block(z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, z->fast_ac[ha], n, |
| 3061 | z->dequant[z->img_comp[n].tq])) |
| 3062 | return 0; |
| 3063 | z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, z->img_comp[n].w2, data); |
| 3064 | // every data block is an MCU, so countdown the restart interval |
| 3065 | if (--z->todo <= 0) { |
| 3066 | if (z->code_bits < 24) |
| 3067 | stbi__grow_buffer_unsafe(z); |
| 3068 | // if it's NOT a restart, then just bail, so we get corrupt data |
| 3069 | // rather than no data |
| 3070 | if (!STBI__RESTART(z->marker)) |
| 3071 | return 1; |
| 3072 | stbi__jpeg_reset(z); |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | return 1; |
| 3077 | } else { // interleaved |
| 3078 | int i, j, k, x, y; |
| 3079 | STBI_SIMD_ALIGN(short, data[64]); |
| 3080 | for (j = 0; j < z->img_mcu_y; ++j) { |
| 3081 | for (i = 0; i < z->img_mcu_x; ++i) { |
| 3082 | // scan an interleaved mcu... process scan_n components in order |
| 3083 | for (k = 0; k < z->scan_n; ++k) { |
| 3084 | int n = z->order[k]; |
| 3085 | // scan out an mcu's worth of this component; that's just determined |
| 3086 | // by the basic H and V specified for the component |
| 3087 | for (y = 0; y < z->img_comp[n].v; ++y) { |
| 3088 | for (x = 0; x < z->img_comp[n].h; ++x) { |
| 3089 | int x2 = (i * z->img_comp[n].h + x) * 8; |
| 3090 | int y2 = (j * z->img_comp[n].v + y) * 8; |
| 3091 | int ha = z->img_comp[n].ha; |
| 3092 | if (!stbi__jpeg_decode_block(z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, |
| 3093 | z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) |
| 3094 | return 0; |
| 3095 | z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * y2 + x2, z->img_comp[n].w2, |
| 3096 | data); |
| 3097 | } |
| 3098 | } |
| 3099 | } |
| 3100 | // after all interleaved components, that's an interleaved MCU, |
| 3101 | // so now count down the restart interval |
no test coverage detected