| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "JBig2_ArithIntDecoder.h" | 7 #include "JBig2_ArithIntDecoder.h" |
| 8 | 8 |
| 9 #include "../../../include/fxcrt/fx_memory.h" | 9 #include "../../../include/fxcrt/fx_memory.h" |
| 10 #include "JBig2_Define.h" |
| 10 | 11 |
| 11 CJBig2_ArithIntDecoder::CJBig2_ArithIntDecoder() { | 12 CJBig2_ArithIntDecoder::CJBig2_ArithIntDecoder() { |
| 12 IAx = FX_Alloc(JBig2ArithCtx, 512); | 13 IAx = (JBig2ArithCtx*)FX_AllocOrDie(sizeof(JBig2ArithCtx), 512); |
| 13 JBIG2_memset(IAx, 0, sizeof(JBig2ArithCtx) * 512); | 14 JBIG2_memset(IAx, 0, sizeof(JBig2ArithCtx) * 512); |
| 14 } | 15 } |
| 15 CJBig2_ArithIntDecoder::~CJBig2_ArithIntDecoder() { | 16 CJBig2_ArithIntDecoder::~CJBig2_ArithIntDecoder() { |
| 16 FX_Free(IAx); | 17 FX_Free(IAx); |
| 17 } | 18 } |
| 18 int CJBig2_ArithIntDecoder::decode(CJBig2_ArithDecoder* pArithDecoder, | 19 int CJBig2_ArithIntDecoder::decode(CJBig2_ArithDecoder* pArithDecoder, |
| 19 int* nResult) { | 20 int* nResult) { |
| 20 int PREV, V; | 21 int PREV, V; |
| 21 int S, D; | 22 int S, D; |
| 22 int nNeedBits, nTemp, i; | 23 int nNeedBits, nTemp, i; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 V = -V; | 76 V = -V; |
| 76 } | 77 } |
| 77 *nResult = V; | 78 *nResult = V; |
| 78 if (S == 1 && V == 0) { | 79 if (S == 1 && V == 0) { |
| 79 return JBIG2_OOB; | 80 return JBIG2_OOB; |
| 80 } | 81 } |
| 81 return 0; | 82 return 0; |
| 82 } | 83 } |
| 83 CJBig2_ArithIaidDecoder::CJBig2_ArithIaidDecoder(unsigned char SBSYMCODELENA) { | 84 CJBig2_ArithIaidDecoder::CJBig2_ArithIaidDecoder(unsigned char SBSYMCODELENA) { |
| 84 SBSYMCODELEN = SBSYMCODELENA; | 85 SBSYMCODELEN = SBSYMCODELENA; |
| 85 IAID = FX_Alloc(JBig2ArithCtx, 1 << SBSYMCODELEN); | 86 IAID = |
| 87 (JBig2ArithCtx*)FX_AllocOrDie(sizeof(JBig2ArithCtx), (1 << SBSYMCODELEN)); |
| 86 JBIG2_memset(IAID, 0, sizeof(JBig2ArithCtx) * (int)(1 << SBSYMCODELEN)); | 88 JBIG2_memset(IAID, 0, sizeof(JBig2ArithCtx) * (int)(1 << SBSYMCODELEN)); |
| 87 } | 89 } |
| 88 CJBig2_ArithIaidDecoder::~CJBig2_ArithIaidDecoder() { | 90 CJBig2_ArithIaidDecoder::~CJBig2_ArithIaidDecoder() { |
| 89 FX_Free(IAID); | 91 FX_Free(IAID); |
| 90 } | 92 } |
| 91 int CJBig2_ArithIaidDecoder::decode(CJBig2_ArithDecoder* pArithDecoder, | 93 int CJBig2_ArithIaidDecoder::decode(CJBig2_ArithDecoder* pArithDecoder, |
| 92 int* nResult) { | 94 int* nResult) { |
| 93 int PREV; | 95 int PREV; |
| 94 int D; | 96 int D; |
| 95 int i; | 97 int i; |
| 96 PREV = 1; | 98 PREV = 1; |
| 97 for (i = 0; i < SBSYMCODELEN; i++) { | 99 for (i = 0; i < SBSYMCODELEN; i++) { |
| 98 D = pArithDecoder->DECODE(IAID + PREV); | 100 D = pArithDecoder->DECODE(IAID + PREV); |
| 99 PREV = (PREV << 1) | D; | 101 PREV = (PREV << 1) | D; |
| 100 } | 102 } |
| 101 PREV = PREV - (1 << SBSYMCODELEN); | 103 PREV = PREV - (1 << SBSYMCODELEN); |
| 102 *nResult = PREV; | 104 *nResult = PREV; |
| 103 return 0; | 105 return 0; |
| 104 } | 106 } |
| OLD | NEW |