123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #ifndef _FILE_H_COMPRESSION_LZARI_
- #define _FILE_H_COMPRESSION_LZARI_
- #define N 4096
- #define F 60
- #define THRESHOLD 2
- #define NIL N
- #define M 15
- #define Q1 (1UL << M)
- #define Q2 (2 * Q1)
- #define Q3 (3 * Q1)
- #define Q4 (4 * Q1)
- #define MAX_CUM (Q1 - 1)
- #define N_CHAR (256 - THRESHOLD + F)
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <VECTOR>
- #if 0
- typedef unsigned char BYTE;
- #define FALSE 0
- #define TRUE 1
- #endif
- class LZARI
- {
- public:
- LZARI();
- virtual ~LZARI();
- protected:
- FILE *infile, *outfile;
- unsigned long textsize;
- unsigned long codesize;
- unsigned long printcount;
- unsigned char text_buf[N + F - 1];
- int match_position;
- int match_length;
- int lson[N + 1];
- int rson[N + 257];
- int dad[N + 1];
-
- unsigned long low;
- unsigned long high;
- unsigned long value;
- int shifts;
- int char_to_sym[N_CHAR];
- int sym_to_char[N_CHAR + 1];
- unsigned int sym_freq[N_CHAR + 1];
- unsigned int sym_cum[N_CHAR + 1];
- unsigned int position_cum[N + 1];
-
- bool m_bMem;
- std::vector<BYTE> m_OutBuffer;
-
- int m_nOutLength;
-
- const BYTE *m_pInBuffer;
- int m_nInLength;
- int m_nInCur;
- unsigned int buffer_putbit, mask_putbit;
- unsigned int buffer_getbit, mask_getbit;
- private:
- void Error(char *message);
- void PutBit(int bit);
- void FlushBitBuffer(void);
- int GetBit(void);
- void InitTree(void);
- void InsertNode(int r);
- void DeleteNode(int p);
- void StartModel(void);
- void UpdateModel(int sym);
- void Output(int bit);
- void EncodeChar(int ch);
- void EncodePosition(int position);
- void EncodeEnd(void);
- int BinarySearchSym(unsigned int x);
- int BinarySearchPos(unsigned int x);
- void StartDecode(void);
- int DecodeChar(void);
- int DecodePosition(void);
- void Encode(void);
- void Decode(void);
- public:
- void Compress(const char *lpszInfile,const char *lpszOutfile);
- void UnCompress(const char *lpszInfile,const char *lpszOutfile);
- void Compress(const BYTE *pInBuffer,int nInLength,const BYTE * &pOutBuffer ,int &nOutLength);
- void UnCompress(const BYTE *pInBuffer,int nInLength,const BYTE * &pOutBuffer,int &nOutLength);
-
- void Release();
- };
- #endif
|