⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moblie.txt

📁 自适应算术编码的框架
💻 TXT
📖 第 1 页 / 共 2 页
字号:
X{   output_bit(bit);				/* Output the bit.          */
X    while (bits_to_follow>0) {
X        output_bit(!bit);			/* Output bits_to_follow    */
X        bits_to_follow -= 1;			/* opposite bits. Set       */
X    }						/* bits_to_follow to zero.  */
X}
END_OF_FILE
if test 2477 -ne `wc -c <'arithmetic_encode.c'`; then
    echo shar: \"'arithmetic_encode.c'\" unpacked with wrong size!
fi
# end of 'arithmetic_encode.c'
fi
if test -f 'bit_input.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bit_input.c'\"
else
echo shar: Extracting \"'bit_input.c'\" \(1117 characters\)
sed "s/^X//" >'bit_input.c' <<'END_OF_FILE'
X/* BIT INPUT ROUTINES. */
X
X#include <stdio.h>
X#include "arithmetic_coding.h"
X
X
X/* THE BIT BUFFER. */
X
Xstatic int buffer;		/* Bits waiting to be input                 */
Xstatic int bits_to_go;		/* Number of bits still in buffer           */
Xstatic int garbage_bits;	/* Number of bits past end-of-file          */
X
X
X/* INITIALIZE BIT INPUT. */
X
Xstart_inputing_bits()
X{   bits_to_go = 0;				/* Buffer starts out with   */
X    garbage_bits = 0;				/* no bits in it.           */
X}
X
X
X/* INPUT A BIT. */
X
Xint input_bit()
X{   int t;
X    if (bits_to_go==0) {			/* Read the next byte if no */
X        buffer = getc(stdin);			/* bits are left in buffer. */
X        if (buffer==EOF) {
X            garbage_bits += 1;			    /* Return arbitrary bits*/
X            if (garbage_bits>Code_value_bits-2) {   /* after eof, but check */
X                fprintf(stderr,"Bad input file\n"); /* for too many such.   */
X                exit(-1);
X            }
X        }
X        bits_to_go = 8;
X    }
X    t = buffer&1;				/* Return the next bit from */
X    buffer >>= 1;				/* the bottom of the byte.  */
X    bits_to_go -= 1;
X    return t;
X}
END_OF_FILE
if test 1117 -ne `wc -c <'bit_input.c'`; then
    echo shar: \"'bit_input.c'\" unpacked with wrong size!
fi
# end of 'bit_input.c'
fi
if test -f 'bit_output.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bit_output.c'\"
else
echo shar: Extracting \"'bit_output.c'\" \(769 characters\)
sed "s/^X//" >'bit_output.c' <<'END_OF_FILE'
X/* BIT OUTPUT ROUTINES. */
X
X#include <stdio.h>
X
X
X/* THE BIT BUFFER. */
X
Xstatic int buffer;		/* Bits buffered for output                 */
Xstatic int bits_to_go;		/* Number of bits free in buffer            */
X
X
X/* INITIALIZE FOR BIT OUTPUT. */
X
Xstart_outputing_bits()
X{   buffer = 0;					/* Buffer is empty to start */
X    bits_to_go= 8;				/* with.                    */
X}
X
X
X/* OUTPUT A BIT. */
X
Xoutput_bit(bit)
X    int bit;
X{   buffer >>= 1; if (bit) buffer |= 0x80;	/* Put bit in top of buffer.*/
X    bits_to_go -= 1;
X    if (bits_to_go==0) {			/* Output buffer if it is   */
X        putc(buffer,stdout);			/* now full.                */
X        bits_to_go = 8;
X    }
X}
X
X
X/* FLUSH OUT THE LAST BITS. */
X
Xdone_outputing_bits()
X{   putc(buffer>>bits_to_go,stdout);
X}
END_OF_FILE
if test 769 -ne `wc -c <'bit_output.c'`; then
    echo shar: \"'bit_output.c'\" unpacked with wrong size!
fi
# end of 'bit_output.c'
fi
if test -f 'decode.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'decode.c'\"
else
echo shar: Extracting \"'decode.c'\" \(614 characters\)
sed "s/^X//" >'decode.c' <<'END_OF_FILE'
X/* MAIN PROGRAM FOR DECODING. */
X
X#include <stdio.h>
X#include "model.h"
X
Xmain()
X{   start_model();				/* Set up other modules.    */
X    start_inputing_bits();
X    start_decoding();
X    for (;;) {					/* Loop through characters. */
X        int ch; int symbol;
X        symbol = decode_symbol(cum_freq);	/* Decode next symbol.      */
X        if (symbol==EOF_symbol) break;		/* Exit loop if EOF symbol. */
X        ch = index_to_char[symbol];		/* Translate to a character.*/
X        putc(ch,stdout);			/* Write that character.    */
X        update_model(symbol);			/* Update the model.        */
X    }
X    exit(0);
X}
END_OF_FILE
if test 614 -ne `wc -c <'decode.c'`; then
    echo shar: \"'decode.c'\" unpacked with wrong size!
