MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / stbi__parse_entropy_coded_data

Function stbi__parse_entropy_coded_data

stb/stb_image.h:2949–3071  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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