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 File Reference
#include "Ppmd.h"
+ Include dependency graph for Ppmd7.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CPpmd7_Context_
 
struct  CPpmd7
 
struct  IPpmd7_RangeDec
 
struct  CPpmd7z_RangeDec
 
struct  CPpmd7z_RangeEnc
 

Macros

#define PPMD7_MIN_ORDER   2
 
#define PPMD7_MAX_ORDER   64
 
#define PPMD7_MIN_MEM_SIZE   (1 << 11)
 
#define PPMD7_MAX_MEM_SIZE   (0xFFFFFFFF - 12 * 3)
 
#define Ppmd7Context_OneState(p)   ((CPpmd_State *)&(p)->SummFreq)
 
#define Ppmd7_WasAllocated(p)   ((p)->Base != NULL)
 
#define Ppmd7_GetPtr(p, offs)   ((void *)((p)->Base + (offs)))
 
#define Ppmd7_GetContext(p, offs)   ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs)))
 
#define Ppmd7_GetStats(p, ctx)   ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats)))
 
#define Ppmd7_GetBinSumm(p)
 
#define Ppmd7z_RangeDec_IsFinishedOK(p)   ((p)->Code == 0)
 

Typedefs

typedef UInt32 CPpmd7_Context_Ref
 
typedef struct CPpmd7_Context_ CPpmd7_Context
 
typedef struct IPpmd7_RangeDec IPpmd7_RangeDec
 

Functions

void Ppmd7_Construct (CPpmd7 *p)
 
Bool Ppmd7_Alloc (CPpmd7 *p, UInt32 size, ISzAllocPtr alloc)
 
void Ppmd7_Free (CPpmd7 *p, ISzAllocPtr alloc)
 
void Ppmd7_Init (CPpmd7 *p, unsigned maxOrder)
 
void Ppmd7_Update1 (CPpmd7 *p)
 
void Ppmd7_Update1_0 (CPpmd7 *p)
 
void Ppmd7_Update2 (CPpmd7 *p)
 
void Ppmd7_UpdateBin (CPpmd7 *p)
 
CPpmd_SeePpmd7_MakeEscFreq (CPpmd7 *p, unsigned numMasked, UInt32 *scale)
 
void Ppmd7z_RangeDec_CreateVTable (CPpmd7z_RangeDec *p)
 
Bool Ppmd7z_RangeDec_Init (CPpmd7z_RangeDec *p)
 
int Ppmd7_DecodeSymbol (CPpmd7 *p, const IPpmd7_RangeDec *rc)
 
void Ppmd7z_RangeEnc_Init (CPpmd7z_RangeEnc *p)
 
void Ppmd7z_RangeEnc_FlushData (CPpmd7z_RangeEnc *p)
 
void Ppmd7_EncodeSymbol (CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol)
 

Variables

const Byte PPMD7_kExpEscape [16]
 

Macro Definition Documentation

#define Ppmd7_GetBinSumm (   p)
Value:
&p->BinSumm[(size_t)(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
p->NS2BSIndx[(size_t)Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \
(p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \
2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \
((p->RunLength >> 26) & 0x20)]

Definition at line 88 of file Ppmd7.h.

#define Ppmd7_GetContext (   p,
  offs 
)    ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs)))

Definition at line 79 of file Ppmd7.h.

#define Ppmd7_GetPtr (   p,
  offs 
)    ((void *)((p)->Base + (offs)))

Definition at line 78 of file Ppmd7.h.

#define Ppmd7_GetStats (   p,
  ctx 
)    ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats)))

Definition at line 80 of file Ppmd7.h.

#define PPMD7_MAX_MEM_SIZE   (0xFFFFFFFF - 12 * 3)

Definition at line 20 of file Ppmd7.h.

#define PPMD7_MAX_ORDER   64

Definition at line 17 of file Ppmd7.h.

#define PPMD7_MIN_MEM_SIZE   (1 << 11)

Definition at line 19 of file Ppmd7.h.

#define PPMD7_MIN_ORDER   2

Definition at line 16 of file Ppmd7.h.

#define Ppmd7_WasAllocated (   p)    ((p)->Base != NULL)

Definition at line 66 of file Ppmd7.h.

#define Ppmd7Context_OneState (   p)    ((CPpmd_State *)&(p)->SummFreq)

Definition at line 40 of file Ppmd7.h.

#define Ppmd7z_RangeDec_IsFinishedOK (   p)    ((p)->Code == 0)

Definition at line 119 of file Ppmd7.h.

Typedef Documentation

Definition at line 22 of file Ppmd7.h.

Definition at line 100 of file Ppmd7.h.

Function Documentation

Bool Ppmd7_Alloc ( CPpmd7 p,
UInt32  size,
ISzAllocPtr  alloc 
)

Definition at line 98 of file Ppmd7.c.

