~ubuntu-branches/ubuntu/vivid/unrar-nonfree/vivid

« back to all changes in this revision

Viewing changes to model.hpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2015-02-03 12:58:01 UTC
  • mfrom: (1.1.18) (5.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20150203125801-od6ev8cqy1er51vz
Tags: 1:5.2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include "coder.hpp"
5
5
#include "suballoc.hpp"
6
6
 
7
 
const int MAX_O=64;                   /* maximum allowed model order */
8
 
 
9
 
const int INT_BITS=7, PERIOD_BITS=7, TOT_BITS=INT_BITS+PERIOD_BITS,
10
 
          INTERVAL=1 << INT_BITS, BIN_SCALE=1 << TOT_BITS, MAX_FREQ=124;
11
 
 
12
 
#ifndef STRICT_ALIGNMENT_REQUIRED
 
7
#ifdef ALLOW_MISALIGNED
13
8
#pragma pack(1)
14
9
#endif
15
10
 
16
 
struct SEE2_CONTEXT
 
11
struct RARPPM_DEF
 
12
{
 
13
  static const int INT_BITS=7, PERIOD_BITS=7, TOT_BITS=INT_BITS+PERIOD_BITS,
 
14
    INTERVAL=1 << INT_BITS, BIN_SCALE=1 << TOT_BITS, MAX_FREQ=124;
 
15
};
 
16
 
 
17
struct RARPPM_SEE2_CONTEXT : RARPPM_DEF
17
18
{ // SEE-contexts for PPM-contexts with masked symbols
18
19
  ushort Summ;
19
20
  byte Shift, Count;
40
41
 
41
42
 
42
43
class ModelPPM;
43
 
struct PPM_CONTEXT;
 
44
struct RARPPM_CONTEXT;
44
45
 
45
 
struct STATE
 
46
struct RARPPM_STATE
46
47
{
47
48
  byte Symbol;
48
49
  byte Freq;
49
 
  PPM_CONTEXT* Successor;
50
 
};
51
 
 
52
 
struct FreqData
53
 
{
54
 
  ushort SummFreq;
55
 
  STATE _PACK_ATTR * Stats;
56
 
};
57
 
 
58
 
struct PPM_CONTEXT 
 
50
  RARPPM_CONTEXT* Successor;
 
51
};
 
52
 
 
53
 
 
54
struct RARPPM_CONTEXT : RARPPM_DEF
59
55
{
60
56
    ushort NumStats;
 
57
 
 
58
    struct FreqData
 
59
    {
 
60
      ushort SummFreq;
 
61
      RARPPM_STATE RARPPM_PACK_ATTR * Stats;
 
62
    };
 
63
    
61
64
    union
62
65
    {
63
66
      FreqData U;
64
 
      STATE OneState;
 
67
      RARPPM_STATE OneState;
65
68
    };
66
69
 
67
 
    PPM_CONTEXT* Suffix;
 
70
    RARPPM_CONTEXT* Suffix;
68
71
    inline void encodeBinSymbol(ModelPPM *Model,int symbol);  // MaxOrder:
69
72
    inline void encodeSymbol1(ModelPPM *Model,int symbol);    //  ABCD    context
70
73
    inline void encodeSymbol2(ModelPPM *Model,int symbol);    //   BCD    suffix
71
74
    inline void decodeBinSymbol(ModelPPM *Model);  //   BCDE   successor
72
75
    inline bool decodeSymbol1(ModelPPM *Model);    // other orders:
73
76
    inline bool decodeSymbol2(ModelPPM *Model);    //   BCD    context
74
 
    inline void update1(ModelPPM *Model,STATE* p); //    CD    suffix
75
 
    inline void update2(ModelPPM *Model,STATE* p); //   BCDE   successor
 
77
    inline void update1(ModelPPM *Model,RARPPM_STATE* p); //    CD    suffix
 
78
    inline void update2(ModelPPM *Model,RARPPM_STATE* p); //   BCDE   successor
76
79
    void rescale(ModelPPM *Model);
77
 
    inline PPM_CONTEXT* createChild(ModelPPM *Model,STATE* pStats,STATE& FirstState);
78
 
    inline SEE2_CONTEXT* makeEscFreq2(ModelPPM *Model,int Diff);
 
80
    inline RARPPM_CONTEXT* createChild(ModelPPM *Model,RARPPM_STATE* pStats,RARPPM_STATE& FirstState);
 
81
    inline RARPPM_SEE2_CONTEXT* makeEscFreq2(ModelPPM *Model,int Diff);
79
82
};
80
83
 
81
 
#ifndef STRICT_ALIGNMENT_REQUIRED
 
84
#ifdef ALLOW_MISALIGNED
82
85
#ifdef _AIX
83
86
#pragma pack(pop)
84
87
#else
86
89
#endif
87
90
#endif
88
91
 
89
 
const uint UNIT_SIZE=Max(sizeof(PPM_CONTEXT),sizeof(RAR_MEM_BLK));
90
 
const uint FIXED_UNIT_SIZE=12;
91
 
 
92
 
/*
93
 
inline PPM_CONTEXT::PPM_CONTEXT(STATE* pStats,PPM_CONTEXT* ShorterContext):
94
 
        NumStats(1), Suffix(ShorterContext) { pStats->Successor=this; }
95
 
inline PPM_CONTEXT::PPM_CONTEXT(): NumStats(0) {}
96
 
*/
97
 
 
98
 
template <class T>
99
 
inline void _PPMD_SWAP(T& t1,T& t2) { T tmp=t1; t1=t2; t2=tmp; }
100
 
 
101
 
 
102
 
class ModelPPM
 
92
class ModelPPM : RARPPM_DEF
103
93
{
104
94
  private:
105
 
    friend struct PPM_CONTEXT;
106
 
    
107
 
    SEE2_CONTEXT SEE2Cont[25][16], DummySEE2Cont;
108
 
    
109
 
    struct PPM_CONTEXT *MinContext, *MedContext, *MaxContext;
110
 
    STATE* FoundState;      // found next state transition
 
95
    friend struct RARPPM_CONTEXT;
 
96
    
 
97
    RARPPM_SEE2_CONTEXT SEE2Cont[25][16], DummySEE2Cont;
 
98
    
 
99
    struct RARPPM_CONTEXT *MinContext, *MedContext, *MaxContext;
 
100
    RARPPM_STATE* FoundState;      // found next state transition
111
101
    int NumMasked, InitEsc, OrderFall, MaxOrder, RunLength, InitRL;
112
102
    byte CharMask[256], NS2Indx[256], NS2BSIndx[256], HB2Flag[256];
113
103
    byte EscCount, PrevSuccess, HiBitsFlag;
118
108
 
119
109
    void RestartModelRare();
120
110
    void StartModelRare(int MaxOrder);
121
 
    inline PPM_CONTEXT* CreateSuccessors(bool Skip,STATE* p1);
 
111
    inline RARPPM_CONTEXT* CreateSuccessors(bool Skip,RARPPM_STATE* p1);
122
112
 
123
113
    inline void UpdateModel();
124
114
    inline void ClearMask();