📄 aricoder.h
字号:
/*****************************************************************************
AriCoder
--------
Revisions: 001
This is a class for compressing a giving block of data with the Arithmetic
compression algorithm which is patented !
The core algorithm is ripped out of "The Data Compression Book" by Mark Nelson.
The output buffers are freed by the class itself in its class destructor.
by yoda
WWW: y0da.cjb.net
E-mail: LordPE@gmx.net
You are allowed to use this source code in your own projects if you mention
my name.
*****************************************************************************/
#pragma once
#include <windows.h>
#include "ByteReader.h"
#include "ByteWriter.h"
//
// constants
//
#define ALPHABET_SIZE 257
//
// structures
//
typedef struct _ARI_SYM
{
WORD low;
WORD high;
WORD scale;
} ARI_SYM, *PARI_SYM;
//
// AriCoder class
//
class AriCoder
{
public:
__declspec( property( get=GetSymTblCntSize ) ) DWORD m_cbSymCntTbl;
AriCoder();
~AriCoder();
BOOL CompressData( PBYTE p, DWORD cb, PBYTE &pOut, DWORD &cbOut );
BOOL DecompressData( PBYTE p, DWORD cb, PBYTE &pOut, DWORD &cbOut );
DWORD GetSymTblCntSize() { return m_cbTable; };
private:
BYTE m_Occurrences[ALPHABET_SIZE];
UINT m_Totals[ALPHABET_SIZE + 1];
DWORD m_cbTable;
PBYTE m_pbyOutBuff;
LONG m_cbOutBuff;
WORD m_wLow;
WORD m_wHigh;
LONG m_cUnderflowBits;
WORD m_wCode;
void Init();
void Dispose();
void FreeOutBuff();
void CountSymbols( PBYTE p, DWORD cb );
void BuildTotals();
void BuildModelFromData( PBYTE p, DWORD cb );
DWORD EmitCounts( PBYTE p, DWORD cb );
DWORD GrabCounts( PBYTE p );
void InitEncoder();
void InitDecoder( ByteReader &reader );
void GetSymbolInfo( WORD symbol, struct _ARI_SYM &s );
void EncodeSymbol( ByteWriter &writer, ARI_SYM sym );
void FlushEncoder( ByteWriter &writer );
void GetSymbolScale( PARI_SYM pSym );
DWORD GetCurrentCount( ARI_SYM s );
UINT SymbolToIndex( DWORD dwCount, PARI_SYM sym );
void RemoveSymbolFromStream( ByteReader &reader, ARI_SYM sym );
};
typedef AriCoder *PAriCoder;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -