00001 /*************************************************************************** 00002 arithcodec.h - Definition of class ArithCodec 00003 ------------------- 00004 begin : June 21 2002 00005 copyright : (C) 2003 by Vojtìch Toman 00006 email : vtoman@lit.cz 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 /* Based on code by: */ 00019 00020 00021 /*************************************************************************** 00022 Authors: John Carpinelli (johnfc@ecr.mu.oz.au) 00023 Wayne Salamonsen (wbs@mundil.cs.mu.oz.au) 00024 Lang Stuiver (langs@cs.mu.oz.au) 00025 00026 Purpose: Data compression using revised arithmetic coding method. 00027 00028 Based on: A. Moffat, R. Neal, I.H. Witten, "Arithmetic Coding Revisted", 00029 Proc. IEEE Data Compression Conference, Snowbird, Utah, 00030 March 1995. 00031 00032 Copyright 1995 John Carpinelli and Wayne Salamonsen, All Rights Reserved. 00033 Copyright 1996 Lang Stuiver, All Rights Reserved. 00034 00035 These programs are supplied free of charge for research purposes only, 00036 and may not sold or incorporated into any commercial product. There is 00037 ABSOLUTELY NO WARRANTY of any sort, nor any undertaking that they are 00038 fit for ANY PURPOSE WHATSOEVER. Use them at your own risk. If you do 00039 happen to find a bug, or have modifications to suggest, please report 00040 the same to Alistair Moffat, alistair@cs.mu.oz.au. The copyright 00041 notice above and this statement of conditions must remain an integral 00042 part of each and every copy made of these files. 00043 ***************************************************************************/ 00044 00053 #ifdef __GNUG__ 00054 #pragma interface 00055 #endif 00056 00057 #ifndef ARITHCODEC_H 00058 #define ARITHCODEC_H 00059 00060 00061 #include "defs.h" 00062 #include "arithcodecbase.h" 00063 00064 00065 00067 #define BYTE_SIZE SIZEOF_CHAR*8 00068 00069 00071 #define Half ((CodeValue) 1 << (B_BITS-1)) 00072 00073 00075 #define Quarter ((CodeValue) 1 << (B_BITS-2)) 00076 00077 00090 class ArithCodec : public ArithCodecBase 00091 { 00092 public: 00094 ArithCodec(void); 00095 00097 //virtual void setOutputDevice(IODevice *device); 00098 00100 //virtual void setInputDevice(IODevice *device); 00101 00103 virtual void arithmeticEncode(FreqValue, FreqValue, FreqValue); 00104 00106 virtual FreqValue arithmeticDecodeTarget(FreqValue); 00107 00109 virtual void arithmeticDecode(FreqValue, FreqValue, FreqValue); 00110 00111 //void binaryArithmeticEncode(FreqValue, FreqValue, int); 00112 //int binaryArithmeticDecode(FreqValue, FreqValue); 00113 00115 virtual void startEncode(void); 00116 00118 virtual void finishEncode(void); 00119 00121 virtual void startDecode(void); 00122 00124 virtual void finishDecode(void); 00125 00127 virtual void startOutputtingBits(void); 00128 00130 virtual void startInputtingBits(void); 00131 00133 virtual void doneOutputtingBits(void); 00134 00136 virtual void doneInputtingBits(void); 00137 00139 virtual size_t numberOfOutputBytes(void); 00140 00141 protected: 00142 // Input decoding state 00143 00145 CodeValue in_R; 00146 00148 CodeValue in_D; 00149 00151 DivValue in_r; 00152 00153 #ifdef FRUGAL_BITS 00154 00155 CodeValue in_V; 00156 #endif 00157 00158 // Output encoding state 00159 00161 long numberOfBytes; 00162 00164 CodeValue out_L; 00165 00167 CodeValue out_R; 00168 00170 unsigned long outBitsOutstanding; 00171 00172 #ifdef FRUGAL_BITS 00173 00174 int ignoreFirstBit; 00175 00177 int firstMessage; 00178 00180 CodeValue retrieveExcessInputBits(void); 00181 #endif 00182 00184 int inBuffer; 00185 00187 unsigned char inBitPtr; 00188 00190 int inGarbage; 00191 00193 int outBuffer; 00194 00196 int outBitsToGo; 00197 00198 }; //ArithCodec 00199 00200 00201 #endif //ARITHCODEC_H