Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Ppmd7.h
Go to the documentation of this file.
1 /* Ppmd7.h -- PPMdH compression codec
2 2017-04-03 : Igor Pavlov : Public domain
3 This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
4 
5 /* This code supports virtual RangeDecoder and includes the implementation
6 of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H.
7 If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */
8 
9 #ifndef __PPMD7_H
10 #define __PPMD7_H
11 
12 #include "Ppmd.h"
13 
15 
16 #define PPMD7_MIN_ORDER 2
17 #define PPMD7_MAX_ORDER 64
18 
19 #define PPMD7_MIN_MEM_SIZE (1 << 11)
20 #define PPMD7_MAX_MEM_SIZE (0xFFFFFFFF - 12 * 3)
21 
23 
24 typedef
25  #ifdef PPMD_32BIT
26  struct CPpmd7_Context_ *
27  #else
28  UInt32
29  #endif
31 
32 typedef struct CPpmd7_Context_
33 {
39 
40 #define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)
41 
42 typedef struct
43 {
44  CPpmd7_Context *MinContext, *MaxContext;
46  unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag;
47  Int32 RunLength, InitRL; /* must be 32-bit at least */
48 
51  Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;
53 
54  Byte Indx2Units[PPMD_NUM_INDEXES];
55  Byte Units2Indx[128];
57  Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256];
58  CPpmd_See DummySee, See[25][16];
59  UInt16 BinSumm[128][64];
60 } CPpmd7;
61 
62 void Ppmd7_Construct(CPpmd7 *p);
63 Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc);
64 void Ppmd7_Free(CPpmd7 *p, ISzAllocPtr alloc);
65 void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder);
66 #define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
67 
68 
69 /* ---------- Internal Functions ---------- */
70 
71 extern const Byte PPMD7_kExpEscape[16];
72 
73 #ifdef PPMD_32BIT
74  #define Ppmd7_GetPtr(p, ptr) (ptr)
75  #define Ppmd7_GetContext(p, ptr) (ptr)
76  #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats)
77 #else
78  #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
79  #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs)))
80  #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats)))
81 #endif
82 
83 void Ppmd7_Update1(CPpmd7 *p);
84 void Ppmd7_Update1_0(CPpmd7 *p);
85 void Ppmd7_Update2(CPpmd7 *p);
86 void Ppmd7_UpdateBin(CPpmd7 *p);
87 
88 #define Ppmd7_GetBinSumm(p) \
89  &p->BinSumm[(size_t)(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
90  p->NS2BSIndx[(size_t)Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \
91  (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \
92  2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \
93  ((p->RunLength >> 26) & 0x20)]
94 
95 CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale);
96 
97 
98 /* ---------- Decode ---------- */
99 
101 
103 {
105  void (*Decode)(const IPpmd7_RangeDec *p, UInt32 start, UInt32 size);
106  UInt32 (*DecodeBit)(const IPpmd7_RangeDec *p, UInt32 size0);
107 };
108 
109 typedef struct
110 {
116 
119 #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
120 
121 int Ppmd7_DecodeSymbol(CPpmd7 *p, const IPpmd7_RangeDec *rc);
122 
123 
124 /* ---------- Encode ---------- */
125 
126 typedef struct
127 {
134 
137 
138 void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol);
139 
141 
142 #endif