summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-27 21:33:58 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-27 21:33:58 +0000
commit1279579430dfd1e57c1df05605535876d402be49 (patch)
tree9f95db6235cfad2fc5df6f08b2b94801b5aac846 /core/fxcodec/jbig2/JBig2_HuffmanTable.cpp
parent74c8b8e6e561b4ff1059441d70f7f1476494dfbb (diff)
downloadpdfium-1279579430dfd1e57c1df05605535876d402be49.tar.xz
Remove CJBig2_HuffmanTable::InitCodes().
Use CJBig2_Context::HuffmanAssignCode() instead. Change-Id: Ief187420494a8cefa26eeedb98a55683caf7807b Reviewed-on: https://pdfium-review.googlesource.com/31538 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fxcodec/jbig2/JBig2_HuffmanTable.cpp')
-rw-r--r--core/fxcodec/jbig2/JBig2_HuffmanTable.cpp43
1 files changed, 7 insertions, 36 deletions
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp b/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp
index aa3cd0be10..988978a699 100644
--- a/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp
+++ b/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp
@@ -6,11 +6,11 @@
#include "core/fxcodec/jbig2/JBig2_HuffmanTable.h"
-#include <algorithm>
#include <limits>
#include <vector>
#include "core/fxcodec/jbig2/JBig2_BitStream.h"
+#include "core/fxcodec/jbig2/JBig2_Context.h"
#include "core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h"
#include "core/fxcrt/fx_memory.h"
#include "third_party/base/numerics/safe_math.h"
@@ -18,8 +18,9 @@
CJBig2_HuffmanTable::CJBig2_HuffmanTable(const JBig2TableLine* pTable,
uint32_t nLines,
bool bHTOOB)
- : m_bOK(true), HTOOB(bHTOOB), NTEMP(nLines) {
- ParseFromStandardTable(pTable);
+ : HTOOB(bHTOOB), NTEMP(nLines) {
+ m_bOK = ParseFromStandardTable(pTable);
+ ASSERT(m_bOK);
}
CJBig2_HuffmanTable::CJBig2_HuffmanTable(CJBig2_BitStream* pStream)
@@ -29,7 +30,7 @@ CJBig2_HuffmanTable::CJBig2_HuffmanTable(CJBig2_BitStream* pStream)
CJBig2_HuffmanTable::~CJBig2_HuffmanTable() {}
-void CJBig2_HuffmanTable::ParseFromStandardTable(const JBig2TableLine* pTable) {
+bool CJBig2_HuffmanTable::ParseFromStandardTable(const JBig2TableLine* pTable) {
CODES.resize(NTEMP);
RANGELEN.resize(NTEMP);
RANGELOW.resize(NTEMP);
@@ -38,7 +39,7 @@ void CJBig2_HuffmanTable::ParseFromStandardTable(const JBig2TableLine* pTable) {
RANGELEN[i] = pTable[i].RANDELEN;
RANGELOW[i] = pTable[i].RANGELOW;
}
- InitCodes();
+ return CJBig2_Context::HuffmanAssignCode(CODES.data(), NTEMP);
}
bool CJBig2_HuffmanTable::ParseFromCodedBuffer(CJBig2_BitStream* pStream) {
@@ -104,37 +105,7 @@ bool CJBig2_HuffmanTable::ParseFromCodedBuffer(CJBig2_BitStream* pStream) {
++NTEMP;
}
- return InitCodes();
-}
-
-bool CJBig2_HuffmanTable::InitCodes() {
- int lenmax = 0;
- for (uint32_t i = 0; i < NTEMP; ++i)
- lenmax = std::max(CODES[i].codelen, lenmax);
-
- std::vector<int> LENCOUNT(lenmax + 1);
- std::vector<int> FIRSTCODE(lenmax + 1);
- for (uint32_t i = 0; i < NTEMP; ++i)
- ++LENCOUNT[CODES[i].codelen];
-
- FIRSTCODE[0] = 0;
- LENCOUNT[0] = 0;
- for (int i = 1; i <= lenmax; ++i) {
- pdfium::base::CheckedNumeric<int> shifted = FIRSTCODE[i - 1];
- shifted += LENCOUNT[i - 1];
- shifted <<= 1;
- if (!shifted.IsValid())
- return false;
-
- FIRSTCODE[i] = shifted.ValueOrDie();
- int CURCODE = FIRSTCODE[i];
- for (uint32_t j = 0; j < NTEMP; ++j) {
- if (CODES[j].codelen == i)
- CODES[j].code = CURCODE++;
- }
- }
-
- return true;
+ return CJBig2_Context::HuffmanAssignCode(CODES.data(), NTEMP);
}
void CJBig2_HuffmanTable::ExtendBuffers(bool increment) {