Exemplo n.º 1
0
/*
 * This expansion routine demonstrates the basic algorithm used for
 * decompression in this article.  It first goes to the modeling
 * module and gets the scale for the current context.  (Note that
 * the scale is fixed here, since this is not an adaptive model).
 * It then asks the arithmetic decoder to give a high and low
 * value for the current input number scaled to match the current
 * range.  Finally, it asks the modeling unit to convert the
 * high and low values to a symbol.
 */
void expand()
{
    FILE *compressed_file;
    SYMBOL s;
    char c;
    int count;

    compressed_file=fopen( "software/benchmarks/data/test_comp.cmp", "rb" );
    if ( compressed_file == NULL )
        error_exit( "Could not open output file" );
    puts( "Decoding..." );
    printf( "Incoming characters: " );
    initialize_input_bitstream();
    initialize_arithmetic_decoder( compressed_file );
    for ( ; ; )
    {
        s.scale = 11;
        count = get_current_count( &s );
        c = convert_symbol_to_int( count, &s );
        if ( c == '\0' )
            break;
        remove_symbol_from_stream( compressed_file, &s );
        putc( c, stdout );
    }
    putc( '\n', stdout );
}
Exemplo n.º 2
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 );
 }
}
Exemplo n.º 3
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;
}