iOS/buildlibs/armv7/allegro-4.4.2/addons/jpgalleg/src/decode.c
/* huffman_decode:
 *  Fetches bits from the input stream until a valid huffman code is found,
 *  then returns the value associated with that code.
 */
Fetches bits from the input stream until a valid huffman code is found,
then returns the value associated with that code.
Fetches bits from the input stream until a valid huffman code is found then returns the value associated with that code .
static int
huffman_decode(HUFFMAN_TABLE *table)
{
	HUFFMAN_ENTRY *entry, **entry_lut;
	int i, value;
	unsigned char *p = _jpeg_io.buffer;
	value = (*p & ((1 << _jpeg_io.current_bit) - 1)) << (16 - _jpeg_io.current_bit);
	if (*p++ == 0xff) p++;
	if (p < _jpeg_io.buffer_end) {
		value |= *p << (8 - _jpeg_io.current_bit);
		if (*p++ == 0xff) p++;
		if (p < _jpeg_io.buffer_end)
			value |= *p >> _jpeg_io.current_bit;
	}
	entry_lut = table->entry_of_length;
	for (i = 15; i >= 0; i--) {
		entry = &((*entry_lut)[value >> i]);
		if (entry->bits_length == 16 - i) {
			_jpeg_io.current_bit -= 16 - i;
			while (_jpeg_io.current_bit <= 0) {
				_jpeg_io.current_bit += 8;
				if (*_jpeg_io.buffer == 0xff)
					_jpeg_io.buffer++;
				_jpeg_io.buffer++;
			}
			return entry->value;
		}
		entry_lut++;
	}
	return -1;
}
static int huffman_decode ( HUFFMAN_TABLE * table ) { HUFFMAN_ENTRY * entry , * * entry_lut ; int i , value ; unsigned char * p = _jpeg_io . buffer ; value = ( * p & ( ( 1 << _jpeg_io . current_bit ) - 1 ) ) << ( 16 - _jpeg_io . current_bit ) ; if ( * p ++ == 0xff ) p ++ ; if ( p < _jpeg_io . buffer_end ) { value |= * p << ( 8 - _jpeg_io . current_bit ) ; if ( * p ++ == 0xff ) p ++ ; if ( p < _jpeg_io . buffer_end ) value |= * p >> _jpeg_io . current_bit ; } entry_lut = table -> entry_of_length ; for ( i = 15 ; i >= 0 ; i -- ) { entry = & ( ( * entry_lut ) [ value >> i ] ) ; if ( entry -> bits_length == 16 - i ) { _jpeg_io . current_bit -= 16 - i ; while ( _jpeg_io . current_bit <= 0 ) { _jpeg_io . current_bit += 8 ; if ( * _jpeg_io . buffer == 0xff ) _jpeg_io . buffer ++ ; _jpeg_io . buffer ++ ; } return entry -> value ; } entry_lut ++ ; } return -1 ; }
huffman_decode:
  Fetches bits from the input stream until a valid huffman code is found,
  then returns the value associated with that code.
huffman_decode : Fetches bits from the input stream until a valid huffman code is found then returns the value associated with that code .