README
上传用户:ykyjsl
上传日期:2022-01-30
资源大小:145k
文件大小:8k
源码类别:

压缩解压

开发平台:

C/C++

  1. Word, Character, Integer, and Bit Based Compression Using Arithmetic Coding.
  2. -------------------------------------------------------------------
  3. Authors:
  4. John Carpinelli
  5. Alistair Moffat (alistair@cs.mu.oz.au)
  6. Radford Neal (radford@ai.toronto.edu)
  7. Wayne Salamonsen
  8. Lang Stuiver (langs@cs.mu.oz.au)
  9. Andrew Turpin (aht@cs.mu.oz.au)
  10. Ian Witten (ihw@waikato.ac.nz)
  11. Contact:
  12. Alistair Moffat
  13. Department of Computer Science
  14. University of Melbourne
  15. Victoria, Australia 3052.
  16. Fax: +61 3 93481184
  17. alistair@cs.mu.oz.au
  18. http://www.cs.mu.oz.au/~alistair/
  19. Based on:
  20. A. Moffat, R. Neal, I.H. Witten, "Arithmetic Coding Revisted", ACM
  21. Transactions on Information Systems, 16(3):256-294, 1998.
  22. http://www.cs.mu.oz.au/~alistair/abstracts/mnw98:acmtois.html
  23. A. Moffat, "An improved data structure for cummulative probability
  24. tables", Software-Practice and Experience, Software-Practice and
  25. Experience, 29(7):647-659, 1999.
  26. http://www.cs.mu.oz.au/~alistair/abstracts/mof99:spe.html
  27. See also:
  28. I.H. Witten, R. Neal, J.G. Cleary, "Arithmetic Coding for Data
  29. Compression", Comm ACM., 30(6):520-541, June 1987.
  30. ftp://ftp.cpsc.ucalgary.ca/pub/projects/ar.cod
  31. Radford M. Neal, Low-Precision Arithmetic Coding Implementation.
  32. ftp://ftp.cs.toronto.edu/pub/radford/lowp_ac.shar
  33. Thanks:
  34. To Mahesh Naik, Julian Seward, Michael Schindler, Sascha Kratky, Tim
  35. Wentford, and the many other people who have provided feedback on
  36. earlier versions of this software.
  37. Overview:
  38. This package contains C source code for an illustrative implementation
  39. of arithmetic coding.  Four different models are included with the
  40. package: an adaptive zero-order word based model, an adaptive
  41. zero-order character based model, and adaptive zero-order (unsigned)
  42. integer based model, and an adaptive fixed-context bit-based model.
  43. The option of using shift/add operations to effect the necessary
  44. integer multiplication and division operations is also supported.  Use
  45. of the shift/add option may result in speed improvement on some
  46. architectures.
  47. Each of the four programs can be thought of as consisting of three
  48. sections:  model, statistics, and coder. Four different models have
  49. been provided, one statistics module, and one coder module (but with a
  50. compile time option to use hardware or software arithmetic).
  51. Models:
  52. The word model follows a strictly alternating sequence of reading a
  53. word then a non-word. After reading each word/non-word it uses a
  54. hashtable to find the corresponding ordinal word number which it then
  55. passes to the statistics module together with the corresponding
  56. word/non word context. A context stores the corresponding frequency for
  57. each ordinal symbol. This model illustrates the advantages of the new
  58. coder on large alphabets, and the manipulation of a number of
  59. ``contexts'' within a single program.
  60. The adaptive zero-order character-based model is broadly equivalent to
  61. the one presented in the CACM paper of Witten, Neal and Cleary.
  62. Compression is relatively poor.
  63. The adaptive zero-order integer-based model is a simple derivative of
  64. the character-based one, and reads uints from the input rather than
  65. bytes.  Note that each integer must be in the range 1..r+1, where r is
  66. the largest integer seen to date. The first integer in the file must be
  67. 1.  Think of these integers as being symbol identifiers assigned on the
  68. fly in order of first appearance.
  69. The bit-based model takes one bit at a time from the input stream and
  70. passes it and the corresponding context into the statistics module.
  71. The correct context is chosen based on the previous n bits, where 0 <=
  72. n <= 20 is specified as a commandline parameter.  Relatively good
  73. compression results when n is large, but it runs slowly. The intention
  74. is to illustrate the use of the arithmetic coding routines when
  75. restricted to a binary alphabet.
  76. The zero-order unsigned-integer based model was used in experiments
  77. when testing the cummulative statistics data structure used in stats.c,
  78. and many other coding exeriments (see the WWW site for details).
  79. Statistics:
  80. The statistics module interfaces the model and the coder.  It is
  81. responsible for probability estimation and generation of the parameters
  82. required by the coder.  It does so by adaptively counting symbol
  83. occurrences, and uses a tree-based structure to maintain cumulative
  84. frequencies.  Accessing the structure takes O(log s) time per symbol
  85. number s.  Just as important, it is space-economical, and requires just
  86. n words of storage compared to the 3n words required by the CACM
  87. structure.
  88. Coder:
  89. The default coder uses shift/add integer arithmetic in its
  90. calculations, as described in "Arithmetic Coding Revisited". The
  91. compile time option "-DMULT_DIV" forces the use of multiplications and
  92. divisions.  The low precision that is required allows, on some
  93. architectures, faster execution with shift/add.
  94. One notable feature about the coder is that by using a limited
  95. precision implementation, the total frequency can be up to 30 bits
  96. (assuming 32 bit integers, or more generally n-2 for n-bit integers).
  97. That is, the total frequency may reach a value as large as
  98. 1,073,741,824 before frequencies need be halved. The number of bits
  99. used for frequency counts can be set as a command line argument
  100. allowing one to use fewer bits for more precise coding.  The default
  101. number of bits used for frequency counts is 27.
  102. The use of large values for the F_bits parameter also allows faster
  103. execution, since much of the arithmetic can be done to low precision.
  104. Very large values for F_bits do, however, introduce rounding effects in
  105. the coder that may negate the gain of using more accurate model
  106. probabilities.  See the paper for analysis of these rounding effects.
  107. The package:
  108. The package consists of 22 files: 9 source files (.c), 5 header files (.h), 1
  109. include file (.i), a makefile, 4 man pages (.1), a WHATSNEW file, and this
  110. README file.
  111. arith_coder.c: Front end to the program.
  112. word.c: Driving code for the word based compression model.
  113. char.c:  Driving code for the character based compression model.
  114. bits.c: Driving code for the bit based compression model.
  115. uint.c: Driving code for the unsigned integer based compression model.
  116. bitio.c: Input output functions (bit and byte level)
  117. stats.c:  Functions for maintaining frequency counts.
  118. arith.c:  Functions associated with arithmetic coding.  
  119. hashtable.c:  Functions associated with maintaining the hash table 
  120.               used to convert words to ordinal word numbers
  121. arith.h: Function prototypes exported from arith.c, #defines used in
  122.   arith.c
  123. stats.h: Function prototypes exported from stats.c, #defines used in
  124. stats.c
  125. bitio.h: Input / output macros (bit and byte level)
  126. arith_coder.h: Function prototypes #defines used in arith_coder.c, char.c,
  127.                bits.c, word.c.
  128. hashtable.h: Function prototypes exported from hashtable.c, #defines used
  129.              in hashtable.c
  130. unroll.i: Generic include file to unroll loops / repeat code fragments.
  131. arith_coder.1: Manual page
  132. char.1, word.1, bits.1, uint.1: Pointers to arith_coder.1 man page.
  133. Usage:  
  134. The programs share a common interface (and are in fact the same program).
  135. Output is written to stdout. If no input file is specified, input is taken
  136. from stdin. One of -e or -d must be specified, to encode or decode.
  137. For help on usage, type "arith_coder -h".  For more detail refer to the man
  138. page.
  139. Here is a sample output of arith_coder -h:
  140. Usage: arith_coder [-e [-t s] [-f n] [-b n] [-m n] [-c n] | -d] [-v] [file]
  141. -e: Encode
  142.     -t s    Encoding method               (char, word, bits, default = char)
  143.     -b n    Code bits to use              (27, fixed at compile time)
  144.     -f n    Frequency bits to use         (32, fixed at compile time)
  145.     -m n    Memory size to use (Mbytes)   (1..255, default = 1)    bits & word
  146.     -c n    Bits of context to use        (0..20, default = 16)    bits only
  147. -d: Decode
  148. -v: Verbose Give timing, compression, and memory usage information.
  149. Conditions:
  150. These programs are supplied free of charge for research purposes only, and
  151. may not sold or incorporated into any commercial product.  There is
  152. ABSOLUTELY NO WARRANTY of any sort, nor any undertaking that they are fit for
  153. ANY PURPOSE WHATSOEVER.  Use them at your own risk.  If you do happen to find
  154. a bug, or have modifications to suggest, please report the same to Alistair
  155. Moffat at the address above.
  156. Have fun!
  157. Alistair Moffat,
  158. February 1999