summaryrefslogtreecommitdiff
path: root/core/fxcodec
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-09-17 18:31:47 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-09-17 18:31:47 +0000
commitbff81396b7aee1cc195194d0d1122d8fbec7dfb9 (patch)
tree6659efa22a5f30ca4575ca662e05d90fc35aa536 /core/fxcodec
parentcb798258c433bec7087948fcbfff14d1e7683006 (diff)
downloadpdfium-bff81396b7aee1cc195194d0d1122d8fbec7dfb9.tar.xz
Make JBig2ArithCtx a class.
For better encapsulation. Change-Id: Ia6fd8056112d97d672b91a9a521a2978c807060f Reviewed-on: https://pdfium-review.googlesource.com/42605 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcodec')
-rw-r--r--core/fxcodec/jbig2/JBig2_ArithDecoder.cpp39
-rw-r--r--core/fxcodec/jbig2/JBig2_ArithDecoder.h23
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.h2
-rw-r--r--core/fxcodec/jbig2/JBig2_GrrdProc.h2
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.h2
-rw-r--r--core/fxcodec/jbig2/JBig2_PddProc.h2
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.h2
7 files changed, 41 insertions, 31 deletions
diff --git a/core/fxcodec/jbig2/JBig2_ArithDecoder.cpp b/core/fxcodec/jbig2/JBig2_ArithDecoder.cpp
index 7d9f8fec9e..b3a851524e 100644
--- a/core/fxcodec/jbig2/JBig2_ArithDecoder.cpp
+++ b/core/fxcodec/jbig2/JBig2_ArithDecoder.cpp
@@ -11,14 +11,7 @@
namespace {
-struct JBig2ArithQe {
- uint16_t Qe;
- uint8_t NMPS;
- uint8_t NLPS;
- uint8_t nSwitch;
-};
-
-const JBig2ArithQe kQeTable[] = {
+const JBig2ArithCtx::JBig2ArithQe kQeTable[] = {
// Stupid hack to keep clang-format from reformatting this badly.
{0x5601, 1, 1, 1}, {0x3401, 2, 6, 0}, {0x1801, 3, 9, 0},
{0x0AC1, 4, 12, 0}, {0x0521, 5, 29, 0}, {0x0221, 38, 33, 0},
@@ -39,21 +32,23 @@ const JBig2ArithQe kQeTable[] = {
const unsigned int kDefaultAValue = 0x8000;
-int DecodeNMPS(JBig2ArithCtx* pCX, const JBig2ArithQe& qe) {
- pCX->I = qe.NMPS;
- return pCX->MPS;
-}
+} // namespace
+
+JBig2ArithCtx::JBig2ArithCtx() = default;
-int DecodeNLPS(JBig2ArithCtx* pCX, const JBig2ArithQe& qe) {
+int JBig2ArithCtx::DecodeNLPS(const JBig2ArithQe& qe) {
// TODO(thestig): |D|, |MPS| and friends probably should be booleans.
- int D = 1 - pCX->MPS;
+ int D = 1 - m_MPS;
if (qe.nSwitch == 1)
- pCX->MPS = 1 - pCX->MPS;
- pCX->I = qe.NLPS;
+ m_MPS = 1 - m_MPS;
+ m_I = qe.NLPS;
return D;
}
-} // namespace
+int JBig2ArithCtx::DecodeNMPS(const JBig2ArithQe& qe) {
+ m_I = qe.NMPS;
+ return m_MPS;
+}
CJBig2_ArithDecoder::CJBig2_ArithDecoder(CJBig2_BitStream* pStream)
: m_Complete(false), m_FinishedStream(false), m_pStream(pStream) {
@@ -68,22 +63,22 @@ CJBig2_ArithDecoder::CJBig2_ArithDecoder(CJBig2_BitStream* pStream)
CJBig2_ArithDecoder::~CJBig2_ArithDecoder() {}
int CJBig2_ArithDecoder::Decode(JBig2ArithCtx* pCX) {
- if (!pCX || pCX->I >= FX_ArraySize(kQeTable))
+ if (!pCX || pCX->I() >= FX_ArraySize(kQeTable))
return 0;
- const JBig2ArithQe& qe = kQeTable[pCX->I];
+ const JBig2ArithCtx::JBig2ArithQe& qe = kQeTable[pCX->I()];
m_A -= qe.Qe;
if ((m_C >> 16) < m_A) {
if (m_A & kDefaultAValue)
- return pCX->MPS;
+ return pCX->MPS();
- const int D = m_A < qe.Qe ? DecodeNLPS(pCX, qe) : DecodeNMPS(pCX, qe);
+ const int D = m_A < qe.Qe ? pCX->DecodeNLPS(qe) : pCX->DecodeNMPS(qe);
ReadValueA();
return D;
}
m_C -= m_A << 16;
- const int D = m_A < qe.Qe ? DecodeNMPS(pCX, qe) : DecodeNLPS(pCX, qe);
+ const int D = m_A < qe.Qe ? pCX->DecodeNMPS(qe) : pCX->DecodeNLPS(qe);
m_A = qe.Qe;
ReadValueA();
return D;
diff --git a/core/fxcodec/jbig2/JBig2_ArithDecoder.h b/core/fxcodec/jbig2/JBig2_ArithDecoder.h
index 250e7009ff..0a233237b2 100644
--- a/core/fxcodec/jbig2/JBig2_ArithDecoder.h
+++ b/core/fxcodec/jbig2/JBig2_ArithDecoder.h
@@ -13,11 +13,26 @@
class CJBig2_BitStream;
-struct JBig2ArithCtx {
- JBig2ArithCtx() : MPS(0), I(0) {}
+class JBig2ArithCtx {
+ public:
+ struct JBig2ArithQe {
+ uint16_t Qe;
+ uint8_t NMPS;
+ uint8_t NLPS;
+ uint8_t nSwitch;
+ };
+
+ JBig2ArithCtx();
+
+ int DecodeNLPS(const JBig2ArithQe& qe);
+ int DecodeNMPS(const JBig2ArithQe& qe);
- unsigned int MPS;
- unsigned int I;
+ unsigned int MPS() const { return m_MPS; }
+ unsigned int I() const { return m_I; }
+
+ private:
+ unsigned int m_MPS = 0;
+ unsigned int m_I = 0;
};
class CJBig2_ArithDecoder {
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.h b/core/fxcodec/jbig2/JBig2_GrdProc.h
index a78e8cdbc1..af6f2232d1 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.h
@@ -17,8 +17,8 @@
class CJBig2_ArithDecoder;
class CJBig2_BitStream;
class CJBig2_Image;
+class JBig2ArithCtx;
class PauseIndicatorIface;
-struct JBig2ArithCtx;
class CJBig2_GRDProc {
public:
diff --git a/core/fxcodec/jbig2/JBig2_GrrdProc.h b/core/fxcodec/jbig2/JBig2_GrrdProc.h
index ec178a24c2..c7e3bf9d13 100644
--- a/core/fxcodec/jbig2/JBig2_GrrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_GrrdProc.h
@@ -14,7 +14,7 @@
class CJBig2_ArithDecoder;
class CJBig2_Image;
-struct JBig2ArithCtx;
+class JBig2ArithCtx;
class CJBig2_GRRDProc {
public:
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.h b/core/fxcodec/jbig2/JBig2_HtrdProc.h
index eab3f57970..cd90aae884 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.h
@@ -15,8 +15,8 @@
class CJBig2_ArithDecoder;
class CJBig2_BitStream;
+class JBig2ArithCtx;
class PauseIndicatorIface;
-struct JBig2ArithCtx;
class CJBig2_HTRDProc {
public:
diff --git a/core/fxcodec/jbig2/JBig2_PddProc.h b/core/fxcodec/jbig2/JBig2_PddProc.h
index 13590edb41..be5fadfb32 100644
--- a/core/fxcodec/jbig2/JBig2_PddProc.h
+++ b/core/fxcodec/jbig2/JBig2_PddProc.h
@@ -15,8 +15,8 @@ class CJBig2_ArithDecoder;
class CJBig2_BitStream;
class CJBig2_GRDProc;
class CJBig2_PatternDict;
+class JBig2ArithCtx;
class PauseIndicatorIface;
-struct JBig2ArithCtx;
class CJBig2_PDDProc {
public:
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.h b/core/fxcodec/jbig2/JBig2_TrdProc.h
index 855a13accb..8f4e42dd2e 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.h
@@ -19,7 +19,7 @@ class CJBig2_ArithIaidDecoder;
class CJBig2_ArithIntDecoder;
class CJBig2_BitStream;
class CJBig2_HuffmanTable;
-struct JBig2ArithCtx;
+class JBig2ArithCtx;
struct JBig2HuffmanCode;
struct JBig2IntDecoderState {