fi
# end of 'decode.c'
fi
if test -f 'encode.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'encode.c'\"
else
echo shar: Extracting \"'encode.c'\" \(759 characters\)
sed "s/^X//" >'encode.c' <<'END_OF_FILE'
X/* MAIN PROGRAM FOR ENCODING. */
X
X#include <stdio.h>
X#include "model.h"
X
Xmain()
X{   start_model();				/* Set up other modules.    */
X    start_outputing_bits();
X    start_encoding();
X    for (;;) {					/* Loop through characters. */
X        int ch; int symbol;
X        ch = getc(stdin);			/* Read the next character. */
X        if (ch==EOF) break;			/* Exit loop on end-of-file.*/
X        symbol = char_to_index[ch];		/* Translate to an index.   */
X        encode_symbol(symbol,cum_freq);		/* Encode that symbol.      */
X        update_model(symbol);			/* Update the model.        */
X    }
X    encode_symbol(EOF_symbol,cum_freq);		/* Encode the EOF symbol.   */
X    done_encoding();				/* Send the last few bits.  */
X    done_outputing_bits();
X    exit(0);
X}
END_OF_FILE
if test 759 -ne `wc -c <'encode.c'`; then
    echo shar: \"'encode.c'\" unpacked with wrong size!
fi
# end of 'encode.c'
fi
if test -f 'makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile'\"
else
echo shar: Extracting \"'makefile'\" \(699 characters\)
sed "s/^X//" >'makefile' <<'END_OF_FILE'
XCFLAGS = -O
X
Xall:		adaptive
X
Xadaptive:		adaptive_encode adaptive_decode
X
Xadaptive_encode:	encode.o adaptive_model.o bit_output.o \
X			  arithmetic_encode.o
X			cc encode.o adaptive_model.o bit_output.o \
X			  arithmetic_encode.o -o adaptive_encode
X
Xadaptive_decode:	decode.o adaptive_model.o bit_input.o \
X			  arithmetic_decode.o
X			cc decode.o adaptive_model.o bit_input.o \
X			  arithmetic_decode.o -o adaptive_decode
X
Xencode.o:		encode.c model.h
Xdecode.o:		decode.c model.h
X
Xadaptive_model.o:	adaptive_model.c model.h
X
Xarithmetic_encode.o:	arithmetic_encode.c arithmetic_coding.h
Xarithmetic_decode.o:	arithmetic_decode.c arithmetic_coding.h
X
Xbit_input.o:		bit_input.c
Xbit_output.o:		bit_output.c
END_OF_FILE
if test 699 -ne `wc -c <'makefile'`; then
    echo shar: \"'makefile'\" unpacked with wrong size!
fi
# end of 'makefile'
fi
if test -f 'model.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'model.h'\"
else
echo shar: Extracting \"'model.h'\" \(691 characters\)
sed "s/^X//" >'model.h' <<'END_OF_FILE'
X/* INTERFACE TO THE MODEL. */
X
X
X/* THE SET OF SYMBOLS THAT MAY BE ENCODED. */
X
X#define No_of_chars 256			/* Number of character symbols      */
X#define EOF_symbol (No_of_chars+1)	/* Index of EOF symbol              */
X
X#define No_of_symbols (No_of_chars+1)	/* Total number of symbols          */
X
X
X/* TRANSLATION TABLES BETWEEN CHARACTERS AND SYMBOL INDEXES. */
X
Xint char_to_index[No_of_chars];		/* To index from character          */
Xunsigned char index_to_char[No_of_symbols+1]; /* To character from index    */
X
X
X/* CUMULATIVE FREQUENCY TABLE. */
X
X#define Max_frequency 16383		/* Maximum allowed frequency count  */
X
Xint cum_freq[No_of_symbols+1];		/* Cumulative symbol frequencies    */
END_OF_FILE
if test 691 -ne `wc -c <'model.h'`; then
    echo shar: \"'model.h'\" unpacked with wrong size!
fi
# end of 'model.h'
fi
echo shar: End of shell archive.
exit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -