iOS/buildlibs/armv7/allegro-4.4.2/addons/jpgalleg/src/decode.c
/* decode_baseline_block:
 *  Decodes an 8x8 basic block of coefficients of given type (luminance or
 *  chrominance) from the input stream. Used for baseline decoding.
 */
Decodes an 8x8 basic block of coefficients of given type (luminance or
chrominance) from the input stream. Used for baseline decoding.
Decodes an 8x8 basic block of coefficients of given type ( luminance or chrominance ) from the input stream . Used for baseline decoding .
static int
decode_baseline_block(short *block, int type, int *old_dc)
{
	HUFFMAN_TABLE *dc_table, *ac_table;
	short *quant_table;
	int data, i, index;
	int num_zeroes, category;
	short workspace[130];
	short pre_idct_block[80];
	short ordered_pre_idct_block[64];
	if (type == LUMINANCE) {
		dc_table = dc_luminance_table;
		ac_table = ac_luminance_table;
		quant_table = luminance_quantization_table;
	}
	else {
		dc_table = dc_chrominance_table;
		ac_table = ac_chrominance_table;
		quant_table = chrominance_quantization_table;
	}
	data = huffman_decode(dc_table);
	if (data < 0) {
		TRACE("Bad dc data");
		jpgalleg_error = JPG_ERROR_BAD_IMAGE;
		return -1;
	}
	if ((data = get_value(data & 0xf)) == (int)0x80000000)
		return -1;
	*old_dc += data;
	pre_idct_block[0] = *old_dc;
	index = 1;
	do {
		data = huffman_decode(ac_table);
		if (data < 0) {
			TRACE("Bad ac data");
			jpgalleg_error = JPG_ERROR_BAD_IMAGE;
			return -1;
		}
		num_zeroes = data >> 4;
		category = data & 0xf;
		if (category != 0) {
			for (; num_zeroes; num_zeroes--)
				pre_idct_block[index++] = 0;
			if ((data = get_value(category)) == (int)0x80000000)
				return -1;
			pre_idct_block[index++] = data;
		}
		else {
			if (num_zeroes == 0) {
				while (index < 64)
					pre_idct_block[index++] = 0;
				break;
			}
			else if (num_zeroes == 15) {
				for (i = 16; i; i--)
					pre_idct_block[index++] = 0;
			}
			else {
				TRACE("Bad ac data");
				jpgalleg_error = JPG_ERROR_BAD_IMAGE;
				return -1;
			}
		}
	} while (index < 64);
	zigzag_reorder(pre_idct_block, ordered_pre_idct_block);
	idct(ordered_pre_idct_block, block, quant_table, workspace);
	return 0;
}
static int decode_baseline_block ( short * block , int type , int * old_dc ) { HUFFMAN_TABLE * dc_table , * ac_table ; short * quant_table ; int data , i , index ; int num_zeroes , category ; short workspace [ 130 ] ; short pre_idct_block [ 80 ] ; short ordered_pre_idct_block [ 64 ] ; if ( type == LUMINANCE ) { dc_table = dc_luminance_table ; ac_table = ac_luminance_table ; quant_table = luminance_quantization_table ; } else { dc_table = dc_chrominance_table ; ac_table = ac_chrominance_table ; quant_table = chrominance_quantization_table ; } data = huffman_decode ( dc_table ) ; if ( data < 0 ) { TRACE ( " " ) ; jpgalleg_error = JPG_ERROR_BAD_IMAGE ; return -1 ; } if ( ( data = get_value ( data & 0xf ) ) == ( int ) 0x80000000 ) return -1 ; * old_dc += data ; pre_idct_block [ 0 ] = * old_dc ; index = 1 ; do { data = huffman_decode ( ac_table ) ; if ( data < 0 ) { TRACE ( " " ) ; jpgalleg_error = JPG_ERROR_BAD_IMAGE ; return -1 ; } num_zeroes = data >> 4 ; category = data & 0xf ; if ( category != 0 ) { for ( ; num_zeroes ; num_zeroes -- ) pre_idct_block [ index ++ ] = 0 ; if ( ( data = get_value ( category ) ) == ( int ) 0x80000000 ) return -1 ; pre_idct_block [ index ++ ] = data ; } else { if ( num_zeroes == 0 ) { while ( index < 64 ) pre_idct_block [ index ++ ] = 0 ; break ; } else if ( num_zeroes == 15 ) { for ( i = 16 ; i ; i -- ) pre_idct_block [ index ++ ] = 0 ; } else { TRACE ( " " ) ; jpgalleg_error = JPG_ERROR_BAD_IMAGE ; return -1 ; } } } while ( index < 64 ) ; zigzag_reorder ( pre_idct_block , ordered_pre_idct_block ) ; idct ( ordered_pre_idct_block , block , quant_table , workspace ) ; return 0 ; }
decode_baseline_block:
  Decodes an 8x8 basic block of coefficients of given type (luminance or
  chrominance) from the input stream.
decode_baseline_block : Decodes an 8x8 basic block of coefficients of given type ( luminance or chrominance ) from the input stream .
/* Bad block */ /* Normal zero run length coding */ /* End of block */ /* 16 zeroes special case */