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