Fix FX_BOOL type mismatches.
[pdfium.git] / core / src / fxcodec / jbig2 / JBig2_HuffmanDecoder.cpp
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.
4  
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "JBig2_HuffmanDecoder.h"
8 CJBig2_HuffmanDecoder::CJBig2_HuffmanDecoder(CJBig2_BitStream *pStream)
9 {
10     m_pStream = pStream;
11 }
12 CJBig2_HuffmanDecoder::~CJBig2_HuffmanDecoder()
13 {
14 }
15 int CJBig2_HuffmanDecoder::decodeAValue(CJBig2_HuffmanTable *pTable, int *nResult)
16 {
17     int i;
18     int nVal = 0;
19     int nBits = 0;
20     FX_DWORD nTmp;
21     while(1) {
22         if(m_pStream->read1Bit(&nTmp) == -1) {
23             return -1;
24         }
25         nVal = (nVal << 1) | nTmp;
26         nBits ++;
27         for(i = 0; i < pTable->NTEMP; i++) {
28             if((pTable->PREFLEN[i] == nBits) && (pTable->CODES[i] == nVal)) {
29                 if((pTable->HTOOB == 1) && (i == pTable->NTEMP - 1)) {
30                     return JBIG2_OOB;
31                 }
32                 if(m_pStream->readNBits(pTable->RANGELEN[i], &nTmp) == -1) {
33                     return -1;
34                 }
35                 if(pTable->HTOOB) {
36                     if(i == pTable->NTEMP - 3) {
37                         *nResult = pTable->RANGELOW[i] - nTmp;
38                         return 0;
39                     } else {
40                         *nResult = pTable->RANGELOW[i] + nTmp;
41                         return 0;
42                     }
43                 } else {
44                     if(i == pTable->NTEMP - 2) {
45                         *nResult = pTable->RANGELOW[i] - nTmp;
46                         return 0;
47                     } else {
48                         *nResult = pTable->RANGELOW[i] + nTmp;
49                         return 0;
50                     }
51                 }
52             }
53         }
54     }
55     return -2;
56 }