16c95142eSMartin Matuska /* Ppmd7.h -- PPMdH compression codec 26c95142eSMartin Matuska 2010-03-12 : Igor Pavlov : Public domain 36c95142eSMartin Matuska This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 46c95142eSMartin Matuska 56c95142eSMartin Matuska /* This code supports virtual RangeDecoder and includes the implementation 66c95142eSMartin Matuska of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H. 76c95142eSMartin Matuska If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */ 86c95142eSMartin Matuska 9*f9762417SMartin Matuska #ifndef ARCHIVE_PPMD7_PRIVATE_H_INCLUDED 10*f9762417SMartin Matuska #define ARCHIVE_PPMD7_PRIVATE_H_INCLUDED 11*f9762417SMartin Matuska 126c95142eSMartin Matuska #ifndef __LIBARCHIVE_BUILD 136c95142eSMartin Matuska #error This header is only to be used internally to libarchive. 146c95142eSMartin Matuska #endif 156c95142eSMartin Matuska 166c95142eSMartin Matuska #include "archive_ppmd_private.h" 176c95142eSMartin Matuska 186c95142eSMartin Matuska #define PPMD7_MIN_ORDER 2 196c95142eSMartin Matuska #define PPMD7_MAX_ORDER 64 206c95142eSMartin Matuska 216c95142eSMartin Matuska #define PPMD7_MIN_MEM_SIZE (1 << 11) 22cfa49a9bSMartin Matuska #define PPMD7_MAX_MEM_SIZE (0xFFFFFFFFu - 12 * 3) 236c95142eSMartin Matuska 246c95142eSMartin Matuska struct CPpmd7_Context_; 256c95142eSMartin Matuska 266c95142eSMartin Matuska typedef 276c95142eSMartin Matuska #ifdef PPMD_32BIT 286c95142eSMartin Matuska struct CPpmd7_Context_ * 296c95142eSMartin Matuska #else 306c95142eSMartin Matuska UInt32 316c95142eSMartin Matuska #endif 326c95142eSMartin Matuska CPpmd7_Context_Ref; 336c95142eSMartin Matuska 346c95142eSMartin Matuska typedef struct CPpmd7_Context_ 356c95142eSMartin Matuska { 366c95142eSMartin Matuska UInt16 NumStats; 376c95142eSMartin Matuska UInt16 SummFreq; 386c95142eSMartin Matuska CPpmd_State_Ref Stats; 396c95142eSMartin Matuska CPpmd7_Context_Ref Suffix; 406c95142eSMartin Matuska } CPpmd7_Context; 416c95142eSMartin Matuska 426c95142eSMartin Matuska #define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq) 436c95142eSMartin Matuska 446c95142eSMartin Matuska typedef struct 456c95142eSMartin Matuska { 466c95142eSMartin Matuska CPpmd7_Context *MinContext, *MaxContext; 476c95142eSMartin Matuska CPpmd_State *FoundState; 486c95142eSMartin Matuska unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag; 496c95142eSMartin Matuska Int32 RunLength, InitRL; /* must be 32-bit at least */ 506c95142eSMartin Matuska 516c95142eSMartin Matuska UInt32 Size; 526c95142eSMartin Matuska UInt32 GlueCount; 536c95142eSMartin Matuska Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart; 546c95142eSMartin Matuska UInt32 AlignOffset; 556c95142eSMartin Matuska 566c95142eSMartin Matuska Byte Indx2Units[PPMD_NUM_INDEXES]; 576c95142eSMartin Matuska Byte Units2Indx[128]; 586c95142eSMartin Matuska CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES]; 596c95142eSMartin Matuska Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256]; 606c95142eSMartin Matuska CPpmd_See DummySee, See[25][16]; 616c95142eSMartin Matuska UInt16 BinSumm[128][64]; 626c95142eSMartin Matuska } CPpmd7; 636c95142eSMartin Matuska 646c95142eSMartin Matuska /* ---------- Decode ---------- */ 656c95142eSMartin Matuska 666c95142eSMartin Matuska typedef struct 676c95142eSMartin Matuska { 686c95142eSMartin Matuska UInt32 (*GetThreshold)(void *p, UInt32 total); 696c95142eSMartin Matuska void (*Decode)(void *p, UInt32 start, UInt32 size); 706c95142eSMartin Matuska UInt32 (*DecodeBit)(void *p, UInt32 size0); 716c95142eSMartin Matuska } IPpmd7_RangeDec; 726c95142eSMartin Matuska 736c95142eSMartin Matuska typedef struct 746c95142eSMartin Matuska { 756c95142eSMartin Matuska IPpmd7_RangeDec p; 766c95142eSMartin Matuska UInt32 Range; 776c95142eSMartin Matuska UInt32 Code; 786c95142eSMartin Matuska UInt32 Low; 796c95142eSMartin Matuska UInt32 Bottom; 806c95142eSMartin Matuska IByteIn *Stream; 816c95142eSMartin Matuska } CPpmd7z_RangeDec; 826c95142eSMartin Matuska 836c95142eSMartin Matuska /* ---------- Encode ---------- */ 846c95142eSMartin Matuska 856c95142eSMartin Matuska typedef struct 866c95142eSMartin Matuska { 876c95142eSMartin Matuska UInt64 Low; 886c95142eSMartin Matuska UInt32 Range; 896c95142eSMartin Matuska Byte Cache; 906c95142eSMartin Matuska UInt64 CacheSize; 916c95142eSMartin Matuska IByteOut *Stream; 926c95142eSMartin Matuska } CPpmd7z_RangeEnc; 936c95142eSMartin Matuska 946c95142eSMartin Matuska typedef struct 956c95142eSMartin Matuska { 966c95142eSMartin Matuska /* Base Functions */ 976c95142eSMartin Matuska void (*Ppmd7_Construct)(CPpmd7 *p); 98a2a3407cSMartin Matuska Bool (*Ppmd7_Alloc)(CPpmd7 *p, UInt32 size); 99a2a3407cSMartin Matuska void (*Ppmd7_Free)(CPpmd7 *p); 1006c95142eSMartin Matuska void (*Ppmd7_Init)(CPpmd7 *p, unsigned maxOrder); 1016c95142eSMartin Matuska #define Ppmd7_WasAllocated(p) ((p)->Base != NULL) 1026c95142eSMartin Matuska 1036c95142eSMartin Matuska /* Decode Functions */ 1046c95142eSMartin Matuska void (*Ppmd7z_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p); 1056c95142eSMartin Matuska void (*PpmdRAR_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p); 1066c95142eSMartin Matuska Bool (*Ppmd7z_RangeDec_Init)(CPpmd7z_RangeDec *p); 1076c95142eSMartin Matuska Bool (*PpmdRAR_RangeDec_Init)(CPpmd7z_RangeDec *p); 1086c95142eSMartin Matuska #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) 1096c95142eSMartin Matuska int (*Ppmd7_DecodeSymbol)(CPpmd7 *p, IPpmd7_RangeDec *rc); 1106c95142eSMartin Matuska 1116c95142eSMartin Matuska /* Encode Functions */ 1126c95142eSMartin Matuska void (*Ppmd7z_RangeEnc_Init)(CPpmd7z_RangeEnc *p); 1136c95142eSMartin Matuska void (*Ppmd7z_RangeEnc_FlushData)(CPpmd7z_RangeEnc *p); 1146c95142eSMartin Matuska 1156c95142eSMartin Matuska void (*Ppmd7_EncodeSymbol)(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol); 1166c95142eSMartin Matuska } IPpmd7; 1176c95142eSMartin Matuska 1186c95142eSMartin Matuska extern const IPpmd7 __archive_ppmd7_functions; 1196c95142eSMartin Matuska #endif 120