summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-01 14:37:54 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-01 14:37:54 +0000
commit1599b465904a312f0d0455cd26cdc9b0fe7b7d0c (patch)
tree38a7a3c997c642e91fe9a6e00086dfdf34382f73 /core/fxcodec/jbig2
parentea603b9f0baf33462b61fa4ee6364e4f4161f55a (diff)
downloadpdfium-1599b465904a312f0d0455cd26cdc9b0fe7b7d0c.tar.xz
Add struct CJBig2_GRDProc::ProgressiveArithDecodeState.
Track the decode state in one data structure. Also grab pointers to data structure members before tight loops when decoding. It turns out referring to this->foo in tight loops can actually slow down decoding. Change-Id: I6a09b08ca06ef05968966055b5ad20f8c89896af Reviewed-on: https://pdfium-review.googlesource.com/31790 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fxcodec/jbig2')
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp16
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.cpp263
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.h52
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.cpp12
-rw-r--r--core/fxcodec/jbig2/JBig2_PddProc.cpp12
5 files changed, 181 insertions, 174 deletions
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 76dff1d592..1763144b49 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -1094,15 +1094,19 @@ int32_t CJBig2_Context::ParseGenericRegion(CJBig2_Segment* pSegment,
if (m_pGRD->MMR == 0) {
if (m_gbContext.empty())
m_gbContext.resize(GetHuffContextSize(m_pGRD->GBTEMPLATE));
- if (!m_pArithDecoder) {
+
+ bool bStart = !m_pArithDecoder;
+ if (bStart) {
m_pArithDecoder =
pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
- m_ProcessingStatus = m_pGRD->StartDecodeArith(
- &pSegment->m_Image, m_pArithDecoder.get(), &m_gbContext[0], pPause);
- } else {
- m_ProcessingStatus =
- m_pGRD->ContinueDecode(pPause, m_pArithDecoder.get());
}
+ CJBig2_GRDProc::ProgressiveArithDecodeState state;
+ state.pImage = &pSegment->m_Image;
+ state.pArithDecoder = m_pArithDecoder.get();
+ state.gbContext = m_gbContext.data();
+ state.pPause = pPause;
+ m_ProcessingStatus = bStart ? m_pGRD->StartDecodeArith(&state)
+ : m_pGRD->ContinueDecode(&state);
if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
if (pSegment->m_cFlags.s.type != 36) {
if (!m_bBufSpecified) {
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
index ef3c2d8562..5343df269e 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
@@ -17,12 +17,7 @@
#include "core/fxcrt/pauseindicator_iface.h"
#include "third_party/base/ptr_util.h"
-CJBig2_GRDProc::CJBig2_GRDProc()
- : m_loopIndex(0),
- m_pLine(nullptr),
- m_DecodeType(0),
- m_LTP(0) {
-}
+CJBig2_GRDProc::CJBig2_GRDProc() {}
CJBig2_GRDProc::~CJBig2_GRDProc() {}
@@ -638,15 +633,13 @@ std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::DecodeArithTemplate3Unopt(
}
FXCODEC_STATUS CJBig2_GRDProc::StartDecodeArith(
- std::unique_ptr<CJBig2_Image>* pImage,
- CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
if (!CJBig2_Image::IsValidImageSize(GBW, GBH)) {
m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH;
return FXCODEC_STATUS_DECODE_FINISH;
}
m_ProssiveStatus = FXCODEC_STATUS_DECODE_READY;
+ std::unique_ptr<CJBig2_Image>* pImage = pState->pImage;
if (!*pImage)
*pImage = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!(*pImage)->data()) {
@@ -654,23 +647,20 @@ FXCODEC_STATUS CJBig2_GRDProc::StartDecodeArith(
m_ProssiveStatus = FXCODEC_STATUS_ERROR;
return FXCODEC_STATUS_ERROR;
}
+ pImage->get()->fill(0);
m_DecodeType = 1;
- m_pImage = pImage->get();
- m_pImage->fill(0);
- m_gbContext = gbContext;
m_LTP = 0;
m_pLine = nullptr;
m_loopIndex = 0;
- return ProgressiveDecodeArith(pPause, pArithDecoder);
+ return ProgressiveDecodeArith(pState);
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArith(
- PauseIndicatorIface* pPause,
- CJBig2_ArithDecoder* pArithDecoder) {
+ ProgressiveArithDecodeState* pState) {
int iline = m_loopIndex;
using DecodeFunction = std::function<FXCODEC_STATUS(
- CJBig2_GRDProc&, CJBig2_ArithDecoder*, PauseIndicatorIface*)>;
+ CJBig2_GRDProc&, ProgressiveArithDecodeState*)>;
DecodeFunction func;
switch (GBTEMPLATE) {
case 0:
@@ -694,9 +684,10 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArith(
: &CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Unopt;
break;
}
- m_ProssiveStatus = func(*this, pArithDecoder, pPause);
+ CJBig2_Image* pImage = pState->pImage->get();
+ m_ProssiveStatus = func(*this, pState);
m_ReplaceRect.left = 0;
- m_ReplaceRect.right = m_pImage->width();
+ m_ReplaceRect.right = pImage->width();
m_ReplaceRect.top = iline;
m_ReplaceRect.bottom = m_loopIndex;
if (m_ProssiveStatus == FXCODEC_STATUS_DECODE_FINISH)
@@ -727,8 +718,7 @@ FXCODEC_STATUS CJBig2_GRDProc::StartDecodeMMR(
}
FXCODEC_STATUS CJBig2_GRDProc::ContinueDecode(
- PauseIndicatorIface* pPause,
- CJBig2_ArithDecoder* pArithDecoder) {
+ ProgressiveArithDecodeState* pState) {
if (m_ProssiveStatus != FXCODEC_STATUS_DECODE_TOBECONTINUE)
return m_ProssiveStatus;
@@ -736,15 +726,17 @@ FXCODEC_STATUS CJBig2_GRDProc::ContinueDecode(
m_ProssiveStatus = FXCODEC_STATUS_ERROR;
return m_ProssiveStatus;
}
- return ProgressiveDecodeArith(pPause, pArithDecoder);
+ return ProgressiveDecodeArith(pState);
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
+ CJBig2_Image* pImage = pState->pImage->get();
+ JBig2ArithCtx* gbContext = pState->gbContext;
+ CJBig2_ArithDecoder* pArithDecoder = pState->pArithDecoder;
if (!m_pLine)
- m_pLine = m_pImage->data();
- int32_t nStride = m_pImage->stride();
+ m_pLine = pImage->data();
+ int32_t nStride = pImage->stride();
int32_t nStride2 = nStride << 1;
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
@@ -755,10 +747,10 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- m_LTP = m_LTP ^ pArithDecoder->Decode(&m_gbContext[0x9b25]);
+ m_LTP = m_LTP ^ pArithDecoder->Decode(&gbContext[0x9b25]);
}
if (m_LTP) {
- m_pImage->copyLine(m_loopIndex, m_loopIndex - 1);
+ pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
if (m_loopIndex > 1) {
uint8_t* pLine1 = m_pLine - nStride2;
@@ -774,7 +766,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010));
@@ -788,7 +780,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
(((CONTEXT & 0x7bf7) << 1) | bVal |
@@ -808,7 +800,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT =
(((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010));
@@ -821,7 +813,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
((line2 >> (7 - k)) & 0x0010));
@@ -830,7 +822,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3(
}
}
m_pLine += nStride;
- if (pPause && pPause->NeedToPauseNow()) {
+ if (pState->pPause && pState->pPause->NeedToPauseNow()) {
m_loopIndex++;
m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
return FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -841,23 +833,25 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3(
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Unopt(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
+ CJBig2_Image* pImage = pState->pImage->get();
+ JBig2ArithCtx* gbContext = pState->gbContext;
+ CJBig2_ArithDecoder* pArithDecoder = pState->pArithDecoder;
for (; m_loopIndex < GBH; m_loopIndex++) {
if (TPGDON) {
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- m_LTP = m_LTP ^ pArithDecoder->Decode(&m_gbContext[0x9b25]);
+ m_LTP = m_LTP ^ pArithDecoder->Decode(&gbContext[0x9b25]);
}
if (m_LTP) {
- m_pImage->copyLine(m_loopIndex, m_loopIndex - 1);
+ pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
- uint32_t line1 = m_pImage->getPixel(1, m_loopIndex - 2);
- line1 |= m_pImage->getPixel(0, m_loopIndex - 2) << 1;
- uint32_t line2 = m_pImage->getPixel(2, m_loopIndex - 1);
- line2 |= m_pImage->getPixel(1, m_loopIndex - 1) << 1;
- line2 |= m_pImage->getPixel(0, m_loopIndex - 1) << 2;
+ uint32_t line1 = pImage->getPixel(1, m_loopIndex - 2);
+ line1 |= pImage->getPixel(0, m_loopIndex - 2) << 1;
+ uint32_t line2 = pImage->getPixel(2, m_loopIndex - 1);
+ line2 |= pImage->getPixel(1, m_loopIndex - 1) << 1;
+ line2 |= pImage->getPixel(0, m_loopIndex - 1) << 2;
uint32_t line3 = 0;
for (uint32_t w = 0; w < GBW; w++) {
int bVal;
@@ -865,32 +859,28 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Unopt(
bVal = 0;
} else {
uint32_t CONTEXT = line3;
- CONTEXT |= m_pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1])
- << 4;
+ CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4;
CONTEXT |= line2 << 5;
- CONTEXT |= m_pImage->getPixel(w + GBAT[2], m_loopIndex + GBAT[3])
- << 10;
- CONTEXT |= m_pImage->getPixel(w + GBAT[4], m_loopIndex + GBAT[5])
- << 11;
+ CONTEXT |= pImage->getPixel(w + GBAT[2], m_loopIndex + GBAT[3]) << 10;
+ CONTEXT |= pImage->getPixel(w + GBAT[4], m_loopIndex + GBAT[5]) << 11;
CONTEXT |= line1 << 12;
- CONTEXT |= m_pImage->getPixel(w + GBAT[6], m_loopIndex + GBAT[7])
- << 15;
+ CONTEXT |= pImage->getPixel(w + GBAT[6], m_loopIndex + GBAT[7]) << 15;
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
}
if (bVal) {
- m_pImage->setPixel(w, m_loopIndex, bVal);
+ pImage->setPixel(w, m_loopIndex, bVal);
}
line1 =
- ((line1 << 1) | m_pImage->getPixel(w + 2, m_loopIndex - 2)) & 0x07;
+ ((line1 << 1) | pImage->getPixel(w + 2, m_loopIndex - 2)) & 0x07;
line2 =
- ((line2 << 1) | m_pImage->getPixel(w + 3, m_loopIndex - 1)) & 0x1f;
+ ((line2 << 1) | pImage->getPixel(w + 3, m_loopIndex - 1)) & 0x1f;
line3 = ((line3 << 1) | bVal) & 0x0f;
}
}
- if (pPause && pPause->NeedToPauseNow()) {
+ if (pState->pPause && pState->pPause->NeedToPauseNow()) {
m_loopIndex++;
m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
return FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -901,11 +891,13 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Unopt(
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
+ CJBig2_Image* pImage = pState->pImage->get();
+ JBig2ArithCtx* gbContext = pState->gbContext;
+ CJBig2_ArithDecoder* pArithDecoder = pState->pArithDecoder;
if (!m_pLine)
- m_pLine = m_pImage->data();
- int32_t nStride = m_pImage->stride();
+ m_pLine = pImage->data();
+ int32_t nStride = pImage->stride();
int32_t nStride2 = nStride << 1;
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
@@ -914,10 +906,10 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- m_LTP = m_LTP ^ pArithDecoder->Decode(&m_gbContext[0x0795]);
+ m_LTP = m_LTP ^ pArithDecoder->Decode(&gbContext[0x0795]);
}
if (m_LTP) {
- m_pImage->copyLine(m_loopIndex, m_loopIndex - 1);
+ pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
if (m_loopIndex > 1) {
uint8_t* pLine1 = m_pLine - nStride2;
@@ -933,7 +925,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008);
@@ -947,7 +939,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
((line1 >> (7 - k)) & 0x0200) |
@@ -967,7 +959,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
((line2 >> (k + 1)) & 0x0008);
@@ -980,7 +972,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008);
@@ -989,7 +981,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3(
}
}
m_pLine += nStride;
- if (pPause && pPause->NeedToPauseNow()) {
+ if (pState->pPause && pState->pPause->NeedToPauseNow()) {
m_loopIndex++;
m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
return FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -1000,24 +992,26 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3(
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Unopt(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
+ CJBig2_Image* pImage = pState->pImage->get();
+ JBig2ArithCtx* gbContext = pState->gbContext;
+ CJBig2_ArithDecoder* pArithDecoder = pState->pArithDecoder;
for (uint32_t h = 0; h < GBH; h++) {
if (TPGDON) {
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- m_LTP = m_LTP ^ pArithDecoder->Decode(&m_gbContext[0x0795]);
+ m_LTP = m_LTP ^ pArithDecoder->Decode(&gbContext[0x0795]);
}
if (m_LTP) {
- m_pImage->copyLine(h, h - 1);
+ pImage->copyLine(h, h - 1);
} else {
- uint32_t line1 = m_pImage->getPixel(2, h - 2);
- line1 |= m_pImage->getPixel(1, h - 2) << 1;
- line1 |= m_pImage->getPixel(0, h - 2) << 2;
- uint32_t line2 = m_pImage->getPixel(2, h - 1);
- line2 |= m_pImage->getPixel(1, h - 1) << 1;
- line2 |= m_pImage->getPixel(0, h - 1) << 2;
+ uint32_t line1 = pImage->getPixel(2, h - 2);
+ line1 |= pImage->getPixel(1, h - 2) << 1;
+ line1 |= pImage->getPixel(0, h - 2) << 2;
+ uint32_t line2 = pImage->getPixel(2, h - 1);
+ line2 |= pImage->getPixel(1, h - 1) << 1;
+ line2 |= pImage->getPixel(0, h - 1) << 2;
uint32_t line3 = 0;
for (uint32_t w = 0; w < GBW; w++) {
int bVal;
@@ -1025,23 +1019,23 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Unopt(
bVal = 0;
} else {
uint32_t CONTEXT = line3;
- CONTEXT |= m_pImage->getPixel(w + GBAT[0], h + GBAT[1]) << 3;
+ CONTEXT |= pImage->getPixel(w + GBAT[0], h + GBAT[1]) << 3;
CONTEXT |= line2 << 4;
CONTEXT |= line1 << 9;
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
}
if (bVal) {
- m_pImage->setPixel(w, h, bVal);
+ pImage->setPixel(w, h, bVal);
}
- line1 = ((line1 << 1) | m_pImage->getPixel(w + 3, h - 2)) & 0x0f;
- line2 = ((line2 << 1) | m_pImage->getPixel(w + 3, h - 1)) & 0x1f;
+ line1 = ((line1 << 1) | pImage->getPixel(w + 3, h - 2)) & 0x0f;
+ line2 = ((line2 << 1) | pImage->getPixel(w + 3, h - 1)) & 0x1f;
line3 = ((line3 << 1) | bVal) & 0x07;
}
}
- if (pPause && pPause->NeedToPauseNow()) {
+ if (pState->pPause && pState->pPause->NeedToPauseNow()) {
m_loopIndex++;
m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
return FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -1052,11 +1046,13 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Unopt(
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
+ CJBig2_Image* pImage = pState->pImage->get();
+ JBig2ArithCtx* gbContext = pState->gbContext;
+ CJBig2_ArithDecoder* pArithDecoder = pState->pArithDecoder;
if (!m_pLine)
- m_pLine = m_pImage->data();
- int32_t nStride = m_pImage->stride();
+ m_pLine = pImage->data();
+ int32_t nStride = pImage->stride();
int32_t nStride2 = nStride << 1;
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
@@ -1065,10 +1061,10 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- m_LTP = m_LTP ^ pArithDecoder->Decode(&m_gbContext[0x00e5]);
+ m_LTP = m_LTP ^ pArithDecoder->Decode(&gbContext[0x00e5]);
}
if (m_LTP) {
- m_pImage->copyLine(m_loopIndex, m_loopIndex - 1);
+ pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
if (m_loopIndex > 1) {
uint8_t* pLine1 = m_pLine - nStride2;
@@ -1084,7 +1080,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004);
@@ -1098,7 +1094,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
((line1 >> (7 - k)) & 0x0080) |
@@ -1118,7 +1114,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
((line2 >> (k + 3)) & 0x0004);
@@ -1131,7 +1127,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
(((line2 >> (10 - k))) & 0x0004);
@@ -1140,7 +1136,8 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3(
}
}
m_pLine += nStride;
- if (pPause && m_loopIndex % 50 == 0 && pPause->NeedToPauseNow()) {
+ if (pState->pPause && m_loopIndex % 50 == 0 &&
+ pState->pPause->NeedToPauseNow()) {
m_loopIndex++;
m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
return FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -1151,22 +1148,24 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3(
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Unopt(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
+ CJBig2_Image* pImage = pState->pImage->get();
+ JBig2ArithCtx* gbContext = pState->gbContext;
+ CJBig2_ArithDecoder* pArithDecoder = pState->pArithDecoder;
for (; m_loopIndex < GBH; m_loopIndex++) {
if (TPGDON) {
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- m_LTP = m_LTP ^ pArithDecoder->Decode(&m_gbContext[0x00e5]);
+ m_LTP = m_LTP ^ pArithDecoder->Decode(&gbContext[0x00e5]);
}
if (m_LTP) {
- m_pImage->copyLine(m_loopIndex, m_loopIndex - 1);
+ pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
- uint32_t line1 = m_pImage->getPixel(1, m_loopIndex - 2);
- line1 |= m_pImage->getPixel(0, m_loopIndex - 2) << 1;
- uint32_t line2 = m_pImage->getPixel(1, m_loopIndex - 1);
- line2 |= m_pImage->getPixel(0, m_loopIndex - 1) << 1;
+ uint32_t line1 = pImage->getPixel(1, m_loopIndex - 2);
+ line1 |= pImage->getPixel(0, m_loopIndex - 2) << 1;
+ uint32_t line2 = pImage->getPixel(1, m_loopIndex - 1);
+ line2 |= pImage->getPixel(0, m_loopIndex - 1) << 1;
uint32_t line3 = 0;
for (uint32_t w = 0; w < GBW; w++) {
int bVal;
@@ -1174,26 +1173,25 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Unopt(
bVal = 0;
} else {
uint32_t CONTEXT = line3;
- CONTEXT |= m_pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1])
- << 2;
+ CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 2;
CONTEXT |= line2 << 3;
CONTEXT |= line1 << 7;
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
}
if (bVal) {
- m_pImage->setPixel(w, m_loopIndex, bVal);
+ pImage->setPixel(w, m_loopIndex, bVal);
}
line1 =
- ((line1 << 1) | m_pImage->getPixel(w + 2, m_loopIndex - 2)) & 0x07;
+ ((line1 << 1) | pImage->getPixel(w + 2, m_loopIndex - 2)) & 0x07;
line2 =
- ((line2 << 1) | m_pImage->getPixel(w + 2, m_loopIndex - 1)) & 0x0f;
+ ((line2 << 1) | pImage->getPixel(w + 2, m_loopIndex - 1)) & 0x0f;
line3 = ((line3 << 1) | bVal) & 0x03;
}
}
- if (pPause && pPause->NeedToPauseNow()) {
+ if (pState->pPause && pState->pPause->NeedToPauseNow()) {
m_loopIndex++;
m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
return FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -1204,11 +1202,13 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Unopt(
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
+ CJBig2_Image* pImage = pState->pImage->get();
+ JBig2ArithCtx* gbContext = pState->gbContext;
+ CJBig2_ArithDecoder* pArithDecoder = pState->pArithDecoder;
if (!m_pLine)
- m_pLine = m_pImage->data();
- int32_t nStride = m_pImage->stride();
+ m_pLine = pImage->data();
+ int32_t nStride = pImage->stride();
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
for (; m_loopIndex < GBH; m_loopIndex++) {
@@ -1216,10 +1216,10 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- m_LTP = m_LTP ^ pArithDecoder->Decode(&m_gbContext[0x0195]);
+ m_LTP = m_LTP ^ pArithDecoder->Decode(&gbContext[0x0195]);
}
if (m_LTP) {
- m_pImage->copyLine(m_loopIndex, m_loopIndex - 1);
+ pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
if (m_loopIndex > 0) {
uint8_t* pLine1 = m_pLine - nStride;
@@ -1232,7 +1232,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
((line1 >> (k + 1)) & 0x0010);
@@ -1245,7 +1245,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010);
@@ -1259,7 +1259,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
}
@@ -1270,7 +1270,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3(
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- int bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ int bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
}
@@ -1278,7 +1278,7 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3(
}
}
m_pLine += nStride;
- if (pPause && pPause->NeedToPauseNow()) {
+ if (pState->pPause && pState->pPause->NeedToPauseNow()) {
m_loopIndex++;
m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
return FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -1289,20 +1289,22 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3(
}
FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Unopt(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause) {
+ ProgressiveArithDecodeState* pState) {
+ CJBig2_Image* pImage = pState->pImage->get();
+ JBig2ArithCtx* gbContext = pState->gbContext;
+ CJBig2_ArithDecoder* pArithDecoder = pState->pArithDecoder;
for (; m_loopIndex < GBH; m_loopIndex++) {
if (TPGDON) {
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- m_LTP = m_LTP ^ pArithDecoder->Decode(&m_gbContext[0x0195]);
+ m_LTP = m_LTP ^ pArithDecoder->Decode(&gbContext[0x0195]);
}
if (m_LTP) {
- m_pImage->copyLine(m_loopIndex, m_loopIndex - 1);
+ pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
- uint32_t line1 = m_pImage->getPixel(1, m_loopIndex - 1);
- line1 |= m_pImage->getPixel(0, m_loopIndex - 1) << 1;
+ uint32_t line1 = pImage->getPixel(1, m_loopIndex - 1);
+ line1 |= pImage->getPixel(0, m_loopIndex - 1) << 1;
uint32_t line2 = 0;
for (uint32_t w = 0; w < GBW; w++) {
int bVal;
@@ -1310,23 +1312,22 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Unopt(
bVal = 0;
} else {
uint32_t CONTEXT = line2;
- CONTEXT |= m_pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1])
- << 4;
+ CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4;
CONTEXT |= line1 << 5;
if (pArithDecoder->IsComplete())
return FXCODEC_STATUS_ERROR;
- bVal = pArithDecoder->Decode(&m_gbContext[CONTEXT]);
+ bVal = pArithDecoder->Decode(&gbContext[CONTEXT]);
}
if (bVal) {
- m_pImage->setPixel(w, m_loopIndex, bVal);
+ pImage->setPixel(w, m_loopIndex, bVal);
}
line1 =
- ((line1 << 1) | m_pImage->getPixel(w + 2, m_loopIndex - 1)) & 0x1f;
+ ((line1 << 1) | pImage->getPixel(w + 2, m_loopIndex - 1)) & 0x1f;
line2 = ((line2 << 1) | bVal) & 0x0f;
}
}
- if (pPause && pPause->NeedToPauseNow()) {
+ if (pState->pPause && pState->pPause->NeedToPauseNow()) {
m_loopIndex++;
m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
return FXCODEC_STATUS_DECODE_TOBECONTINUE;
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.h b/core/fxcodec/jbig2/JBig2_GrdProc.h
index 08081dde3d..67d83ddec6 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.h
@@ -22,20 +22,23 @@ struct JBig2ArithCtx;
class CJBig2_GRDProc {
public:
+ struct ProgressiveArithDecodeState {
+ std::unique_ptr<CJBig2_Image>* pImage;
+ CJBig2_ArithDecoder* pArithDecoder;
+ JBig2ArithCtx* gbContext;
+ PauseIndicatorIface* pPause;
+ };
+
CJBig2_GRDProc();
~CJBig2_GRDProc();
std::unique_ptr<CJBig2_Image> DecodeArith(CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext);
- FXCODEC_STATUS StartDecodeArith(std::unique_ptr<CJBig2_Image>* pImage,
- CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext,
- PauseIndicatorIface* pPause);
+ FXCODEC_STATUS StartDecodeArith(ProgressiveArithDecodeState* pState);
FXCODEC_STATUS StartDecodeMMR(std::unique_ptr<CJBig2_Image>* pImage,
CJBig2_BitStream* pStream);
- FXCODEC_STATUS ContinueDecode(PauseIndicatorIface* pPause,
- CJBig2_ArithDecoder* pArithDecoder);
+ FXCODEC_STATUS ContinueDecode(ProgressiveArithDecodeState* pState);
const FX_RECT& GetReplaceRect() const { return m_ReplaceRect; }
bool MMR;
@@ -52,32 +55,23 @@ class CJBig2_GRDProc {
bool UseTemplate1Opt3() const;
bool UseTemplate23Opt3() const;
- FXCODEC_STATUS ProgressiveDecodeArith(PauseIndicatorIface* pPause,
- CJBig2_ArithDecoder* pArithDecoder);
+ FXCODEC_STATUS ProgressiveDecodeArith(ProgressiveArithDecodeState* pState);
FXCODEC_STATUS ProgressiveDecodeArithTemplate0Opt3(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause);
+ ProgressiveArithDecodeState* pState);
FXCODEC_STATUS ProgressiveDecodeArithTemplate0Unopt(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause);
+ ProgressiveArithDecodeState* pState);
FXCODEC_STATUS ProgressiveDecodeArithTemplate1Opt3(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause);
+ ProgressiveArithDecodeState* pState);
FXCODEC_STATUS ProgressiveDecodeArithTemplate1Unopt(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause);
+ ProgressiveArithDecodeState* pState);
FXCODEC_STATUS ProgressiveDecodeArithTemplate2Opt3(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause);
+ ProgressiveArithDecodeState* pState);
FXCODEC_STATUS ProgressiveDecodeArithTemplate2Unopt(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause);
+ ProgressiveArithDecodeState* pState);
FXCODEC_STATUS ProgressiveDecodeArithTemplate3Opt3(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause);
+ ProgressiveArithDecodeState* pState);
FXCODEC_STATUS ProgressiveDecodeArithTemplate3Unopt(
- CJBig2_ArithDecoder* pArithDecoder,
- PauseIndicatorIface* pPause);
+ ProgressiveArithDecodeState* pState);
std::unique_ptr<CJBig2_Image> DecodeArithTemplate0Opt3(
CJBig2_ArithDecoder* pArithDecoder,
@@ -104,13 +98,11 @@ class CJBig2_GRDProc {
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext);
- uint32_t m_loopIndex;
- uint8_t* m_pLine;
+ uint32_t m_loopIndex = 0;
+ uint8_t* m_pLine = nullptr;
FXCODEC_STATUS m_ProssiveStatus;
- CJBig2_Image* m_pImage;
- JBig2ArithCtx* m_gbContext;
- uint16_t m_DecodeType;
- int m_LTP;
+ uint16_t m_DecodeType = 0;
+ int m_LTP = 0;
FX_RECT m_ReplaceRect;
};
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
index 8618236264..fb2257e853 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
@@ -64,11 +64,15 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::DecodeArith(
std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP);
for (int32_t i = GSBPP - 1; i >= 0; --i) {
std::unique_ptr<CJBig2_Image> pImage;
- FXCODEC_STATUS status =
- GRD.StartDecodeArith(&pImage, pArithDecoder, gbContext, nullptr);
+ CJBig2_GRDProc::ProgressiveArithDecodeState state;
+ state.pImage = &pImage;
+ state.pArithDecoder = pArithDecoder;
+ state.gbContext = gbContext;
+ state.pPause = nullptr;
+ FXCODEC_STATUS status = GRD.StartDecodeArith(&state);
+ state.pPause = pPause;
while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE)
- status = GRD.ContinueDecode(pPause, pArithDecoder);
-
+ status = GRD.ContinueDecode(&state);
if (!pImage)
return nullptr;
diff --git a/core/fxcodec/jbig2/JBig2_PddProc.cpp b/core/fxcodec/jbig2/JBig2_PddProc.cpp
index 18c50ef4cd..32f29d745c 100644
--- a/core/fxcodec/jbig2/JBig2_PddProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_PddProc.cpp
@@ -38,10 +38,16 @@ std::unique_ptr<CJBig2_PatternDict> CJBig2_PDDProc::DecodeArith(
pGRD->GBAT[6] = -2;
pGRD->GBAT[7] = -2;
}
- FXCODEC_STATUS status =
- pGRD->StartDecodeArith(&BHDC, pArithDecoder, gbContext, nullptr);
+ CJBig2_GRDProc::ProgressiveArithDecodeState state;
+ state.pImage = &BHDC;
+ state.pArithDecoder = pArithDecoder;
+ state.gbContext = gbContext;
+ state.pPause = nullptr;
+
+ FXCODEC_STATUS status = pGRD->StartDecodeArith(&state);
+ state.pPause = pPause;
while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE)
- status = pGRD->ContinueDecode(pPause, pArithDecoder);
+ status = pGRD->ContinueDecode(&state);
if (!BHDC)
return nullptr;