?? 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 + -