unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

model.hpp
Go to the documentation of this file.
1#ifndef _RAR_PPMMODEL_
2#define _RAR_PPMMODEL_
3
4#include "coder.hpp"
5#include "suballoc.hpp"
6
7#ifdef ALLOW_MISALIGNED
8#pragma pack(1)
9#endif
10
12{
15};
16
18{ // SEE-contexts for PPM-contexts with masked symbols
20 byte Shift, Count;
21 void init(int InitVal)
22 {
23 Summ=InitVal << (Shift=PERIOD_BITS-4);
24 Count=4;
25 }
27 {
28 uint RetVal=GET_SHORT16(Summ) >> Shift;
29 Summ -= RetVal;
30 return RetVal+(RetVal == 0);
31 }
32 void update()
33 {
34 if (Shift < PERIOD_BITS && --Count == 0)
35 {
36 Summ += Summ;
37 Count=3 << Shift++;
38 }
39 }
40};
41
42
43class ModelPPM;
44struct RARPPM_CONTEXT;
45
47{
48 byte Symbol;
49 byte Freq;
51};
52
53
55{
57
58 struct FreqData
59 {
62 };
63
64 union
65 {
68 };
69
71 inline void encodeBinSymbol(ModelPPM *Model,int symbol); // MaxOrder:
72 inline void encodeSymbol1(ModelPPM *Model,int symbol); // ABCD context
73 inline void encodeSymbol2(ModelPPM *Model,int symbol); // BCD suffix
74 inline void decodeBinSymbol(ModelPPM *Model); // BCDE successor
75 inline bool decodeSymbol1(ModelPPM *Model); // other orders:
76 inline bool decodeSymbol2(ModelPPM *Model); // BCD context
77 inline void update1(ModelPPM *Model,RARPPM_STATE* p); // CD suffix
78 inline void update2(ModelPPM *Model,RARPPM_STATE* p); // BCDE successor
79 void rescale(ModelPPM *Model);
80 inline RARPPM_CONTEXT* createChild(ModelPPM *Model,RARPPM_STATE* pStats,RARPPM_STATE& FirstState);
81 inline RARPPM_SEE2_CONTEXT* makeEscFreq2(ModelPPM *Model,int Diff);
82};
83
84#ifdef ALLOW_MISALIGNED
85#ifdef _AIX
86#pragma pack(pop)
87#else
88#pragma pack()
89#endif
90#endif
91
93{
94 private:
95 friend struct RARPPM_CONTEXT;
96
98
100 RARPPM_STATE* FoundState; // found next state transition
102 byte CharMask[256], NS2Indx[256], NS2BSIndx[256], HB2Flag[256];
104 ushort BinSumm[128][64]; // binary SEE-contexts
105
108
109 void RestartModelRare();
110 void StartModelRare(int MaxOrder);
111 inline RARPPM_CONTEXT* CreateSuccessors(bool Skip,RARPPM_STATE* p1);
112
113 inline void UpdateModel();
114 inline void ClearMask();
115 public:
116 ModelPPM();
117 void CleanUp(); // reset PPM variables after data error
118 bool DecodeInit(Unpack *UnpackRead,int &EscChar);
119 int DecodeChar();
120};
121
122#endif
int MaxOrder
Definition: model.hpp:101
void StartModelRare(int MaxOrder)
Definition: model.cpp:74
RARPPM_SEE2_CONTEXT SEE2Cont[25][16]
Definition: model.hpp:97
int OrderFall
Definition: model.hpp:101
SubAllocator SubAlloc
Definition: model.hpp:107
void UpdateModel()
Definition: model.cpp:246
byte HB2Flag[256]
Definition: model.hpp:102
byte CharMask[256]
Definition: model.hpp:102
byte NS2BSIndx[256]
Definition: model.hpp:102
RangeCoder Coder
Definition: model.hpp:106
int InitRL
Definition: model.hpp:101
ModelPPM()
Definition: model.cpp:30
void CleanUp()
Definition: model.cpp:561
int NumMasked
Definition: model.hpp:101
bool DecodeInit(Unpack *UnpackRead, int &EscChar)
Definition: model.cpp:569
int DecodeChar()
Definition: model.cpp:600
struct RARPPM_CONTEXT * MinContext
Definition: model.hpp:99
RARPPM_CONTEXT * CreateSuccessors(bool Skip, RARPPM_STATE *p1)
Definition: model.cpp:171
int InitEsc
Definition: model.hpp:101
byte PrevSuccess
Definition: model.hpp:103
struct RARPPM_CONTEXT * MaxContext
Definition: model.hpp:99
struct RARPPM_CONTEXT * MedContext
Definition: model.hpp:99
int RunLength
Definition: model.hpp:101
byte HiBitsFlag
Definition: model.hpp:103
ushort BinSumm[128][64]
Definition: model.hpp:104
RARPPM_STATE * FoundState
Definition: model.hpp:100
RARPPM_SEE2_CONTEXT DummySEE2Cont
Definition: model.hpp:97
byte EscCount
Definition: model.hpp:103
void RestartModelRare()
Definition: model.cpp:38
byte NS2Indx[256]
Definition: model.hpp:102
void ClearMask()
Definition: model.cpp:550
unsigned int uint
Definition: rartypes.hpp:8
uint16_t ushort
Definition: rartypes.hpp:7
#define GET_SHORT16(x)
Definition: rartypes.hpp:16
RARPPM_STATE * Stats
Definition: model.hpp:61
RARPPM_STATE OneState
Definition: model.hpp:67
RARPPM_SEE2_CONTEXT * makeEscFreq2(ModelPPM *Model, int Diff)
Definition: model.cpp:468
RARPPM_CONTEXT * createChild(ModelPPM *Model, RARPPM_STATE *pStats, RARPPM_STATE &FirstState)
Definition: model.cpp:15
void rescale(ModelPPM *Model)
Definition: model.cpp:119
void decodeBinSymbol(ModelPPM *Model)
Definition: model.cpp:364
ushort NumStats
Definition: model.hpp:56
void encodeSymbol2(ModelPPM *Model, int symbol)
void update2(ModelPPM *Model, RARPPM_STATE *p)
Definition: model.cpp:457
FreqData U
Definition: model.hpp:66
void encodeBinSymbol(ModelPPM *Model, int symbol)
RARPPM_CONTEXT * Suffix
Definition: model.hpp:70
void encodeSymbol1(ModelPPM *Model, int symbol)
bool decodeSymbol2(ModelPPM *Model)
Definition: model.cpp:490
bool decodeSymbol1(ModelPPM *Model)
Definition: model.cpp:412
void update1(ModelPPM *Model, RARPPM_STATE *p)
Definition: model.cpp:396
static const int INT_BITS
Definition: model.hpp:13
static const int INTERVAL
Definition: model.hpp:14
static const int TOT_BITS
Definition: model.hpp:13
static const int PERIOD_BITS
Definition: model.hpp:13
static const int BIN_SCALE
Definition: model.hpp:14
static const int MAX_FREQ
Definition: model.hpp:14
void init(int InitVal)
Definition: model.hpp:21
byte Freq
Definition: model.hpp:49
byte Symbol
Definition: model.hpp:48
RARPPM_CONTEXT * Successor
Definition: model.hpp:50
#define RARPPM_PACK_ATTR
Definition: suballoc.hpp:13