diff options
Diffstat (limited to '')
-rw-r--r-- | C/Ppmd7aDec.c | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/C/Ppmd7aDec.c b/C/Ppmd7aDec.c index c424578..55e164e 100644 --- a/C/Ppmd7aDec.c +++ b/C/Ppmd7aDec.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Ppmd7aDec.c -- PPMd7a (PPMdH) Decoder | 1 | /* Ppmd7aDec.c -- PPMd7a (PPMdH) 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.H (2001): Dmitry Shkarin : Public domain | 4 | PPMd var.H (2001): 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 "Ppmd7.h" | 9 | #include "Ppmd7.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) | 14 | #define READ_BYTE(p) IByteIn_Read((p)->Stream) |
15 | 15 | ||
@@ -37,9 +37,9 @@ BoolInt Ppmd7a_RangeDec_Init(CPpmd7_RangeDec *p) | |||
37 | 37 | ||
38 | #define R (&p->rc.dec) | 38 | #define R (&p->rc.dec) |
39 | 39 | ||
40 | MY_FORCE_INLINE | 40 | Z7_FORCE_INLINE |
41 | // MY_NO_INLINE | 41 | // Z7_NO_INLINE |
42 | static void RangeDec_Decode(CPpmd7 *p, UInt32 start, UInt32 size) | 42 | static void Ppmd7a_RD_Decode(CPpmd7 *p, UInt32 start, UInt32 size) |
43 | { | 43 | { |
44 | start *= R->Range; | 44 | start *= R->Range; |
45 | R->Low += start; | 45 | R->Low += start; |
@@ -48,9 +48,9 @@ static void RangeDec_Decode(CPpmd7 *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) Ppmd7a_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) ((CPpmd7_Context *)Ppmd7_GetContext(p, ref)) | 56 | #define CTX(ref) ((CPpmd7_Context *)Ppmd7_GetContext(p, ref)) |
@@ -70,7 +70,7 @@ int Ppmd7a_DecodeSymbol(CPpmd7 *p) | |||
70 | CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); | 70 | CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); |
71 | unsigned i; | 71 | unsigned i; |
72 | UInt32 count, hiCnt; | 72 | UInt32 count, hiCnt; |
73 | UInt32 summFreq = p->MinContext->Union2.SummFreq; | 73 | const UInt32 summFreq = p->MinContext->Union2.SummFreq; |
74 | 74 | ||
75 | if (summFreq > R->Range) | 75 | if (summFreq > R->Range) |
76 | return PPMD7_SYM_ERROR; | 76 | return PPMD7_SYM_ERROR; |
@@ -81,7 +81,7 @@ int Ppmd7a_DecodeSymbol(CPpmd7 *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 | Ppmd7_Update1_0(p); | 87 | Ppmd7_Update1_0(p); |
@@ -96,7 +96,7 @@ int Ppmd7a_DecodeSymbol(CPpmd7 *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 | Ppmd7_Update1(p); | 102 | Ppmd7_Update1(p); |
@@ -109,10 +109,10 @@ int Ppmd7a_DecodeSymbol(CPpmd7 *p) | |||
109 | return PPMD7_SYM_ERROR; | 109 | return PPMD7_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 | p->HiBitsFlag = PPMD7_HiBitsFlag_3(p->FoundState->Symbol); | 114 | p->HiBitsFlag = PPMD7_HiBitsFlag_3(p->FoundState->Symbol); |
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 | { |
@@ -176,7 +176,7 @@ int Ppmd7a_DecodeSymbol(CPpmd7 *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(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0; | 180 | MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0; |
181 | p->PrevSuccess = 0; | 181 | p->PrevSuccess = 0; |
182 | } | 182 | } |
@@ -245,13 +245,13 @@ int Ppmd7a_DecodeSymbol(CPpmd7 *p) | |||
245 | { | 245 | { |
246 | count -= s->Freq & (unsigned)(MASK((s)->Symbol)); s++; if ((Int32)count < 0) break; | 246 | count -= s->Freq & (unsigned)(MASK((s)->Symbol)); s++; if ((Int32)count < 0) break; |
247 | // count -= s->Freq & (unsigned)(MASK((s)->Symbol)); s++; if ((Int32)count < 0) break; | 247 | // count -= s->Freq & (unsigned)(MASK((s)->Symbol)); s++; if ((Int32)count < 0) break; |
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 | Ppmd7_Update2(p); | 257 | Ppmd7_Update2(p); |
@@ -261,7 +261,7 @@ int Ppmd7a_DecodeSymbol(CPpmd7 *p) | |||
261 | if (count >= freqSum) | 261 | if (count >= freqSum) |
262 | return PPMD7_SYM_ERROR; | 262 | return PPMD7_SYM_ERROR; |
263 | 263 | ||
264 | RC_Decode(hiCnt, freqSum - hiCnt); | 264 | RC_Decode(hiCnt, freqSum - 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 Ppmd7a_DecodeSymbol(CPpmd7 *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 | ||