1 /* Ppmd7.h -- PPMdH compression codec 2 2010-03-12 : 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 __LIBARCHIVE_BUILD 10 #error This header is only to be used internally to libarchive. 11 #endif 12 13 #ifndef ARCHIVE_PPMD7_PRIVATE_H_INCLUDED 14 #define ARCHIVE_PPMD7_PRIVATE_H_INCLUDED 15 16 #include "archive_ppmd_private.h" 17 18 #define PPMD7_MIN_ORDER 2 19 #define PPMD7_MAX_ORDER 64 20 21 #define PPMD7_MIN_MEM_SIZE (1 << 11) 22 #define PPMD7_MAX_MEM_SIZE (0xFFFFFFFFu - 12 * 3) 23 24 struct CPpmd7_Context_; 25 26 typedef 27 #ifdef PPMD_32BIT 28 struct CPpmd7_Context_ * 29 #else 30 UInt32 31 #endif 32 CPpmd7_Context_Ref; 33 34 typedef struct CPpmd7_Context_ 35 { 36 UInt16 NumStats; 37 UInt16 SummFreq; 38 CPpmd_State_Ref Stats; 39 CPpmd7_Context_Ref Suffix; 40 } CPpmd7_Context; 41 42 #define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq) 43 44 typedef struct 45 { 46 CPpmd7_Context *MinContext, *MaxContext; 47 CPpmd_State *FoundState; 48 unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag; 49 Int32 RunLength, InitRL; /* must be 32-bit at least */ 50 51 UInt32 Size; 52 UInt32 GlueCount; 53 Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart; 54 UInt32 AlignOffset; 55 56 Byte Indx2Units[PPMD_NUM_INDEXES]; 57 Byte Units2Indx[128]; 58 CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES]; 59 Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256]; 60 CPpmd_See DummySee, See[25][16]; 61 UInt16 BinSumm[128][64]; 62 } CPpmd7; 63 64 /* ---------- Decode ---------- */ 65 66 typedef struct 67 { 68 UInt32 (*GetThreshold)(void *p, UInt32 total); 69 void (*Decode)(void *p, UInt32 start, UInt32 size); 70 UInt32 (*DecodeBit)(void *p, UInt32 size0); 71 } IPpmd7_RangeDec; 72 73 typedef struct 74 { 75 IPpmd7_RangeDec p; 76 UInt32 Range; 77 UInt32 Code; 78 UInt32 Low; 79 UInt32 Bottom; 80 IByteIn *Stream; 81 } CPpmd7z_RangeDec; 82 83 /* ---------- Encode ---------- */ 84 85 typedef struct 86 { 87 UInt64 Low; 88 UInt32 Range; 89 Byte Cache; 90 UInt64 CacheSize; 91 IByteOut *Stream; 92 } CPpmd7z_RangeEnc; 93 94 typedef struct 95 { 96 /* Base Functions */ 97 void (*Ppmd7_Construct)(CPpmd7 *p); 98 Bool (*Ppmd7_Alloc)(CPpmd7 *p, UInt32 size, ISzAlloc *alloc); 99 void (*Ppmd7_Free)(CPpmd7 *p, ISzAlloc *alloc); 100 void (*Ppmd7_Init)(CPpmd7 *p, unsigned maxOrder); 101 #define Ppmd7_WasAllocated(p) ((p)->Base != NULL) 102 103 /* Decode Functions */ 104 void (*Ppmd7z_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p); 105 void (*PpmdRAR_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p); 106 Bool (*Ppmd7z_RangeDec_Init)(CPpmd7z_RangeDec *p); 107 Bool (*PpmdRAR_RangeDec_Init)(CPpmd7z_RangeDec *p); 108 #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) 109 int (*Ppmd7_DecodeSymbol)(CPpmd7 *p, IPpmd7_RangeDec *rc); 110 111 /* Encode Functions */ 112 void (*Ppmd7z_RangeEnc_Init)(CPpmd7z_RangeEnc *p); 113 void (*Ppmd7z_RangeEnc_FlushData)(CPpmd7z_RangeEnc *p); 114 115 void (*Ppmd7_EncodeSymbol)(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol); 116 } IPpmd7; 117 118 extern const IPpmd7 __archive_ppmd7_functions; 119 #endif 120