Cube Demo/src/stb_image.h
// decode one 64-entry block--

decode one 64-entry block
decode one 64 - entry block
static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi__uint16 *dequant)
{
	int diff, dc, k;
	int t;
	if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
	t = stbi__jpeg_huff_decode(j, hdc);
	if (t < 0) return stbi__err("bad huffman code", "Corrupt JPEG");
	memset(data, 0, 64 * sizeof(data[0]));
	diff = t ? stbi__extend_receive(j, t) : 0;
	dc = j->img_comp[b].dc_pred + diff;
	j->img_comp[b].dc_pred = dc;
	data[0] = (short)(dc * dequant[0]);
	k = 1;
	do {
		unsigned int zig;
		int c, r, s;
		if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
		c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS) - 1);
		r = fac[c];
		if (r) { 
			k += (r >> 4) & 15; 
			s = r & 15; 
			j->code_buffer <<= s;
			j->code_bits -= s;
			zig = stbi__jpeg_dezigzag[k++];
			data[zig] = (short)((r >> 8) * dequant[zig]);
		}
		else {
			int rs = stbi__jpeg_huff_decode(j, hac);
			if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG");
			s = rs & 15;
			r = rs >> 4;
			if (s == 0) {
				if (rs != 0xf0) break; 
				k += 16;
			}
			else {
				k += r;
				zig = stbi__jpeg_dezigzag[k++];
				data[zig] = (short)(stbi__extend_receive(j, s) * dequant[zig]);
			}
		}
	} while (k < 64);
	return 1;
}
static int stbi__jpeg_decode_block ( stbi__jpeg * j , short data [ 64 ] , stbi__huffman * hdc , stbi__huffman * hac , stbi__int16 * fac , int b , stbi__uint16 * dequant ) { int diff , dc , k ; int t ; if ( j -> code_bits < 16 ) stbi__grow_buffer_unsafe ( j ) ; t = stbi__jpeg_huff_decode ( j , hdc ) ; if ( t < 0 ) return stbi__err ( " " , " " ) ; memset ( data , 0 , 64 * sizeof ( data [ 0 ] ) ) ; diff = t ? stbi__extend_receive ( j , t ) : 0 ; dc = j -> img_comp [ b ] . dc_pred + diff ; j -> img_comp [ b ] . dc_pred = dc ; data [ 0 ] = ( short ) ( dc * dequant [ 0 ] ) ; k = 1 ; do { unsigned int zig ; int c , r , s ; if ( j -> code_bits < 16 ) stbi__grow_buffer_unsafe ( j ) ; c = ( j -> code_buffer >> ( 32 - FAST_BITS ) ) & ( ( 1 << FAST_BITS ) - 1 ) ; r = fac [ c ] ; if ( r ) { k += ( r >> 4 ) & 15 ; s = r & 15 ; j -> code_buffer <<= s ; j -> code_bits -= s ; zig = stbi__jpeg_dezigzag [ k ++ ] ; data [ zig ] = ( short ) ( ( r >> 8 ) * dequant [ zig ] ) ; } else { int rs = stbi__jpeg_huff_decode ( j , hac ) ; if ( rs < 0 ) return stbi__err ( " " , " " ) ; s = rs & 15 ; r = rs >> 4 ; if ( s == 0 ) { if ( rs != 0xf0 ) break ; k += 16 ; } else { k += r ; zig = stbi__jpeg_dezigzag [ k ++ ] ; data [ zig ] = ( short ) ( stbi__extend_receive ( j , s ) * dequant [ zig ] ) ; } } } while ( k < 64 ) ; return 1 ; }
decode one 64-entry block
decode one 64 - entry block
// 0 all the ac values now so we can do it 32-bits at a time
 // decode AC components, see JPEG spec
 // fast-AC path
 // run
 // combined length
 // decode into unzigzag'd location
 // end block
 // decode into unzigzag'd location
