diff options
author | Lei Zhang <thestig@chromium.org> | 2018-04-27 20:53:58 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-27 20:53:58 +0000 |
commit | 724f61671bec82f521be75b0ace069fb3130902a (patch) | |
tree | d96cba59467a28dc08b93d80b4224feb860cb1e9 /core/fxcodec/jbig2/JBig2_HuffmanTable.cpp | |
parent | ccd9426e7127373c13986fd4f8a029f744e9dad0 (diff) | |
download | pdfium-724f61671bec82f521be75b0ace069fb3130902a.tar.xz |
Change CJBig2_HuffmanTable to use struct JBig2HuffmanCode.
Change-Id: I6461f81a3d8005efa75b8141c18c502a63252883
Reviewed-on: https://pdfium-review.googlesource.com/31537
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.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp b/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp index 5a49e1e4be..aa3cd0be10 100644 --- a/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp +++ b/core/fxcodec/jbig2/JBig2_HuffmanTable.cpp @@ -11,7 +11,6 @@ #include <vector> #include "core/fxcodec/jbig2/JBig2_BitStream.h" -#include "core/fxcodec/jbig2/JBig2_Define.h" #include "core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h" #include "core/fxcrt/fx_memory.h" #include "third_party/base/numerics/safe_math.h" @@ -31,11 +30,11 @@ CJBig2_HuffmanTable::CJBig2_HuffmanTable(CJBig2_BitStream* pStream) CJBig2_HuffmanTable::~CJBig2_HuffmanTable() {} void CJBig2_HuffmanTable::ParseFromStandardTable(const JBig2TableLine* pTable) { - PREFLEN.resize(NTEMP); + CODES.resize(NTEMP); RANGELEN.resize(NTEMP); RANGELOW.resize(NTEMP); for (uint32_t i = 0; i < NTEMP; ++i) { - PREFLEN[i] = pTable[i].PREFLEN; + CODES[i].codelen = pTable[i].PREFLEN; RANGELEN[i] = pTable[i].RANDELEN; RANGELOW[i] = pTable[i].RANGELOW; } @@ -65,7 +64,7 @@ bool CJBig2_HuffmanTable::ParseFromCodedBuffer(CJBig2_BitStream* pStream) { ExtendBuffers(false); pdfium::base::CheckedNumeric<int> cur_low = low; do { - if ((pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) || + if ((pStream->readNBits(HTPS, &CODES[NTEMP].codelen) == -1) || (pStream->readNBits(HTRS, &RANGELEN[NTEMP]) == -1) || (static_cast<size_t>(RANGELEN[NTEMP]) >= 8 * sizeof(cur_low))) { return false; @@ -81,7 +80,7 @@ bool CJBig2_HuffmanTable::ParseFromCodedBuffer(CJBig2_BitStream* pStream) { ExtendBuffers(true); } while (cur_low.ValueOrDie() < high); - if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) + if (pStream->readNBits(HTPS, &CODES[NTEMP].codelen) == -1) return false; RANGELEN[NTEMP] = 32; @@ -91,7 +90,7 @@ bool CJBig2_HuffmanTable::ParseFromCodedBuffer(CJBig2_BitStream* pStream) { RANGELOW[NTEMP] = low - 1; ExtendBuffers(true); - if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) + if (pStream->readNBits(HTPS, &CODES[NTEMP].codelen) == -1) return false; RANGELEN[NTEMP] = 32; @@ -99,7 +98,7 @@ bool CJBig2_HuffmanTable::ParseFromCodedBuffer(CJBig2_BitStream* pStream) { ExtendBuffers(true); if (HTOOB) { - if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) + if (pStream->readNBits(HTPS, &CODES[NTEMP].codelen) == -1) return false; ++NTEMP; @@ -111,13 +110,12 @@ bool CJBig2_HuffmanTable::ParseFromCodedBuffer(CJBig2_BitStream* pStream) { bool CJBig2_HuffmanTable::InitCodes() { int lenmax = 0; for (uint32_t i = 0; i < NTEMP; ++i) - lenmax = std::max(PREFLEN[i], lenmax); + lenmax = std::max(CODES[i].codelen, lenmax); - CODES.resize(NTEMP); std::vector<int> LENCOUNT(lenmax + 1); std::vector<int> FIRSTCODE(lenmax + 1); - for (int len : PREFLEN) - ++LENCOUNT[len]; + for (uint32_t i = 0; i < NTEMP; ++i) + ++LENCOUNT[CODES[i].codelen]; FIRSTCODE[0] = 0; LENCOUNT[0] = 0; @@ -131,8 +129,8 @@ bool CJBig2_HuffmanTable::InitCodes() { FIRSTCODE[i] = shifted.ValueOrDie(); int CURCODE = FIRSTCODE[i]; for (uint32_t j = 0; j < NTEMP; ++j) { - if (PREFLEN[j] == i) - CODES[j] = CURCODE++; + if (CODES[j].codelen == i) + CODES[j].code = CURCODE++; } } @@ -143,13 +141,13 @@ void CJBig2_HuffmanTable::ExtendBuffers(bool increment) { if (increment) ++NTEMP; - size_t size = PREFLEN.size(); + size_t size = CODES.size(); if (NTEMP < size) return; size += 16; ASSERT(NTEMP < size); - PREFLEN.resize(size); + CODES.resize(size); RANGELEN.resize(size); RANGELOW.resize(size); } |