summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp')
-rw-r--r--core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp b/core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp
index c6dd3924b8..cdb6fbe752 100644
--- a/core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp
+++ b/core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp
@@ -25,20 +25,22 @@ int CJBig2_HuffmanDecoder::DecodeAValue(CJBig2_HuffmanTable* pTable,
nVal = (nVal << 1) | nTmp;
++nBits;
for (uint32_t i = 0; i < pTable->Size(); ++i) {
- if (pTable->GetPREFLEN()[i] == nBits && pTable->GetCODES()[i] == nVal) {
- if (pTable->IsHTOOB() && i == pTable->Size() - 1)
- return JBIG2_OOB;
-
- if (m_pStream->readNBits(pTable->GetRANGELEN()[i], &nTmp) == -1)
- return -1;
-
- uint32_t offset = pTable->IsHTOOB() ? 3 : 2;
- if (i == pTable->Size() - offset)
- *nResult = pTable->GetRANGELOW()[i] - nTmp;
- else
- *nResult = pTable->GetRANGELOW()[i] + nTmp;
- return 0;
- }
+ const JBig2HuffmanCode& code = pTable->GetCODES()[i];
+ if (code.codelen != nBits || code.code != nVal)
+ continue;
+
+ if (pTable->IsHTOOB() && i == pTable->Size() - 1)
+ return JBIG2_OOB;
+
+ if (m_pStream->readNBits(pTable->GetRANGELEN()[i], &nTmp) == -1)
+ return -1;
+
+ uint32_t offset = pTable->IsHTOOB() ? 3 : 2;
+ if (i == pTable->Size() - offset)
+ *nResult = pTable->GetRANGELOW()[i] - nTmp;
+ else
+ *nResult = pTable->GetRANGELOW()[i] + nTmp;
+ return 0;
}
}
return -1;