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_HuffmanDecoder.h" | 7 #include "JBig2_HuffmanDecoder.h" |
8 CJBig2_HuffmanDecoder::CJBig2_HuffmanDecoder(CJBig2_BitStream *pStream) | 8 CJBig2_HuffmanDecoder::CJBig2_HuffmanDecoder(CJBig2_BitStream* pStream) { |
9 { | 9 m_pStream = pStream; |
10 m_pStream = pStream; | |
11 } | 10 } |
12 CJBig2_HuffmanDecoder::~CJBig2_HuffmanDecoder() | 11 CJBig2_HuffmanDecoder::~CJBig2_HuffmanDecoder() { |
13 { | |
14 } | 12 } |
15 int CJBig2_HuffmanDecoder::decodeAValue(CJBig2_HuffmanTable *pTable, int *nResul
t) | 13 int CJBig2_HuffmanDecoder::decodeAValue(CJBig2_HuffmanTable* pTable, |
16 { | 14 int* nResult) { |
17 int nVal, nTmp, i, nBits; | 15 int nVal, nTmp, i, nBits; |
18 nVal = 0; | 16 nVal = 0; |
19 nBits = 0; | 17 nBits = 0; |
20 while(1) { | 18 while (1) { |
21 if(m_pStream->read1Bit(&nTmp) == -1) { | 19 if (m_pStream->read1Bit(&nTmp) == -1) { |
22 return -1; | 20 return -1; |
| 21 } |
| 22 nVal = (nVal << 1) | nTmp; |
| 23 nBits++; |
| 24 for (i = 0; i < pTable->NTEMP; i++) { |
| 25 if ((pTable->PREFLEN[i] == nBits) && (pTable->CODES[i] == nVal)) { |
| 26 if ((pTable->HTOOB == 1) && (i == pTable->NTEMP - 1)) { |
| 27 return JBIG2_OOB; |
23 } | 28 } |
24 nVal = (nVal << 1) | nTmp; | 29 if (m_pStream->readNBits(pTable->RANGELEN[i], &nTmp) == -1) { |
25 nBits ++; | 30 return -1; |
26 for(i = 0; i < pTable->NTEMP; i++) { | |
27 if((pTable->PREFLEN[i] == nBits) && (pTable->CODES[i] == nVal)) { | |
28 if((pTable->HTOOB == 1) && (i == pTable->NTEMP - 1)) { | |
29 return JBIG2_OOB; | |
30 } | |
31 if(m_pStream->readNBits(pTable->RANGELEN[i], &nTmp) == -1) { | |
32 return -1; | |
33 } | |
34 if(pTable->HTOOB) { | |
35 if(i == pTable->NTEMP - 3) { | |
36 *nResult = pTable->RANGELOW[i] - nTmp; | |
37 return 0; | |
38 } else { | |
39 *nResult = pTable->RANGELOW[i] + nTmp; | |
40 return 0; | |
41 } | |
42 } else { | |
43 if(i == pTable->NTEMP - 2) { | |
44 *nResult = pTable->RANGELOW[i] - nTmp; | |
45 return 0; | |
46 } else { | |
47 *nResult = pTable->RANGELOW[i] + nTmp; | |
48 return 0; | |
49 } | |
50 } | |
51 } | |
52 } | 31 } |
| 32 if (pTable->HTOOB) { |
| 33 if (i == pTable->NTEMP - 3) { |
| 34 *nResult = pTable->RANGELOW[i] - nTmp; |
| 35 return 0; |
| 36 } else { |
| 37 *nResult = pTable->RANGELOW[i] + nTmp; |
| 38 return 0; |
| 39 } |
| 40 } else { |
| 41 if (i == pTable->NTEMP - 2) { |
| 42 *nResult = pTable->RANGELOW[i] - nTmp; |
| 43 return 0; |
| 44 } else { |
| 45 *nResult = pTable->RANGELOW[i] + nTmp; |
| 46 return 0; |
| 47 } |
| 48 } |
| 49 } |
53 } | 50 } |
54 return -2; | 51 } |
| 52 return -2; |
55 } | 53 } |
OLD | NEW |