1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "JBig2_ArithIntDecoder.h"
9 #include "../../../include/fxcrt/fx_memory.h"
11 CJBig2_ArithIntDecoder::CJBig2_ArithIntDecoder() {
12 IAx = FX_Alloc(JBig2ArithCtx, 512);
13 JBIG2_memset(IAx, 0, sizeof(JBig2ArithCtx) * 512);
15 CJBig2_ArithIntDecoder::~CJBig2_ArithIntDecoder() {
18 int CJBig2_ArithIntDecoder::decode(CJBig2_ArithDecoder* pArithDecoder,
22 int nNeedBits, nTemp, i;
24 S = pArithDecoder->DECODE(IAx + PREV);
25 PREV = (PREV << 1) | S;
26 D = pArithDecoder->DECODE(IAx + PREV);
27 PREV = (PREV << 1) | D;
29 D = pArithDecoder->DECODE(IAx + PREV);
30 PREV = (PREV << 1) | D;
32 D = pArithDecoder->DECODE(IAx + PREV);
33 PREV = (PREV << 1) | D;
35 D = pArithDecoder->DECODE(IAx + PREV);
36 PREV = (PREV << 1) | D;
38 D = pArithDecoder->DECODE(IAx + PREV);
39 PREV = (PREV << 1) | D;
64 for (i = 0; i < nNeedBits; i++) {
65 D = pArithDecoder->DECODE(IAx + PREV);
67 PREV = (PREV << 1) | D;
69 PREV = (((PREV << 1) | D) & 511) | 256;
71 nTemp = (nTemp << 1) | D;
74 if (S == 1 && V > 0) {
78 if (S == 1 && V == 0) {
83 CJBig2_ArithIaidDecoder::CJBig2_ArithIaidDecoder(unsigned char SBSYMCODELENA) {
84 SBSYMCODELEN = SBSYMCODELENA;
85 IAID = FX_Alloc(JBig2ArithCtx, 1 << SBSYMCODELEN);
86 JBIG2_memset(IAID, 0, sizeof(JBig2ArithCtx) * (int)(1 << SBSYMCODELEN));
88 CJBig2_ArithIaidDecoder::~CJBig2_ArithIaidDecoder() {
91 int CJBig2_ArithIaidDecoder::decode(CJBig2_ArithDecoder* pArithDecoder,
97 for (i = 0; i < SBSYMCODELEN; i++) {
98 D = pArithDecoder->DECODE(IAID + PREV);
99 PREV = (PREV << 1) | D;
101 PREV = PREV - (1 << SBSYMCODELEN);