archive_ppmd_private.h revision 358088
1/* Ppmd.h -- PPMD codec common code 22010-03-12 : Igor Pavlov : Public domain 3This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 5#ifndef ARCHIVE_PPMD_PRIVATE_H_INCLUDED 6#define ARCHIVE_PPMD_PRIVATE_H_INCLUDED 7 8#ifndef __LIBARCHIVE_BUILD 9#error This header is only to be used internally to libarchive. 10#endif 11 12#include <stddef.h> 13 14#include "archive_read_private.h" 15 16/*** Begin defined in Types.h ***/ 17 18#if !defined(ZCONF_H) 19typedef unsigned char Byte; 20#endif 21typedef short Int16; 22typedef unsigned short UInt16; 23 24#ifdef _LZMA_UINT32_IS_ULONG 25typedef long Int32; 26typedef unsigned long UInt32; 27#else 28typedef int Int32; 29typedef unsigned int UInt32; 30#endif 31 32#ifdef _SZ_NO_INT_64 33 34/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. 35 NOTES: Some code will work incorrectly in that case! */ 36 37typedef long Int64; 38typedef unsigned long UInt64; 39 40#else 41 42#if defined(_MSC_VER) || defined(__BORLANDC__) 43typedef __int64 Int64; 44typedef unsigned __int64 UInt64; 45#define UINT64_CONST(n) n 46#else 47typedef long long int Int64; 48typedef unsigned long long int UInt64; 49#define UINT64_CONST(n) n ## ULL 50#endif 51 52#endif 53 54typedef int Bool; 55#define True 1 56#define False 0 57 58/* The following interfaces use first parameter as pointer to structure */ 59 60typedef struct 61{ 62 struct archive_read *a; 63 Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ 64} IByteIn; 65 66typedef struct 67{ 68 struct archive_write *a; 69 void (*Write)(void *p, Byte b); 70} IByteOut; 71 72/*** End defined in Types.h ***/ 73/*** Begin defined in CpuArch.h ***/ 74 75#if defined(_M_IX86) || defined(__i386__) 76#define MY_CPU_X86 77#endif 78 79#if defined(MY_CPU_X86) || defined(_M_ARM) 80#define MY_CPU_32BIT 81#endif 82 83#ifdef MY_CPU_32BIT 84#define PPMD_32BIT 85#endif 86 87/*** End defined in CpuArch.h ***/ 88 89#define PPMD_INT_BITS 7 90#define PPMD_PERIOD_BITS 7 91#define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS)) 92 93#define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift)) 94#define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2) 95#define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob)) 96#define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob)) 97 98#define PPMD_N1 4 99#define PPMD_N2 4 100#define PPMD_N3 4 101#define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4) 102#define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4) 103 104/* SEE-contexts for PPM-contexts with masked symbols */ 105typedef struct 106{ 107 UInt16 Summ; /* Freq */ 108 Byte Shift; /* Speed of Freq change; low Shift is for fast change */ 109 Byte Count; /* Count to next change of Shift */ 110} CPpmd_See; 111 112#define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \ 113 { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); } 114 115typedef struct 116{ 117 Byte Symbol; 118 Byte Freq; 119 UInt16 SuccessorLow; 120 UInt16 SuccessorHigh; 121} CPpmd_State; 122 123typedef 124 #ifdef PPMD_32BIT 125 CPpmd_State * 126 #else 127 UInt32 128 #endif 129 CPpmd_State_Ref; 130 131typedef 132 #ifdef PPMD_32BIT 133 void * 134 #else 135 UInt32 136 #endif 137 CPpmd_Void_Ref; 138 139typedef 140 #ifdef PPMD_32BIT 141 Byte * 142 #else 143 UInt32 144 #endif 145 CPpmd_Byte_Ref; 146 147#define PPMD_SetAllBitsIn256Bytes(p) \ 148 { unsigned j; for (j = 0; j < 256 / sizeof(p[0]); j += 8) { \ 149 p[j+7] = p[j+6] = p[j+5] = p[j+4] = p[j+3] = p[j+2] = p[j+1] = p[j+0] = ~(size_t)0; }} 150 151#endif 152