summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2018-05-16 22:28:22 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-16 22:28:22 +0000
commit1c0da4bf0f4235b50dade1c1d37fbd1f4421722d (patch)
tree91f5f0e3765bfadd3e92eed0ab96bdfe067439e4 /core/fxcodec/jbig2
parent98ec53359b8e61e717440f280d3fcc101fe140bb (diff)
downloadpdfium-1c0da4bf0f4235b50dade1c1d37fbd1f4421722d.tar.xz
Move JBig2 HuffmanTables into JBig2_HuffmanTable.cpp
This CL changes the table information so it can be indexed, and allows moving all of the information to the CJBig2_HuffmanTable implementation, which is the only real user of the data. Change-Id: I88780bee32c8509198518fd3b1e82d68ae7ff707 Reviewed-on: https://pdfium-review.googlesource.com/32635 Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcodec/jbig2')
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp70
-rw-r--r--core/fxcodec/jbig2/JBig2_HuffmanTable.cpp127
-rw-r--r--core/fxcodec/jbig2/JBig2_HuffmanTable.h7
-rw-r--r--core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.cpp118
-rw-r--r--core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h78
-rw-r--r--core/fxcodec/jbig2/JBig2_SddProc.cpp58
6 files changed, 164 insertions, 294 deletions
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 37971cec94..f49276444f 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -19,7 +19,6 @@
#include "core/fxcodec/jbig2/JBig2_GrdProc.h"
#include "core/fxcodec/jbig2/JBig2_GrrdProc.h"
#include "core/fxcodec/jbig2/JBig2_HtrdProc.h"
-#include "core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h"
#include "core/fxcodec/jbig2/JBig2_PddProc.h"
#include "core/fxcodec/jbig2/JBig2_SddProc.h"
#include "core/fxcodec/jbig2/JBig2_TrdProc.h"
@@ -489,12 +488,10 @@ JBig2_Result CJBig2_Context::ParseSymbolDict(CJBig2_Segment* pSegment) {
int32_t nIndex = 0;
if (cSDHUFFDH == 0) {
- Table_B4 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B4, HuffmanTable_B4_Size, HuffmanTable_HTOOB_B4);
+ Table_B4 = pdfium::MakeUnique<CJBig2_HuffmanTable>(4);
pSymbolDictDecoder->SDHUFFDH = Table_B4.get();
} else if (cSDHUFFDH == 1) {
- Table_B5 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B5, HuffmanTable_B5_Size, HuffmanTable_HTOOB_B5);
+ Table_B5 = pdfium::MakeUnique<CJBig2_HuffmanTable>(5);
pSymbolDictDecoder->SDHUFFDH = Table_B5.get();
} else {
CJBig2_Segment* pSeg =
@@ -504,12 +501,10 @@ JBig2_Result CJBig2_Context::ParseSymbolDict(CJBig2_Segment* pSegment) {
pSymbolDictDecoder->SDHUFFDH = pSeg->m_HuffmanTable.get();
}
if (cSDHUFFDW == 0) {
- Table_B2 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B2, HuffmanTable_B2_Size, HuffmanTable_HTOOB_B2);
+ Table_B2 = pdfium::MakeUnique<CJBig2_HuffmanTable>(2);
pSymbolDictDecoder->SDHUFFDW = Table_B2.get();
} else if (cSDHUFFDW == 1) {
- Table_B3 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B3, HuffmanTable_B3_Size, HuffmanTable_HTOOB_B3);
+ Table_B3 = pdfium::MakeUnique<CJBig2_HuffmanTable>(3);
pSymbolDictDecoder->SDHUFFDW = Table_B3.get();
} else {
CJBig2_Segment* pSeg =
@@ -519,8 +514,7 @@ JBig2_Result CJBig2_Context::ParseSymbolDict(CJBig2_Segment* pSegment) {
pSymbolDictDecoder->SDHUFFDW = pSeg->m_HuffmanTable.get();
}
if (cSDHUFFBMSIZE == 0) {
- Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B1, HuffmanTable_B1_Size, HuffmanTable_HTOOB_B1);
+ Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
pSymbolDictDecoder->SDHUFFBMSIZE = Table_B1.get();
} else {
CJBig2_Segment* pSeg =
@@ -532,8 +526,7 @@ JBig2_Result CJBig2_Context::ParseSymbolDict(CJBig2_Segment* pSegment) {
if (pSymbolDictDecoder->SDREFAGG == 1) {
if (cSDHUFFAGGINST == 0) {
if (!Table_B1) {
- Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B1, HuffmanTable_B1_Size, HuffmanTable_HTOOB_B1);
+ Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
}
pSymbolDictDecoder->SDHUFFAGGINST = Table_B1.get();
} else {
@@ -761,12 +754,10 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) {
}
int32_t nIndex = 0;
if (cSBHUFFFS == 0) {
- Table_B6 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B6, HuffmanTable_B6_Size, HuffmanTable_HTOOB_B6);
+ Table_B6 = pdfium::MakeUnique<CJBig2_HuffmanTable>(6);
pTRD->SBHUFFFS = Table_B6.get();
} else if (cSBHUFFFS == 1) {
- Table_B7 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B7, HuffmanTable_B7_Size, HuffmanTable_HTOOB_B7);
+ Table_B7 = pdfium::MakeUnique<CJBig2_HuffmanTable>(7);
pTRD->SBHUFFFS = Table_B7.get();
} else {
CJBig2_Segment* pSeg =
@@ -776,16 +767,13 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) {
pTRD->SBHUFFFS = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFDS == 0) {
- Table_B8 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B8, HuffmanTable_B8_Size, HuffmanTable_HTOOB_B8);
+ Table_B8 = pdfium::MakeUnique<CJBig2_HuffmanTable>(8);
pTRD->SBHUFFDS = Table_B8.get();
} else if (cSBHUFFDS == 1) {
- Table_B9 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B9, HuffmanTable_B9_Size, HuffmanTable_HTOOB_B9);
+ Table_B9 = pdfium::MakeUnique<CJBig2_HuffmanTable>(9);
pTRD->SBHUFFDS = Table_B9.get();
} else if (cSBHUFFDS == 2) {
- Table_B10 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B10, HuffmanTable_B10_Size, HuffmanTable_HTOOB_B10);
+ Table_B10 = pdfium::MakeUnique<CJBig2_HuffmanTable>(10);
pTRD->SBHUFFDS = Table_B10.get();
} else {
CJBig2_Segment* pSeg =
@@ -795,16 +783,13 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) {
pTRD->SBHUFFDS = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFDT == 0) {
- Table_B11 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B11, HuffmanTable_B11_Size, HuffmanTable_HTOOB_B11);
+ Table_B11 = pdfium::MakeUnique<CJBig2_HuffmanTable>(11);
pTRD->SBHUFFDT = Table_B11.get();
} else if (cSBHUFFDT == 1) {
- Table_B12 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B12, HuffmanTable_B12_Size, HuffmanTable_HTOOB_B12);
+ Table_B12 = pdfium::MakeUnique<CJBig2_HuffmanTable>(12);
pTRD->SBHUFFDT = Table_B12.get();
} else if (cSBHUFFDT == 2) {
- Table_B13 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B13, HuffmanTable_B13_Size, HuffmanTable_HTOOB_B13);
+ Table_B13 = pdfium::MakeUnique<CJBig2_HuffmanTable>(13);
pTRD->SBHUFFDT = Table_B13.get();
} else {
CJBig2_Segment* pSeg =
@@ -814,12 +799,10 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) {
pTRD->SBHUFFDT = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFRDW == 0) {
- Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B14, HuffmanTable_B14_Size, HuffmanTable_HTOOB_B14);
+ Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(14);
pTRD->SBHUFFRDW = Table_B14.get();
} else if (cSBHUFFRDW == 1) {
- Table_B15 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
+ Table_B15 = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
pTRD->SBHUFFRDW = Table_B15.get();
} else {
CJBig2_Segment* pSeg =
@@ -830,14 +813,12 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) {
}
if (cSBHUFFRDH == 0) {
if (!Table_B14) {
- Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B14, HuffmanTable_B14_Size, HuffmanTable_HTOOB_B14);
+ Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(14);
}
pTRD->SBHUFFRDH = Table_B14.get();
} else if (cSBHUFFRDH == 1) {
if (!Table_B15) {
- Table_B15 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
+ Table_B15 = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
}
pTRD->SBHUFFRDH = Table_B15.get();
} else {
@@ -849,14 +830,12 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) {
}
if (cSBHUFFRDX == 0) {
if (!Table_B14) {
- Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B14, HuffmanTable_B14_Size, HuffmanTable_HTOOB_B14);
+ Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(14);
}
pTRD->SBHUFFRDX = Table_B14.get();
} else if (cSBHUFFRDX == 1) {
if (!Table_B15) {
- Table_B15 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
+ Table_B15 = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
}
pTRD->SBHUFFRDX = Table_B15.get();
} else {
@@ -868,14 +847,12 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) {
}
if (cSBHUFFRDY == 0) {
if (!Table_B14) {
- Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B14, HuffmanTable_B14_Size, HuffmanTable_HTOOB_B14);
+ Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(14);
}
pTRD->SBHUFFRDY = Table_B14.get();
} else if (cSBHUFFRDY == 1) {
if (!Table_B15) {
- Table_B15 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
+ Table_B15 = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
}
pTRD->SBHUFFRDY = Table_B15.get();
} else {
@@ -886,8 +863,7 @@ JBig2_Result CJBig2_Context::ParseTextRegion(CJBig2_Segment* pSegment) {
pTRD->SBHUFFRDY = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFRSIZE == 0) {
- Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B1, HuffmanTable_B1_Size, HuffmanTable_HTOOB_B1);
+ Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
pTRD->SBHUFFRSIZE = Table_B1.get();
} else {
CJBig2_Segment* pSeg =
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp b/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp
index 988978a699..97740a55fe 100644
--- a/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp
+++ b/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp
@@ -11,15 +11,127 @@
#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"
-CJBig2_HuffmanTable::CJBig2_HuffmanTable(const JBig2TableLine* pTable,
- uint32_t nLines,
- bool bHTOOB)
- : HTOOB(bHTOOB), NTEMP(nLines) {
- m_bOK = ParseFromStandardTable(pTable);
+namespace {
+
+struct JBig2TableLine {
+ uint8_t PREFLEN;
+ uint8_t RANDELEN;
+ int32_t RANGELOW;
+};
+
+struct HuffmanTable {
+ bool HTOOB;
+ const JBig2TableLine* lines;
+ size_t size;
+};
+
+constexpr JBig2TableLine kTableLine1[] = {{1, 4, 0},
+ {2, 8, 16},
+ {3, 16, 272},
+ {0, 32, -1},
+ {3, 32, 65808}};
+
+constexpr JBig2TableLine kTableLine2[] = {{1, 0, 0}, {2, 0, 1}, {3, 0, 2},
+ {4, 3, 3}, {5, 6, 11}, {0, 32, -1},
+ {6, 32, 75}, {6, 0, 0}};
+
+constexpr JBig2TableLine kTableLine3[] = {
+ {8, 8, -256}, {1, 0, 0}, {2, 0, 1}, {3, 0, 2}, {4, 3, 3},
+ {5, 6, 11}, {8, 32, -257}, {7, 32, 75}, {6, 0, 0}};
+
+constexpr JBig2TableLine kTableLine4[] = {{1, 0, 1}, {2, 0, 2}, {3, 0, 3},
+ {4, 3, 4}, {5, 6, 12}, {0, 32, -1},
+ {5, 32, 76}};
+
+constexpr JBig2TableLine kTableLine5[] = {{7, 8, -255}, {1, 0, 1}, {2, 0, 2},
+ {3, 0, 3}, {4, 3, 4}, {5, 6, 12},
+ {7, 32, -256}, {6, 32, 76}};
+
+constexpr JBig2TableLine kTableLine6[] = {
+ {5, 10, -2048}, {4, 9, -1024}, {4, 8, -512}, {4, 7, -256}, {5, 6, -128},
+ {5, 5, -64}, {4, 5, -32}, {2, 7, 0}, {3, 7, 128}, {3, 8, 256},
+ {4, 9, 512}, {4, 10, 1024}, {6, 32, -2049}, {6, 32, 2048}};
+
+constexpr JBig2TableLine kTableLine7[] = {
+ {4, 9, -1024}, {3, 8, -512}, {4, 7, -256}, {5, 6, -128}, {5, 5, -64},
+ {4, 5, -32}, {4, 5, 0}, {5, 5, 32}, {5, 6, 64}, {4, 7, 128},
+ {3, 8, 256}, {3, 9, 512}, {3, 10, 1024}, {5, 32, -1025}, {5, 32, 2048}};
+
+constexpr JBig2TableLine kTableLine8[] = {
+ {8, 3, -15}, {9, 1, -7}, {8, 1, -5}, {9, 0, -3}, {7, 0, -2},
+ {4, 0, -1}, {2, 1, 0}, {5, 0, 2}, {6, 0, 3}, {3, 4, 4},
+ {6, 1, 20}, {4, 4, 22}, {4, 5, 38}, {5, 6, 70}, {5, 7, 134},
+ {6, 7, 262}, {7, 8, 390}, {6, 10, 646}, {9, 32, -16}, {9, 32, 1670},
+ {2, 0, 0}};
+
+constexpr JBig2TableLine kTableLine9[] = {
+ {8, 4, -31}, {9, 2, -15}, {8, 2, -11}, {9, 1, -7}, {7, 1, -5},
+ {4, 1, -3}, {3, 1, -1}, {3, 1, 1}, {5, 1, 3}, {6, 1, 5},
+ {3, 5, 7}, {6, 2, 39}, {4, 5, 43}, {4, 6, 75}, {5, 7, 139},
+ {5, 8, 267}, {6, 8, 523}, {7, 9, 779}, {6, 11, 1291}, {9, 32, -32},
+ {9, 32, 3339}, {2, 0, 0}};
+
+constexpr JBig2TableLine kTableLine10[] = {
+ {7, 4, -21}, {8, 0, -5}, {7, 0, -4}, {5, 0, -3}, {2, 2, -2},
+ {5, 0, 2}, {6, 0, 3}, {7, 0, 4}, {8, 0, 5}, {2, 6, 6},
+ {5, 5, 70}, {6, 5, 102}, {6, 6, 134}, {6, 7, 198}, {6, 8, 326},
+ {6, 9, 582}, {6, 10, 1094}, {7, 11, 2118}, {8, 32, -22}, {8, 32, 4166},
+ {2, 0, 0}};
+
+constexpr JBig2TableLine kTableLine11[] = {
+ {1, 0, 1}, {2, 1, 2}, {4, 0, 4}, {4, 1, 5}, {5, 1, 7},
+ {5, 2, 9}, {6, 2, 13}, {7, 2, 17}, {7, 3, 21}, {7, 4, 29},
+ {7, 5, 45}, {7, 6, 77}, {0, 32, 0}, {7, 32, 141}};
+
+constexpr JBig2TableLine kTableLine12[] = {
+ {1, 0, 1}, {2, 0, 2}, {3, 1, 3}, {5, 0, 5}, {5, 1, 6},
+ {6, 1, 8}, {7, 0, 10}, {7, 1, 11}, {7, 2, 13}, {7, 3, 17},
+ {7, 4, 25}, {8, 5, 41}, {0, 32, 0}, {8, 32, 73}};
+
+constexpr JBig2TableLine kTableLine13[] = {
+ {1, 0, 1}, {3, 0, 2}, {4, 0, 3}, {5, 0, 4}, {4, 1, 5},
+ {3, 3, 7}, {6, 1, 15}, {6, 2, 17}, {6, 3, 21}, {6, 4, 29},
+ {6, 5, 45}, {7, 6, 77}, {0, 32, 0}, {7, 32, 141}};
+
+constexpr JBig2TableLine kTableLine14[] = {{3, 0, -2}, {3, 0, -1}, {1, 0, 0},
+ {3, 0, 1}, {3, 0, 2}, {0, 32, -3},
+ {0, 32, 3}};
+
+constexpr JBig2TableLine kTableLine15[] = {
+ {7, 4, -24}, {6, 2, -8}, {5, 1, -4}, {4, 0, -2}, {3, 0, -1},
+ {1, 0, 0}, {3, 0, 1}, {4, 0, 2}, {5, 1, 3}, {6, 2, 5},
+ {7, 4, 9}, {7, 32, -25}, {7, 32, 25}};
+
+constexpr HuffmanTable kHuffmanTables[16] = {
+ {false, nullptr, 0}, // Zero dummy to preserve indexing.
+ {false, kTableLine1, FX_ArraySize(kTableLine1)},
+ {true, kTableLine2, FX_ArraySize(kTableLine2)},
+ {true, kTableLine3, FX_ArraySize(kTableLine3)},
+ {false, kTableLine4, FX_ArraySize(kTableLine4)},
+ {false, kTableLine5, FX_ArraySize(kTableLine5)},
+ {false, kTableLine6, FX_ArraySize(kTableLine6)},
+ {false, kTableLine7, FX_ArraySize(kTableLine7)},
+ {true, kTableLine8, FX_ArraySize(kTableLine8)},
+ {true, kTableLine9, FX_ArraySize(kTableLine9)},
+ {true, kTableLine10, FX_ArraySize(kTableLine10)},
+ {false, kTableLine11, FX_ArraySize(kTableLine11)},
+ {false, kTableLine12, FX_ArraySize(kTableLine12)},
+ {false, kTableLine13, FX_ArraySize(kTableLine13)},
+ {false, kTableLine14, FX_ArraySize(kTableLine14)},
+ {false, kTableLine15, FX_ArraySize(kTableLine15)}};
+
+} // namespace
+
+CJBig2_HuffmanTable::CJBig2_HuffmanTable(size_t idx) {
+ ASSERT(idx > 0);
+ ASSERT(idx < FX_ArraySize(kHuffmanTables));
+ const HuffmanTable& table = kHuffmanTables[idx];
+ HTOOB = table.HTOOB;
+ NTEMP = table.size;
+ m_bOK = ParseFromStandardTable(idx);
ASSERT(m_bOK);
}
@@ -30,7 +142,8 @@ CJBig2_HuffmanTable::CJBig2_HuffmanTable(CJBig2_BitStream* pStream)
CJBig2_HuffmanTable::~CJBig2_HuffmanTable() {}
-bool CJBig2_HuffmanTable::ParseFromStandardTable(const JBig2TableLine* pTable) {
+bool CJBig2_HuffmanTable::ParseFromStandardTable(size_t idx) {
+ const JBig2TableLine* pTable = kHuffmanTables[idx].lines;
CODES.resize(NTEMP);
RANGELEN.resize(NTEMP);
RANGELOW.resize(NTEMP);
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanTable.h b/core/fxcodec/jbig2/JBig2_HuffmanTable.h
index 1f4cec0ad9..86d925c3d4 100644
--- a/core/fxcodec/jbig2/JBig2_HuffmanTable.h
+++ b/core/fxcodec/jbig2/JBig2_HuffmanTable.h
@@ -13,13 +13,10 @@
#include "core/fxcrt/fx_system.h"
class CJBig2_BitStream;
-struct JBig2TableLine;
class CJBig2_HuffmanTable {
public:
- CJBig2_HuffmanTable(const JBig2TableLine* pTable,
- uint32_t nLines,
- bool bHTOOB);
+ explicit CJBig2_HuffmanTable(size_t idx);
explicit CJBig2_HuffmanTable(CJBig2_BitStream* pStream);
~CJBig2_HuffmanTable();
@@ -31,7 +28,7 @@ class CJBig2_HuffmanTable {
bool IsOK() const { return m_bOK; }
private:
- bool ParseFromStandardTable(const JBig2TableLine* pTable);
+ bool ParseFromStandardTable(size_t table_idx);
bool ParseFromCodedBuffer(CJBig2_BitStream* pStream);
void ExtendBuffers(bool increment);
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.cpp b/core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.cpp
deleted file mode 100644
index abff7868e8..0000000000
--- a/core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h"
-
-#include "core/fxcrt/fx_memory.h"
-
-const bool HuffmanTable_HTOOB_B1 = false;
-const JBig2TableLine HuffmanTable_B1[] = {{1, 4, 0},
- {2, 8, 16},
- {3, 16, 272},
- {0, 32, -1},
- {3, 32, 65808}};
-const size_t HuffmanTable_B1_Size = FX_ArraySize(HuffmanTable_B1);
-
-const bool HuffmanTable_HTOOB_B2 = true;
-const JBig2TableLine HuffmanTable_B2[] = {{1, 0, 0}, {2, 0, 1}, {3, 0, 2},
- {4, 3, 3}, {5, 6, 11}, {0, 32, -1},
- {6, 32, 75}, {6, 0, 0}};
-const size_t HuffmanTable_B2_Size = FX_ArraySize(HuffmanTable_B2);
-
-const bool HuffmanTable_HTOOB_B3 = true;
-const JBig2TableLine HuffmanTable_B3[] = {
- {8, 8, -256}, {1, 0, 0}, {2, 0, 1}, {3, 0, 2}, {4, 3, 3},
- {5, 6, 11}, {8, 32, -257}, {7, 32, 75}, {6, 0, 0}};
-const size_t HuffmanTable_B3_Size = FX_ArraySize(HuffmanTable_B3);
-
-const bool HuffmanTable_HTOOB_B4 = false;
-const JBig2TableLine HuffmanTable_B4[] = {
- {1, 0, 1}, {2, 0, 2}, {3, 0, 3}, {4, 3, 4},
- {5, 6, 12}, {0, 32, -1}, {5, 32, 76},
-};
-const size_t HuffmanTable_B4_Size = FX_ArraySize(HuffmanTable_B4);
-
-const bool HuffmanTable_HTOOB_B5 = false;
-const JBig2TableLine HuffmanTable_B5[] = {{7, 8, -255}, {1, 0, 1}, {2, 0, 2},
- {3, 0, 3}, {4, 3, 4}, {5, 6, 12},
- {7, 32, -256}, {6, 32, 76}};
-const size_t HuffmanTable_B5_Size = FX_ArraySize(HuffmanTable_B5);
-
-const bool HuffmanTable_HTOOB_B6 = false;
-const JBig2TableLine HuffmanTable_B6[] = {
- {5, 10, -2048}, {4, 9, -1024}, {4, 8, -512}, {4, 7, -256}, {5, 6, -128},
- {5, 5, -64}, {4, 5, -32}, {2, 7, 0}, {3, 7, 128}, {3, 8, 256},
- {4, 9, 512}, {4, 10, 1024}, {6, 32, -2049}, {6, 32, 2048}};
-const size_t HuffmanTable_B6_Size = FX_ArraySize(HuffmanTable_B6);
-
-const bool HuffmanTable_HTOOB_B7 = false;
-const JBig2TableLine HuffmanTable_B7[] = {
- {4, 9, -1024}, {3, 8, -512}, {4, 7, -256}, {5, 6, -128}, {5, 5, -64},
- {4, 5, -32}, {4, 5, 0}, {5, 5, 32}, {5, 6, 64}, {4, 7, 128},
- {3, 8, 256}, {3, 9, 512}, {3, 10, 1024}, {5, 32, -1025}, {5, 32, 2048},
-};
-const size_t HuffmanTable_B7_Size = FX_ArraySize(HuffmanTable_B7);
-
-const bool HuffmanTable_HTOOB_B8 = true;
-const JBig2TableLine HuffmanTable_B8[] = {
- {8, 3, -15}, {9, 1, -7}, {8, 1, -5}, {9, 0, -3}, {7, 0, -2},
- {4, 0, -1}, {2, 1, 0}, {5, 0, 2}, {6, 0, 3}, {3, 4, 4},
- {6, 1, 20}, {4, 4, 22}, {4, 5, 38}, {5, 6, 70}, {5, 7, 134},
- {6, 7, 262}, {7, 8, 390}, {6, 10, 646}, {9, 32, -16}, {9, 32, 1670},
- {2, 0, 0}};
-const size_t HuffmanTable_B8_Size = FX_ArraySize(HuffmanTable_B8);
-
-const bool HuffmanTable_HTOOB_B9 = true;
-const JBig2TableLine HuffmanTable_B9[] = {
- {8, 4, -31}, {9, 2, -15}, {8, 2, -11}, {9, 1, -7}, {7, 1, -5},
- {4, 1, -3}, {3, 1, -1}, {3, 1, 1}, {5, 1, 3}, {6, 1, 5},
- {3, 5, 7}, {6, 2, 39}, {4, 5, 43}, {4, 6, 75}, {5, 7, 139},
- {5, 8, 267}, {6, 8, 523}, {7, 9, 779}, {6, 11, 1291}, {9, 32, -32},
- {9, 32, 3339}, {2, 0, 0}};
-const size_t HuffmanTable_B9_Size = FX_ArraySize(HuffmanTable_B9);
-
-const bool HuffmanTable_HTOOB_B10 = true;
-const JBig2TableLine HuffmanTable_B10[] = {
- {7, 4, -21}, {8, 0, -5}, {7, 0, -4}, {5, 0, -3}, {2, 2, -2},
- {5, 0, 2}, {6, 0, 3}, {7, 0, 4}, {8, 0, 5}, {2, 6, 6},
- {5, 5, 70}, {6, 5, 102}, {6, 6, 134}, {6, 7, 198}, {6, 8, 326},
- {6, 9, 582}, {6, 10, 1094}, {7, 11, 2118}, {8, 32, -22}, {8, 32, 4166},
- {2, 0, 0}};
-const size_t HuffmanTable_B10_Size = FX_ArraySize(HuffmanTable_B10);
-
-const bool HuffmanTable_HTOOB_B11 = false;
-const JBig2TableLine HuffmanTable_B11[] = {
- {1, 0, 1}, {2, 1, 2}, {4, 0, 4}, {4, 1, 5}, {5, 1, 7},
- {5, 2, 9}, {6, 2, 13}, {7, 2, 17}, {7, 3, 21}, {7, 4, 29},
- {7, 5, 45}, {7, 6, 77}, {0, 32, 0}, {7, 32, 141}};
-const size_t HuffmanTable_B11_Size = FX_ArraySize(HuffmanTable_B11);
-
-const bool HuffmanTable_HTOOB_B12 = false;
-const JBig2TableLine HuffmanTable_B12[] = {
- {1, 0, 1}, {2, 0, 2}, {3, 1, 3}, {5, 0, 5}, {5, 1, 6},
- {6, 1, 8}, {7, 0, 10}, {7, 1, 11}, {7, 2, 13}, {7, 3, 17},
- {7, 4, 25}, {8, 5, 41}, {0, 32, 0}, {8, 32, 73}};
-const size_t HuffmanTable_B12_Size = FX_ArraySize(HuffmanTable_B12);
-
-const bool HuffmanTable_HTOOB_B13 = false;
-const JBig2TableLine HuffmanTable_B13[] = {
- {1, 0, 1}, {3, 0, 2}, {4, 0, 3}, {5, 0, 4}, {4, 1, 5},
- {3, 3, 7}, {6, 1, 15}, {6, 2, 17}, {6, 3, 21}, {6, 4, 29},
- {6, 5, 45}, {7, 6, 77}, {0, 32, 0}, {7, 32, 141}};
-const size_t HuffmanTable_B13_Size = FX_ArraySize(HuffmanTable_B13);
-
-const bool HuffmanTable_HTOOB_B14 = false;
-const JBig2TableLine HuffmanTable_B14[] = {{3, 0, -2}, {3, 0, -1}, {1, 0, 0},
- {3, 0, 1}, {3, 0, 2}, {0, 32, -3},
- {0, 32, 3}};
-const size_t HuffmanTable_B14_Size = FX_ArraySize(HuffmanTable_B14);
-
-const bool HuffmanTable_HTOOB_B15 = false;
-const JBig2TableLine HuffmanTable_B15[] = {
- {7, 4, -24}, {6, 2, -8}, {5, 1, -4}, {4, 0, -2}, {3, 0, -1},
- {1, 0, 0}, {3, 0, 1}, {4, 0, 2}, {5, 1, 3}, {6, 2, 5},
- {7, 4, 9}, {7, 32, -25}, {7, 32, 25}};
-const size_t HuffmanTable_B15_Size = FX_ArraySize(HuffmanTable_B15);
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h b/core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h
deleted file mode 100644
index c064f57d0c..0000000000
--- a/core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FXCODEC_JBIG2_JBIG2_HUFFMANTABLE_STANDARD_H_
-#define CORE_FXCODEC_JBIG2_JBIG2_HUFFMANTABLE_STANDARD_H_
-
-#include "core/fxcrt/fx_system.h"
-
-struct JBig2TableLine {
- uint8_t PREFLEN;
- uint8_t RANDELEN;
- int32_t RANGELOW;
-};
-
-extern const bool HuffmanTable_HTOOB_B1;
-extern const JBig2TableLine HuffmanTable_B1[];
-extern const size_t HuffmanTable_B1_Size;
-
-extern const bool HuffmanTable_HTOOB_B2;
-extern const JBig2TableLine HuffmanTable_B2[];
-extern const size_t HuffmanTable_B2_Size;
-
-extern const bool HuffmanTable_HTOOB_B3;
-extern const JBig2TableLine HuffmanTable_B3[];
-extern const size_t HuffmanTable_B3_Size;
-
-extern const bool HuffmanTable_HTOOB_B4;
-extern const JBig2TableLine HuffmanTable_B4[];
-extern const size_t HuffmanTable_B4_Size;
-
-extern const bool HuffmanTable_HTOOB_B5;
-extern const JBig2TableLine HuffmanTable_B5[];
-extern const size_t HuffmanTable_B5_Size;
-
-extern const bool HuffmanTable_HTOOB_B6;
-extern const JBig2TableLine HuffmanTable_B6[];
-extern const size_t HuffmanTable_B6_Size;
-
-extern const bool HuffmanTable_HTOOB_B7;
-extern const JBig2TableLine HuffmanTable_B7[];
-extern const size_t HuffmanTable_B7_Size;
-
-extern const bool HuffmanTable_HTOOB_B8;
-extern const JBig2TableLine HuffmanTable_B8[];
-extern const size_t HuffmanTable_B8_Size;
-
-extern const bool HuffmanTable_HTOOB_B9;
-extern const JBig2TableLine HuffmanTable_B9[];
-extern const size_t HuffmanTable_B9_Size;
-
-extern const bool HuffmanTable_HTOOB_B10;
-extern const JBig2TableLine HuffmanTable_B10[];
-extern const size_t HuffmanTable_B10_Size;
-
-extern const bool HuffmanTable_HTOOB_B11;
-extern const JBig2TableLine HuffmanTable_B11[];
-extern const size_t HuffmanTable_B11_Size;
-
-extern const bool HuffmanTable_HTOOB_B12;
-extern const JBig2TableLine HuffmanTable_B12[];
-extern const size_t HuffmanTable_B12_Size;
-
-extern const bool HuffmanTable_HTOOB_B13;
-extern const JBig2TableLine HuffmanTable_B13[];
-extern const size_t HuffmanTable_B13_Size;
-
-extern const bool HuffmanTable_HTOOB_B14;
-extern const JBig2TableLine HuffmanTable_B14[];
-extern const size_t HuffmanTable_B14_Size;
-
-extern const bool HuffmanTable_HTOOB_B15;
-extern const JBig2TableLine HuffmanTable_B15[];
-extern const size_t HuffmanTable_B15_Size;
-
-#endif // CORE_FXCODEC_JBIG2_JBIG2_HUFFMANTABLE_STANDARD_H_
diff --git a/core/fxcodec/jbig2/JBig2_SddProc.cpp b/core/fxcodec/jbig2/JBig2_SddProc.cpp
index 3677076ab2..cf95ec175f 100644
--- a/core/fxcodec/jbig2/JBig2_SddProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_SddProc.cpp
@@ -16,7 +16,6 @@
#include "core/fxcodec/jbig2/JBig2_GrrdProc.h"
#include "core/fxcodec/jbig2/JBig2_HuffmanDecoder.h"
#include "core/fxcodec/jbig2/JBig2_HuffmanTable.h"
-#include "core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h"
#include "core/fxcodec/jbig2/JBig2_SymbolDict.h"
#include "core/fxcodec/jbig2/JBig2_TrdProc.h"
#include "third_party/base/ptr_util.h"
@@ -140,22 +139,14 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::DecodeArith(
pDecoder->TRANSPOSED = 0;
pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT;
pDecoder->SBDSOFFSET = 0;
- auto SBHUFFFS = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B6, HuffmanTable_B6_Size, HuffmanTable_HTOOB_B6);
- auto SBHUFFDS = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B8, HuffmanTable_B8_Size, HuffmanTable_HTOOB_B8);
- auto SBHUFFDT = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B11, HuffmanTable_B11_Size, HuffmanTable_HTOOB_B11);
- auto SBHUFFRDW = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRDH = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRDY = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B1, HuffmanTable_B1_Size, HuffmanTable_HTOOB_B1);
+ auto SBHUFFFS = pdfium::MakeUnique<CJBig2_HuffmanTable>(6);
+ auto SBHUFFDS = pdfium::MakeUnique<CJBig2_HuffmanTable>(8);
+ auto SBHUFFDT = pdfium::MakeUnique<CJBig2_HuffmanTable>(11);
+ auto SBHUFFRDW = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDH = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDY = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
pDecoder->SBHUFFFS = SBHUFFFS.get();
pDecoder->SBHUFFDS = SBHUFFDS.get();
pDecoder->SBHUFFDT = SBHUFFDT.get();
@@ -360,22 +351,14 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::DecodeHuffman(
pDecoder->TRANSPOSED = 0;
pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT;
pDecoder->SBDSOFFSET = 0;
- auto SBHUFFFS = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B6, HuffmanTable_B6_Size, HuffmanTable_HTOOB_B6);
- auto SBHUFFDS = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B8, HuffmanTable_B8_Size, HuffmanTable_HTOOB_B8);
- auto SBHUFFDT = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B11, HuffmanTable_B11_Size, HuffmanTable_HTOOB_B11);
- auto SBHUFFRDW = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRDH = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRDY = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B1, HuffmanTable_B1_Size, HuffmanTable_HTOOB_B1);
+ auto SBHUFFFS = pdfium::MakeUnique<CJBig2_HuffmanTable>(6);
+ auto SBHUFFDS = pdfium::MakeUnique<CJBig2_HuffmanTable>(8);
+ auto SBHUFFDT = pdfium::MakeUnique<CJBig2_HuffmanTable>(11);
+ auto SBHUFFRDW = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDH = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDY = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
pDecoder->SBHUFFFS = SBHUFFFS.get();
pDecoder->SBHUFFDS = SBHUFFDS.get();
pDecoder->SBHUFFDT = SBHUFFDT.get();
@@ -413,10 +396,8 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::DecodeHuffman(
if (IDI < SBNUMSYMS)
break;
}
- auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B15, HuffmanTable_B15_Size, HuffmanTable_HTOOB_B15);
- auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B1, HuffmanTable_B1_Size, HuffmanTable_HTOOB_B1);
+ auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
if ((pHuffmanDecoder->DecodeAValue(SBHUFFRDX.get(), &RDXI) != 0) ||
(pHuffmanDecoder->DecodeAValue(SBHUFFRDX.get(), &RDYI) != 0) ||
(pHuffmanDecoder->DecodeAValue(SBHUFFRSIZE.get(), &nVal) != 0)) {
@@ -494,8 +475,7 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::DecodeHuffman(
}
EXINDEX = 0;
CUREXFLAG = 0;
- pTable = pdfium::MakeUnique<CJBig2_HuffmanTable>(
- HuffmanTable_B1, HuffmanTable_B1_Size, HuffmanTable_HTOOB_B1);
+ pTable = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
EXFLAGS.resize(SDNUMINSYMS + SDNUMNEWSYMS);
num_ex_syms = 0;
while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) {