Exemple #1
0
/*
* The main loop for expansion is very similar to the expansion
* routine used in the simpler compression program, ARITH1E.C. The
* routine first has to initialize the the arithmetic coder and the
* model. The decompression loop differs in a couple of respect.
* First of all, it handles the special ESCAPE character, by
* removing them from the input bit stream but just throwing them
* away otherwise. Secondly, it handles the special FLUSH character.
* Once the main decoding loop is done, the cleanup code is called,
* and the program exits.
*
*/
void ExpandFile(BIT_FILE *input,FILE *output,int argc,char *argv[])
{
 SYMBOL s;
 int c;
 int count;
 initialize_options( argc, argv );
 initialize_model();
 initialize_arithmetic_decoder( input );
 for ( ; ; ) {
	 do {
	 get_symbol_scale( &s );
	 count = get_current_count( &s );
	 c = convert_symbol_to_int( count, &s );
	 remove_symbol_from_stream( input, &s );
	 } while ( c == ESCAPE );
	 if ( c == DONE )
	 	break;
	 if ( c != FLUSH )
	 	putc( (char) c, output );
	 else
	 	flush_model();
	 update_model( c );
	 add_character_to_model( c );
 }
}
Exemple #2
0
static int decode_arith_symbol(MscCoderArithModel *arithModel, GetBitContext *gb) {
	MscCoderArithSymbol arithSymbol;
	int count, value;

	// get range symbol
	get_symbol_scale(arithModel, &arithSymbol);

	// get value for symbol
	count = get_current_count(&arithSymbol);
	value = convert_symbol_to_int(arithModel, count, &arithSymbol);

	// remove symbol from stream
	remove_symbol_from_stream(gb, &arithSymbol);

	// update arithmetic coder model
	update_model(arithModel, value);

	return value;
}