1 /* Ppmd8.h -- PPMdI codec
2 2011-01-27 : Igor Pavlov : Public domain
4 PPMd var.I (2002): Dmitry Shkarin : Public domain
5 Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
7 #ifndef ARCHIVE_PPMD8_PRIVATE_H_INCLUDED
8 #define ARCHIVE_PPMD8_PRIVATE_H_INCLUDED
10 #include "archive_ppmd_private.h"
12 #define PPMD8_MIN_ORDER 2
13 #define PPMD8_MAX_ORDER 16
15 struct CPpmd8_Context_;
19 struct CPpmd8_Context_ *
27 typedef struct CPpmd8_Context_
32 CPpmd_State_Ref Stats;
33 CPpmd8_Context_Ref Suffix;
38 #define Ppmd8Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)
40 /* The BUG in Shkarin's code for FREEZE mode was fixed, but that fixed
41 code is not compatible with original code for some files compressed
42 in FREEZE mode. So we disable FREEZE mode support. */
46 PPMD8_RESTORE_METHOD_RESTART,
47 PPMD8_RESTORE_METHOD_CUT_OFF
48 #ifdef PPMD8_FREEZE_SUPPORT
49 , PPMD8_RESTORE_METHOD_FREEZE
55 CPpmd8_Context *MinContext, *MaxContext;
56 CPpmd_State *FoundState;
57 unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder;
58 Int32 RunLength, InitRL; /* must be 32-bit at least */
62 Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;
64 unsigned RestoreMethod;
76 Byte Indx2Units[PPMD_NUM_INDEXES];
78 CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES];
79 UInt32 Stamps[PPMD_NUM_INDEXES];
81 Byte NS2BSIndx[256], NS2Indx[260];
82 CPpmd_See DummySee, See[24][32];
83 UInt16 BinSumm[25][64];
86 void Ppmd8_Construct(CPpmd8 *p);
87 Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size);
88 void Ppmd8_Free(CPpmd8 *p);
89 void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod);
90 #define Ppmd8_WasAllocated(p) ((p)->Base != NULL)
93 /* ---------- Internal Functions ---------- */
95 extern const Byte PPMD8_kExpEscape[16];
98 #define Ppmd8_GetPtr(p, ptr) (ptr)
99 #define Ppmd8_GetContext(p, ptr) (ptr)
100 #define Ppmd8_GetStats(p, ctx) ((ctx)->Stats)
102 #define Ppmd8_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
103 #define Ppmd8_GetContext(p, offs) ((CPpmd8_Context *)Ppmd8_GetPtr((p), (offs)))
104 #define Ppmd8_GetStats(p, ctx) ((CPpmd_State *)Ppmd8_GetPtr((p), ((ctx)->Stats)))
107 void Ppmd8_Update1(CPpmd8 *p);
108 void Ppmd8_Update1_0(CPpmd8 *p);
109 void Ppmd8_Update2(CPpmd8 *p);
110 void Ppmd8_UpdateBin(CPpmd8 *p);
112 #define Ppmd8_GetBinSumm(p) \
113 &p->BinSumm[p->NS2Indx[Ppmd8Context_OneState(p->MinContext)->Freq - 1]][ \
114 p->NS2BSIndx[Ppmd8_GetContext(p, p->MinContext->Suffix)->NumStats] + \
115 p->PrevSuccess + p->MinContext->Flags + ((p->RunLength >> 26) & 0x20)]
117 CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked, UInt32 *scale);
120 /* ---------- Decode ---------- */
122 Bool Ppmd8_RangeDec_Init(CPpmd8 *p);
123 #define Ppmd8_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
124 int Ppmd8_DecodeSymbol(CPpmd8 *p); /* returns: -1 as EndMarker, -2 as DataError */
126 /* ---------- Encode ---------- */
128 #define Ppmd8_RangeEnc_Init(p) { (p)->Low = 0; (p)->Range = 0xFFFFFFFF; }
129 void Ppmd8_RangeEnc_FlushData(CPpmd8 *p);
130 void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol); /* symbol = -1 means EndMarker */
135 void (*Ppmd8_Construct)(CPpmd8 *p);
136 Bool (*Ppmd8_Alloc)(CPpmd8 *p, UInt32 size);
137 void (*Ppmd8_Free)(CPpmd8 *p);
138 void (*Ppmd8_Init)(CPpmd8 *p, unsigned max_order, unsigned restore_method);
139 #define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
141 /* Decode Functions */
142 int (*Ppmd8_RangeDec_Init)(CPpmd8 *p);
143 int (*Ppmd8_DecodeSymbol)(CPpmd8 *p);
146 extern const IPpmd8 __archive_ppmd8_functions;