MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / stbi__parse_entropy_coded_data

Function stbi__parse_entropy_coded_data

extern/stb_image.h:2947–3069  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2945}
2946
2947static int stbi__parse_entropy_coded_data(stbi__jpeg *z)
2948{
2949 stbi__jpeg_reset(z);
2950 if (!z->progressive) {
2951 if (z->scan_n == 1) {
2952 int i,j;
2953 STBI_SIMD_ALIGN(short, data[64]);
2954 int n = z->order[0];
2955 // non-interleaved data, we just need to process one block at a time,
2956 // in trivial scanline order
2957 // number of blocks to do just depends on how many actual "pixels" this
2958 // component has, independent of interleaved MCU blocking and such
2959 int w = (z->img_comp[n].x+7) >> 3;
2960 int h = (z->img_comp[n].y+7) >> 3;
2961 for (j=0; j < h; ++j) {
2962 for (i=0; i < w; ++i) {
2963 int ha = z->img_comp[n].ha;
2964 if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0;
2965 z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data);
2966 // every data block is an MCU, so countdown the restart interval
2967 if (--z->todo <= 0) {
2968 if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
2969 // if it's NOT a restart, then just bail, so we get corrupt data
2970 // rather than no data
2971 if (!STBI__RESTART(z->marker)) return 1;
2972 stbi__jpeg_reset(z);
2973 }
2974 }
2975 }
2976 return 1;
2977 } else { // interleaved
2978 int i,j,k,x,y;
2979 STBI_SIMD_ALIGN(short, data[64]);
2980 for (j=0; j < z->img_mcu_y; ++j) {
2981 for (i=0; i < z->img_mcu_x; ++i) {
2982 // scan an interleaved mcu... process scan_n components in order
2983 for (k=0; k < z->scan_n; ++k) {
2984 int n = z->order[k];
2985 // scan out an mcu's worth of this component; that's just determined
2986 // by the basic H and V specified for the component
2987 for (y=0; y < z->img_comp[n].v; ++y) {
2988 for (x=0; x < z->img_comp[n].h; ++x) {
2989 int x2 = (i*z->img_comp[n].h + x)*8;
2990 int y2 = (j*z->img_comp[n].v + y)*8;
2991 int ha = z->img_comp[n].ha;
2992 if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0;
2993 z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*y2+x2, z->img_comp[n].w2, data);
2994 }
2995 }
2996 }
2997 // after all interleaved components, that's an interleaved MCU,
2998 // so now count down the restart interval
2999 if (--z->todo <= 0) {
3000 if (z->code_bits < 24) stbi__grow_buffer_unsafe(z);
3001 if (!STBI__RESTART(z->marker)) return 1;
3002 stbi__jpeg_reset(z);
3003 }
3004 }

Callers 1

stbi__decode_jpeg_imageFunction · 0.85

Calls 5

stbi__jpeg_resetFunction · 0.85
stbi__jpeg_decode_blockFunction · 0.85
stbi__grow_buffer_unsafeFunction · 0.85

Tested by

no test coverage detected