MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__parse_entropy_coded_data

Function stbi__parse_entropy_coded_data

Source/Utils/stb_image.h:2948–3070  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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