99 {
100  if (!p->Base || p->Size != size)
101  {
102  size_t size2;
103  Ppmd7_Free(p, alloc);
104  size2 = 0
105  #ifndef PPMD_32BIT
106  + UNIT_SIZE
107  #endif
108  ;
109  p->AlignOffset =
110  #ifdef PPMD_32BIT
111  (4 - size) & 3;
112  #else
113  4 - (size & 3);
114  #endif
115  if ((p->Base = (Byte *)ISzAlloc_Alloc(alloc, p->AlignOffset + size + size2)) == 0)
116  return False;
117  p->Size = size;
118  }
119  return True;
120 }

+ Here is the caller graph for this function:

void Ppmd7_Construct ( CPpmd7 p)

Definition at line 60 of file Ppmd7.c.

61 {
62  unsigned i, k, m;
63 
64  p->Base = 0;
65 
66  for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
67  {
68  unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
69  do { p->Units2Indx[k++] = (Byte)i; } while (--step);
70  p->Indx2Units[i] = (Byte)k;
71  }
72 
73  p->NS2BSIndx[0] = (0 << 1);
74  p->NS2BSIndx[1] = (1 << 1);
75  memset(p->NS2BSIndx + 2, (2 << 1), 9);
76  memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11);
77 
78  for (i = 0; i < 3; i++)
79  p->NS2Indx[i] = (Byte)i;
80  for (m = i, k = 1; i < 256; i++)
81  {
82  p->NS2Indx[i] = (Byte)m;
83  if (--k == 0)
84  k = (++m) - 2;
85  }
86 
87  memset(p->HB2Flag, 0, 0x40);
88  memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40);
89 }

+ Here is the caller graph for this function:

int Ppmd7_DecodeSymbol ( CPpmd7 p,
const IPpmd7_RangeDec rc 
)

Definition at line 83 of file Ppmd7Dec.c.

84 {
85  size_t charMask[256 / sizeof(size_t)];
86  if (p->MinContext->NumStats != 1)
87  {
89  unsigned i;
90  UInt32 count, hiCnt;
91  if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq))
92  {
93  Byte symbol;
94  rc->Decode(rc, 0, s->Freq);
95  p->FoundState = s;
96  symbol = s->Symbol;
97  Ppmd7_Update1_0(p);
98  return symbol;
99  }
100  p->PrevSuccess = 0;
101  i = p->MinContext->NumStats - 1;
102  do
103  {
104  if ((hiCnt += (++s)->Freq) > count)
105  {
106  Byte symbol;
107  rc->Decode(rc, hiCnt - s->Freq, s->Freq);
108  p->FoundState = s;
109  symbol = s->Symbol;
110  Ppmd7_Update1(p);
111  return symbol;
112  }
113  }
114  while (--i);
115  if (count >= p->MinContext->SummFreq)
116  return -2;
117  p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];
118  rc->Decode(rc, hiCnt, p->MinContext->SummFreq - hiCnt);
119  PPMD_SetAllBitsIn256Bytes(charMask);
120  MASK(s->Symbol) = 0;
121  i = p->MinContext->NumStats - 1;
122  do { MASK((--s)->Symbol) = 0; } while (--i);
123  }
124  else
125  {
126  UInt16 *prob = Ppmd7_GetBinSumm(p);
127  if (rc->DecodeBit(rc, *prob) == 0)
128  {
129  Byte symbol;
130  *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
131  symbol = (p->FoundState = Ppmd7Context_OneState(p->MinContext))->Symbol;
132  Ppmd7_UpdateBin(p);
133  return symbol;
134  }
135  *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
136  p->InitEsc = PPMD7_kExpEscape[*prob >> 10];
137  PPMD_SetAllBitsIn256Bytes(charMask);
138  MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0;
139  p->PrevSuccess = 0;
140  }
141  for (;;)
142  {
143  CPpmd_State *ps[256], *s;
144  UInt32 freqSum, count, hiCnt;
145  CPpmd_See *see;
146  unsigned i, num, numMasked = p->MinContext->NumStats;
147  do
148  {
149  p->OrderFall++;
150  if (!p->MinContext->Suffix)
151  return -1;
153  }
154  while (p->MinContext->NumStats == numMasked);
155  hiCnt = 0;
156  s = Ppmd7_GetStats(p, p->MinContext);
157  i = 0;
158  num = p->MinContext->NumStats - numMasked;
159  do
160  {
161  int k = (int)(MASK(s->Symbol));
162  hiCnt += (s->Freq & k);
163  ps[i] = s++;
164  i -= k;
165  }
166  while (i != num);
167 
168  see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum);
169  freqSum += hiCnt;
170  count = rc->GetThreshold(rc, freqSum);
171 
172  if (count < hiCnt)
173  {
174  Byte symbol;
175  CPpmd_State **pps = ps;
176  for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);
177  s = *pps;
178  rc->Decode(rc, hiCnt - s->Freq, s->Freq);
179  Ppmd_See_Update(see);
180  p->FoundState = s;
181  symbol = s->Symbol;
182  Ppmd7_Update2(p);
183  return symbol;
184  }
185  if (count >= freqSum)
186  return -2;
187  rc->Decode(rc, hiCnt, freqSum - hiCnt);
188  see->Summ = (UInt16)(see->Summ + freqSum);
189  do { MASK(ps[--i]->Symbol) = 0; } while (i != 0);
190  }
191 }

+ Here is the caller graph for this function:

void Ppmd7_EncodeSymbol ( CPpmd7 p,
CPpmd7z_RangeEnc rc,
int  symbol 
)
void Ppmd7_Free ( CPpmd7 p,
ISzAllocPtr  alloc 
)

Definition at line 91 of file Ppmd7.c.

92 {
93  ISzAlloc_Free(alloc, p->Base);
94  p->Size = 0;
95  p->Base = 0;
96 }

+ Here is the caller graph for this function:

void Ppmd7_Init ( CPpmd7 p,
unsigned  maxOrder 
)

Definition at line 336 of file Ppmd7.c.

337 {
338  p->MaxOrder = maxOrder;
339  RestartModel(p);
341  p->DummySee.Summ = 0; /* unused */
342  p->DummySee.Count = 64; /* unused */
343 }

+ Here is the caller graph for this function:

CPpmd_See* Ppmd7_MakeEscFreq ( CPpmd7 p,
unsigned  numMasked,
UInt32 scale 
)

Definition at line 638 of file Ppmd7.c.

639 {
640  CPpmd_See *see;
641  unsigned nonMasked = p->MinContext->NumStats - numMasked;
642  if (p->MinContext->NumStats != 256)
643  {
644  see = p->See[(unsigned)p->NS2Indx[(size_t)nonMasked - 1]] +
645  (nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) +
646  2 * (unsigned)(p->MinContext->SummFreq < 11 * p->MinContext->NumStats) +
647  4 * (unsigned)(numMasked > nonMasked) +
648  p->HiBitsFlag;
649  {
650  unsigned r = (see->Summ >> see->Shift);
651  see->Summ = (UInt16)(see->Summ - r);
652  *escFreq = r + (r == 0);
653  }
654  }
655  else
656  {
657  see = &p->DummySee;
658  *escFreq = 1;
659  }
660  return see;
661 }

+ Here is the caller graph for this function:

void Ppmd7_Update1 ( CPpmd7 p)

Definition at line 672 of file Ppmd7.c.

673 {
674  CPpmd_State *s = p->FoundState;
675  s->Freq += 4;
676  p->MinContext->SummFreq += 4;
677  if (s[0].Freq > s[-1].Freq)
678  {
679  SwapStates(&s[0], &s[-1]);
680  p->FoundState = --s;
681  if (s->Freq > MAX_FREQ)
682  Rescale(p);
683  }
684  NextContext(p);
685 }

+ Here is the caller graph for this function:

void Ppmd7_Update1_0 ( CPpmd7 p)

Definition at line 687 of file Ppmd7.c.

688 {
689  p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq);
690  p->RunLength += p->PrevSuccess;
691  p->MinContext->SummFreq += 4;
692  if ((p->FoundState->Freq += 4) > MAX_FREQ)
693  Rescale(p);
694  NextContext(p);
695 }

+ Here is the caller graph for this function:

void Ppmd7_Update2 ( CPpmd7 p)

Definition at line 705 of file Ppmd7.c.

706 {
707  p->MinContext->SummFreq += 4;
708  if ((p->FoundState->Freq += 4) > MAX_FREQ)
709  Rescale(p);
710  p->RunLength = p->InitRL;
711  UpdateModel(p);
712 }

+ Here is the caller graph for this function:

void Ppmd7_UpdateBin ( CPpmd7 p)

Definition at line 697 of file Ppmd7.c.

698 {
699  p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1: 0));
700  p->PrevSuccess = 1;
701  p->RunLength++;
702  NextContext(p);
703 }

+ Here is the caller graph for this function:

void Ppmd7z_RangeDec_CreateVTable ( CPpmd7z_RangeDec p)

Definition at line 73 of file Ppmd7Dec.c.

74 {
76  p->vt.Decode = Range_Decode;
78 }
Bool Ppmd7z_RangeDec_Init ( CPpmd7z_RangeDec p)

Definition at line 11 of file Ppmd7Dec.c.

12 {
13  unsigned i;
14  p->Code = 0;
15  p->Range = 0xFFFFFFFF;
16  if (IByteIn_Read(p->Stream) != 0)
17  return False;
18  for (i = 0; i < 4; i++)
19  p->Code = (p->Code << 8) | IByteIn_Read(p->Stream);
20  return (p->Code < 0xFFFFFFFF);
21 }
void Ppmd7z_RangeEnc_FlushData ( CPpmd7z_RangeEnc p)
void Ppmd7z_RangeEnc_Init ( CPpmd7z_RangeEnc p)

Variable Documentation

const Byte PPMD7_kExpEscape[16]

Definition at line 11 of file Ppmd7.c.