File indexing completed on 2025-02-02 04:25:59
0001 /* Ppmd.h -- PPMD codec common code 0002 2013-01-18 : Igor Pavlov : Public domain 0003 This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 0004 0005 #ifndef __PPMD_H 0006 #define __PPMD_H 0007 0008 #include "CpuArch.h" 0009 0010 EXTERN_C_BEGIN 0011 0012 #ifdef MY_CPU_32BIT 0013 #define PPMD_32BIT 0014 #endif 0015 0016 #define PPMD_INT_BITS 7 0017 #define PPMD_PERIOD_BITS 7 0018 #define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS)) 0019 0020 #define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift)) 0021 #define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2) 0022 #define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob)) 0023 #define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob)) 0024 0025 #define PPMD_N1 4 0026 #define PPMD_N2 4 0027 #define PPMD_N3 4 0028 #define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4) 0029 #define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4) 0030 0031 #pragma pack(push, 1) 0032 /* Most compilers works OK here even without #pragma pack(push, 1), but some GCC compilers need it. */ 0033 0034 /* SEE-contexts for PPM-contexts with masked symbols */ 0035 typedef struct 0036 { 0037 UInt16 Summ; /* Freq */ 0038 Byte Shift; /* Speed of Freq change; low Shift is for fast change */ 0039 Byte Count; /* Count to next change of Shift */ 0040 } CPpmd_See; 0041 0042 #define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \ 0043 { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); } 0044 0045 typedef struct 0046 { 0047 Byte Symbol; 0048 Byte Freq; 0049 UInt16 SuccessorLow; 0050 UInt16 SuccessorHigh; 0051 } CPpmd_State; 0052 0053 #pragma pack(pop) 0054 0055 typedef 0056 #ifdef PPMD_32BIT 0057 CPpmd_State * 0058 #else 0059 UInt32 0060 #endif 0061 CPpmd_State_Ref; 0062 0063 typedef 0064 #ifdef PPMD_32BIT 0065 void * 0066 #else 0067 UInt32 0068 #endif 0069 CPpmd_Void_Ref; 0070 0071 typedef 0072 #ifdef PPMD_32BIT 0073 Byte * 0074 #else 0075 UInt32 0076 #endif 0077 CPpmd_Byte_Ref; 0078 0079 #define PPMD_SetAllBitsIn256Bytes(p) \ 0080 { unsigned i; for (i = 0; i < 256 / sizeof(p[0]); i += 8) { \ 0081 p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }} 0082 0083 EXTERN_C_END 0084 0085 #endif