📄 adaarithcoder.h
字号:
// AdaArithCoder.h : 自适应算术编码器和解码器的类定义
//
// Author: Shen Hongwei
// Date: Nov.10, 2005
// Location: Beijing, China
//
#pragma once
#include "DataCompression.h"
//#define BYTE_TAG
#define SHORT_TAG
// #define LONG_TAG
#ifdef BYTE_TAG
typedef unsigned char TagType;
#define MSB_MASK 0x80
#define MSB2_MASK 0x40
#define TAG_LENG 8
#define LSB_MASK 0x01
#define AND_LSB_MASK 0xfe
#define TOP_VALUE 0xff
#endif
#ifdef SHORT_TAG
typedef unsigned short TagType;
#define MSB_MASK 0x8000
#define MSB2_MASK 0x4000
#define TAG_LENG 16
#define LSB_MASK 0x0001
#define AND_LSB_MASK 0xfffe
#define TOP_VALUE 0xffff
#endif
#ifdef LONG_TAG
typedef unsigned long TagType;
#define MSB_MASK 0x80000000
#define MSB2_MASK 0x40000000
#define TAG_LENG 32
#define LSB_MASK 0x00000001
#define AND_LSB_MASK 0xfffffffe
#define TOP_VALUE 0xffffffff
#endif
class AdaArithCoder :
public Coder
{
public:
AdaArithCoder(void);
~AdaArithCoder(void);
void Init(BitIO * bit_in, BitIO * bit_out);
void Init(BitIO * in, BitIO * out, unsigned long i_leng);
int Run(void);
bool GenNextCode();
void SetDebugMode(int mode);
private:
const static tbSize = 256; // unsigned char的表示范围
const static tagSize = sizeof(TagType);
TagType L, U;
TagType CumCount[tbSize+1];
TagType TotalCount;
void Count(unsigned char c); // 统计各个字符出现的次数
inline bool CheckE3(void) { return(!(L&MSB_MASK) && L&MSB2_MASK && U&MSB_MASK && !(U&MSB2_MASK)); }; // 检查是否满足condition 3
inline char MSB(TagType number) { return ( (number & MSB_MASK) >> (TAG_LENG-1) ); } // 取number的最高位
};
class AdaArithDecoder :
public Coder
{
public:
AdaArithDecoder(void);
~AdaArithDecoder(void);
bool GenNextCode();
void Init(BitIO * bit_in, BitIO * bit_out);
void Init(BitIO * in, BitIO * out, unsigned long i_leng);
int Run(void);
void SetDebugMode(int mode);
private:
const static tbSize = 256; // unsigned char的表示范围
const static tagSize = sizeof(TagType);
TagType L, U;
TagType CumCount[tbSize+1];
TagType TotalCount;
bool ReadATag(TagType & tag);
void Count(unsigned char c); // 统计各个字符出现的次数
void CompareWithOriginal(char * value); // for debug
inline bool CheckE3(void) { return(!(L&MSB_MASK) && L&MSB2_MASK && U&MSB_MASK && !(U&MSB2_MASK)); }; // 检查是否满足condition 3
inline char MSB(TagType number) { return ( (number & MSB_MASK) >> (TAG_LENG-1) ); } // 取number的最高位
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -