diff options
Diffstat (limited to '')
-rw-r--r-- | C/Ppmd8Dec.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/C/Ppmd8Dec.c b/C/Ppmd8Dec.c index d205de2..72d3626 100644 --- a/C/Ppmd8Dec.c +++ b/C/Ppmd8Dec.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Ppmd8Dec.c -- Ppmd8 (PPMdI) Decoder | 1 | /* Ppmd8Dec.c -- Ppmd8 (PPMdI) Decoder |
2 | 2021-04-13 : Igor Pavlov : Public domain | 2 | 2023-04-02 : Igor Pavlov : Public domain |
3 | This code is based on: | 3 | This code is based on: |
4 | PPMd var.I (2002): Dmitry Shkarin : Public domain | 4 | PPMd var.I (2002): Dmitry Shkarin : Public domain |
5 | Carryless rangecoder (1999): Dmitry Subbotin : Public domain */ | 5 | Carryless rangecoder (1999): Dmitry Subbotin : Public domain */ |
@@ -8,8 +8,8 @@ This code is based on: | |||
8 | 8 | ||
9 | #include "Ppmd8.h" | 9 | #include "Ppmd8.h" |
10 | 10 | ||
11 | #define kTop (1 << 24) | 11 | #define kTop ((UInt32)1 << 24) |
12 | #define kBot (1 << 15) | 12 | #define kBot ((UInt32)1 << 15) |
13 | 13 | ||
14 | #define READ_BYTE(p) IByteIn_Read((p)->Stream.In) | 14 | #define READ_BYTE(p) IByteIn_Read((p)->Stream.In) |
15 | 15 | ||
@@ -37,9 +37,9 @@ BoolInt Ppmd8_Init_RangeDec(CPpmd8 *p) | |||
37 | 37 | ||
38 | #define R p | 38 | #define R p |
39 | 39 | ||
40 | MY_FORCE_INLINE | 40 | Z7_FORCE_INLINE |
41 | // MY_NO_INLINE | 41 | // Z7_NO_INLINE |
42 | static void RangeDec_Decode(CPpmd8 *p, UInt32 start, UInt32 size) | 42 | static void Ppmd8_RD_Decode(CPpmd8 *p, UInt32 start, UInt32 size) |
43 | { | 43 | { |
44 | start *= R->Range; | 44 | start *= R->Range; |
45 | R->Low += start; | 45 | R->Low += start; |
@@ -48,13 +48,13 @@ static void RangeDec_Decode(CPpmd8 *p, UInt32 start, UInt32 size) | |||
48 | RC_NORM_LOCAL(R) | 48 | RC_NORM_LOCAL(R) |
49 | } | 49 | } |
50 | 50 | ||
51 | #define RC_Decode(start, size) RangeDec_Decode(p, start, size); | 51 | #define RC_Decode(start, size) Ppmd8_RD_Decode(p, start, size); |
52 | #define RC_DecodeFinal(start, size) RC_Decode(start, size) RC_NORM_REMOTE(R) | 52 | #define RC_DecodeFinal(start, size) RC_Decode(start, size) RC_NORM_REMOTE(R) |
53 | #define RC_GetThreshold(total) (R->Code / (R->Range /= (total))) | 53 | #define RC_GetThreshold(total) (R->Code / (R->Range /= (total))) |
54 | 54 | ||
55 | 55 | ||
56 | #define CTX(ref) ((CPpmd8_Context *)Ppmd8_GetContext(p, ref)) | 56 | #define CTX(ref) ((CPpmd8_Context *)Ppmd8_GetContext(p, ref)) |
57 | typedef CPpmd8_Context * CTX_PTR; | 57 | // typedef CPpmd8_Context * CTX_PTR; |
58 | #define SUCCESSOR(p) Ppmd_GET_SUCCESSOR(p) | 58 | #define SUCCESSOR(p) Ppmd_GET_SUCCESSOR(p) |
59 | void Ppmd8_UpdateModel(CPpmd8 *p); | 59 | void Ppmd8_UpdateModel(CPpmd8 *p); |
60 | 60 | ||
@@ -81,7 +81,7 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
81 | if ((Int32)(count -= s->Freq) < 0) | 81 | if ((Int32)(count -= s->Freq) < 0) |
82 | { | 82 | { |
83 | Byte sym; | 83 | Byte sym; |
84 | RC_DecodeFinal(0, s->Freq); | 84 | RC_DecodeFinal(0, s->Freq) |
85 | p->FoundState = s; | 85 | p->FoundState = s; |
86 | sym = s->Symbol; | 86 | sym = s->Symbol; |
87 | Ppmd8_Update1_0(p); | 87 | Ppmd8_Update1_0(p); |
@@ -96,7 +96,7 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
96 | if ((Int32)(count -= (++s)->Freq) < 0) | 96 | if ((Int32)(count -= (++s)->Freq) < 0) |
97 | { | 97 | { |
98 | Byte sym; | 98 | Byte sym; |
99 | RC_DecodeFinal((hiCnt - count) - s->Freq, s->Freq); | 99 | RC_DecodeFinal((hiCnt - count) - s->Freq, s->Freq) |
100 | p->FoundState = s; | 100 | p->FoundState = s; |
101 | sym = s->Symbol; | 101 | sym = s->Symbol; |
102 | Ppmd8_Update1(p); | 102 | Ppmd8_Update1(p); |
@@ -109,10 +109,10 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
109 | return PPMD8_SYM_ERROR; | 109 | return PPMD8_SYM_ERROR; |
110 | 110 | ||
111 | hiCnt -= count; | 111 | hiCnt -= count; |
112 | RC_Decode(hiCnt, summFreq - hiCnt); | 112 | RC_Decode(hiCnt, summFreq - hiCnt) |
113 | 113 | ||
114 | 114 | ||
115 | PPMD_SetAllBitsIn256Bytes(charMask); | 115 | PPMD_SetAllBitsIn256Bytes(charMask) |
116 | // i = p->MinContext->NumStats - 1; | 116 | // i = p->MinContext->NumStats - 1; |
117 | // do { MASK((--s)->Symbol) = 0; } while (--i); | 117 | // do { MASK((--s)->Symbol) = 0; } while (--i); |
118 | { | 118 | { |
@@ -152,7 +152,7 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
152 | // Ppmd8_UpdateBin(p); | 152 | // Ppmd8_UpdateBin(p); |
153 | { | 153 | { |
154 | unsigned freq = s->Freq; | 154 | unsigned freq = s->Freq; |
155 | CTX_PTR c = CTX(SUCCESSOR(s)); | 155 | CPpmd8_Context *c = CTX(SUCCESSOR(s)); |
156 | sym = s->Symbol; | 156 | sym = s->Symbol; |
157 | p->FoundState = s; | 157 | p->FoundState = s; |
158 | p->PrevSuccess = 1; | 158 | p->PrevSuccess = 1; |
@@ -176,7 +176,7 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
176 | R->Range = (R->Range & ~((UInt32)PPMD_BIN_SCALE - 1)) - size0; | 176 | R->Range = (R->Range & ~((UInt32)PPMD_BIN_SCALE - 1)) - size0; |
177 | RC_NORM_LOCAL(R) | 177 | RC_NORM_LOCAL(R) |
178 | 178 | ||
179 | PPMD_SetAllBitsIn256Bytes(charMask); | 179 | PPMD_SetAllBitsIn256Bytes(charMask) |
180 | MASK(Ppmd8Context_OneState(p->MinContext)->Symbol) = 0; | 180 | MASK(Ppmd8Context_OneState(p->MinContext)->Symbol) = 0; |
181 | p->PrevSuccess = 0; | 181 | p->PrevSuccess = 0; |
182 | } | 182 | } |
@@ -227,7 +227,7 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
227 | see = Ppmd8_MakeEscFreq(p, numMasked, &freqSum); | 227 | see = Ppmd8_MakeEscFreq(p, numMasked, &freqSum); |
228 | freqSum += hiCnt; | 228 | freqSum += hiCnt; |
229 | freqSum2 = freqSum; | 229 | freqSum2 = freqSum; |
230 | PPMD8_CORRECT_SUM_RANGE(R, freqSum2); | 230 | PPMD8_CORRECT_SUM_RANGE(R, freqSum2) |
231 | 231 | ||
232 | 232 | ||
233 | count = RC_GetThreshold(freqSum2); | 233 | count = RC_GetThreshold(freqSum2); |
@@ -235,7 +235,7 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
235 | if (count < hiCnt) | 235 | if (count < hiCnt) |
236 | { | 236 | { |
237 | Byte sym; | 237 | Byte sym; |
238 | // Ppmd_See_Update(see); // new (see->Summ) value can overflow over 16-bits in some rare cases | 238 | // Ppmd_See_UPDATE(see) // new (see->Summ) value can overflow over 16-bits in some rare cases |
239 | s = Ppmd8_GetStats(p, p->MinContext); | 239 | s = Ppmd8_GetStats(p, p->MinContext); |
240 | hiCnt = count; | 240 | hiCnt = count; |
241 | 241 | ||
@@ -248,10 +248,10 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
248 | } | 248 | } |
249 | } | 249 | } |
250 | s--; | 250 | s--; |
251 | RC_DecodeFinal((hiCnt - count) - s->Freq, s->Freq); | 251 | RC_DecodeFinal((hiCnt - count) - s->Freq, s->Freq) |
252 | 252 | ||
253 | // new (see->Summ) value can overflow over 16-bits in some rare cases | 253 | // new (see->Summ) value can overflow over 16-bits in some rare cases |
254 | Ppmd_See_Update(see); | 254 | Ppmd_See_UPDATE(see) |
255 | p->FoundState = s; | 255 | p->FoundState = s; |
256 | sym = s->Symbol; | 256 | sym = s->Symbol; |
257 | Ppmd8_Update2(p); | 257 | Ppmd8_Update2(p); |
@@ -261,7 +261,7 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
261 | if (count >= freqSum2) | 261 | if (count >= freqSum2) |
262 | return PPMD8_SYM_ERROR; | 262 | return PPMD8_SYM_ERROR; |
263 | 263 | ||
264 | RC_Decode(hiCnt, freqSum2 - hiCnt); | 264 | RC_Decode(hiCnt, freqSum2 - hiCnt) |
265 | 265 | ||
266 | // We increase (see->Summ) for sum of Freqs of all non_Masked symbols. | 266 | // We increase (see->Summ) for sum of Freqs of all non_Masked symbols. |
267 | // new (see->Summ) value can overflow over 16-bits in some rare cases | 267 | // new (see->Summ) value can overflow over 16-bits in some rare cases |
@@ -277,3 +277,19 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) | |||
277 | while (s != s2); | 277 | while (s != s2); |
278 | } | 278 | } |
279 | } | 279 | } |
280 | |||
281 | #undef kTop | ||
282 | #undef kBot | ||
283 | #undef READ_BYTE | ||
284 | #undef RC_NORM_BASE | ||
285 | #undef RC_NORM_1 | ||
286 | #undef RC_NORM | ||
287 | #undef RC_NORM_LOCAL | ||
288 | #undef RC_NORM_REMOTE | ||
289 | #undef R | ||
290 | #undef RC_Decode | ||
291 | #undef RC_DecodeFinal | ||
292 | #undef RC_GetThreshold | ||
293 | #undef CTX | ||
294 | #undef SUCCESSOR | ||
295 | #undef MASK | ||