summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp6
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.h4
-rw-r--r--core/fxcodec/jbig2/JBig2_HuffmanTable.cpp43
-rw-r--r--core/fxcodec/jbig2/JBig2_HuffmanTable.h3
4 files changed, 12 insertions, 44 deletions
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 6cb94872c6..8d416ffc3c 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -1319,9 +1319,9 @@ std::vector<JBig2HuffmanCode> CJBig2_Context::DecodeSymbolIDHuffmanTable(
return SBSYMCODES;
}
+// static
bool CJBig2_Context::HuffmanAssignCode(JBig2HuffmanCode* SBSYMCODES,
uint32_t NTEMP) {
- // TODO(thestig): CJBig2_HuffmanTable::InitCodes() has similar code.
int LENMAX = 0;
for (uint32_t i = 0; i < NTEMP; ++i)
LENMAX = std::max(SBSYMCODES[i].codelen, LENMAX);
@@ -1331,7 +1331,6 @@ bool CJBig2_Context::HuffmanAssignCode(JBig2HuffmanCode* SBSYMCODES,
for (uint32_t i = 0; i < NTEMP; ++i)
++LENCOUNT[SBSYMCODES[i].codelen];
- LENCOUNT[0] = 0;
for (int i = 1; i <= LENMAX; ++i) {
pdfium::base::CheckedNumeric<int> shifted = FIRSTCODE[i - 1];
shifted += LENCOUNT[i - 1];
@@ -1342,9 +1341,8 @@ bool CJBig2_Context::HuffmanAssignCode(JBig2HuffmanCode* SBSYMCODES,
FIRSTCODE[i] = shifted.ValueOrDie();
int CURCODE = FIRSTCODE[i];
for (uint32_t j = 0; j < NTEMP; ++j) {
- if (SBSYMCODES[j].codelen == i) {
+ if (SBSYMCODES[j].codelen == i)
SBSYMCODES[j].code = CURCODE++;
- }
}
}
return true;
diff --git a/core/fxcodec/jbig2/JBig2_Context.h b/core/fxcodec/jbig2/JBig2_Context.h
index 3f3304d8b7..e1ee679de7 100644
--- a/core/fxcodec/jbig2/JBig2_Context.h
+++ b/core/fxcodec/jbig2/JBig2_Context.h
@@ -45,6 +45,8 @@ class CJBig2_Context {
bool bIsGlobal);
~CJBig2_Context();
+ static bool HuffmanAssignCode(JBig2HuffmanCode* SBSYMCODES, uint32_t NTEMP);
+
int32_t GetFirstPage(uint8_t* pBuf,
int32_t width,
int32_t height,
@@ -82,8 +84,6 @@ class CJBig2_Context {
std::vector<JBig2HuffmanCode> DecodeSymbolIDHuffmanTable(uint32_t SBNUMSYMS);
- bool HuffmanAssignCode(JBig2HuffmanCode* SBSYMCODES, uint32_t NTEMP);
-
std::unique_ptr<CJBig2_Context> m_pGlobalContext;
std::unique_ptr<CJBig2_BitStream> m_pStream;
std::vector<std::unique_ptr<CJBig2_Segment>> m_SegmentList;
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) {
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanTable.h b/core/fxcodec/jbig2/JBig2_HuffmanTable.h
index cdfb53f4fc..1f4cec0ad9 100644
--- a/core/fxcodec/jbig2/JBig2_HuffmanTable.h
+++ b/core/fxcodec/jbig2/JBig2_HuffmanTable.h
@@ -31,9 +31,8 @@ class CJBig2_HuffmanTable {
bool IsOK() const { return m_bOK; }
private:
- void ParseFromStandardTable(const JBig2TableLine* pTable);
+ bool ParseFromStandardTable(const JBig2TableLine* pTable);
bool ParseFromCodedBuffer(CJBig2_BitStream* pStream);
- bool InitCodes();
void ExtendBuffers(bool increment);
bool m_bOK;