summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-17 17:14:23 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-17 17:14:23 +0000
commit512509a5bb48cbd13fba80fbb5bd1a455f6d248d (patch)
treec0a96b6c9c3d767552bf3d4709ac761a10fc68d3
parentdc5d88bcebbeeb696b405464e901add55d1efaf7 (diff)
downloadpdfium-512509a5bb48cbd13fba80fbb5bd1a455f6d248d.tar.xz
Consolidate identical code in CJBig2_TRDProc.
Change-Id: Ib44a6b7bd19625a4081322d2471551bec894abd8 Reviewed-on: https://pdfium-review.googlesource.com/32638 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.cpp137
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.h11
2 files changed, 71 insertions, 77 deletions
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
index 258014ab10..474b3ccdf2 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
@@ -179,45 +179,11 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeHuffman(
return nullptr;
int32_t SI = CURS.ValueOrDie();
- if (TRANSPOSED == 0) {
- switch (REFCORNER) {
- case JBIG2_CORNER_TOPLEFT:
- SBREG->ComposeFrom(SI, TI, IBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_TOPRIGHT:
- SBREG->ComposeFrom(SI - WI + 1, TI, IBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_BOTTOMLEFT:
- SBREG->ComposeFrom(SI, TI - HI + 1, IBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_BOTTOMRIGHT:
- SBREG->ComposeFrom(SI - WI + 1, TI - HI + 1, IBI.Get(), SBCOMBOP);
- break;
- }
- } else {
- switch (REFCORNER) {
- case JBIG2_CORNER_TOPLEFT:
- SBREG->ComposeFrom(TI, SI, IBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_TOPRIGHT:
- SBREG->ComposeFrom(TI - WI + 1, SI, IBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_BOTTOMLEFT:
- SBREG->ComposeFrom(TI, SI - HI + 1, IBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_BOTTOMRIGHT:
- SBREG->ComposeFrom(TI - WI + 1, SI - HI + 1, IBI.Get(), SBCOMBOP);
- break;
- }
- }
- if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) ||
- (REFCORNER == JBIG2_CORNER_BOTTOMLEFT))) {
- CURS += WI - 1;
- } else if (TRANSPOSED == 1 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) ||
- (REFCORNER == JBIG2_CORNER_TOPRIGHT))) {
- CURS += HI - 1;
- }
- NINSTANCES = NINSTANCES + 1;
+ ComposeData compose = GetComposeData(SI, TI, WI, HI);
+ SBREG->ComposeFrom(compose.x, compose.y, IBI.Get(), SBCOMBOP);
+ if (compose.increment)
+ CURS += compose.increment;
+ ++NINSTANCES;
}
}
return SBREG;
@@ -379,46 +345,63 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeArith(
return nullptr;
int32_t SI = CURS.ValueOrDie();
- if (TRANSPOSED == 0) {
- switch (REFCORNER) {
- case JBIG2_CORNER_TOPLEFT:
- SBREG->ComposeFrom(SI, TI, pIBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_TOPRIGHT:
- SBREG->ComposeFrom(SI - WI + 1, TI, pIBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_BOTTOMLEFT:
- SBREG->ComposeFrom(SI, TI - HI + 1, pIBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_BOTTOMRIGHT:
- SBREG->ComposeFrom(SI - WI + 1, TI - HI + 1, pIBI.Get(), SBCOMBOP);
- break;
- }
- } else {
- switch (REFCORNER) {
- case JBIG2_CORNER_TOPLEFT:
- SBREG->ComposeFrom(TI, SI, pIBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_TOPRIGHT:
- SBREG->ComposeFrom(TI - WI + 1, SI, pIBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_BOTTOMLEFT:
- SBREG->ComposeFrom(TI, SI - HI + 1, pIBI.Get(), SBCOMBOP);
- break;
- case JBIG2_CORNER_BOTTOMRIGHT:
- SBREG->ComposeFrom(TI - WI + 1, SI - HI + 1, pIBI.Get(), SBCOMBOP);
- break;
- }
- }
- if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) ||
- (REFCORNER == JBIG2_CORNER_BOTTOMLEFT))) {
- CURS += WI - 1;
- } else if (TRANSPOSED == 1 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) ||
- (REFCORNER == JBIG2_CORNER_TOPRIGHT))) {
- CURS += HI - 1;
- }
+ ComposeData compose = GetComposeData(SI, TI, WI, HI);
+ SBREG->ComposeFrom(compose.x, compose.y, pIBI.Get(), SBCOMBOP);
+ if (compose.increment)
+ CURS += compose.increment;
++NINSTANCES;
}
}
return SBREG;
}
+
+CJBig2_TRDProc::ComposeData CJBig2_TRDProc::GetComposeData(int32_t SI,
+ int32_t TI,
+ uint32_t WI,
+ uint32_t HI) const {
+ ComposeData results;
+ if (TRANSPOSED == 0) {
+ switch (REFCORNER) {
+ case JBIG2_CORNER_TOPLEFT:
+ results.x = SI;
+ results.y = TI;
+ results.increment = WI - 1;
+ break;
+ case JBIG2_CORNER_TOPRIGHT:
+ results.x = SI - WI + 1;
+ results.y = TI;
+ break;
+ case JBIG2_CORNER_BOTTOMLEFT:
+ results.x = SI;
+ results.y = TI - HI + 1;
+ results.increment = WI - 1;
+ break;
+ case JBIG2_CORNER_BOTTOMRIGHT:
+ results.x = SI - WI + 1;
+ results.y = TI - HI + 1;
+ break;
+ }
+ } else {
+ switch (REFCORNER) {
+ case JBIG2_CORNER_TOPLEFT:
+ results.x = TI;
+ results.y = SI;
+ results.increment = HI - 1;
+ break;
+ case JBIG2_CORNER_TOPRIGHT:
+ results.x = TI - WI + 1;
+ results.y = SI;
+ results.increment = HI - 1;
+ break;
+ case JBIG2_CORNER_BOTTOMLEFT:
+ results.x = TI;
+ results.y = SI - HI + 1;
+ break;
+ case JBIG2_CORNER_BOTTOMRIGHT:
+ results.x = TI - WI + 1;
+ results.y = SI - HI + 1;
+ break;
+ }
+ }
+ return results;
+}
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.h b/core/fxcodec/jbig2/JBig2_TrdProc.h
index df0aa1585d..3db3121d3e 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.h
@@ -82,6 +82,17 @@ class CJBig2_TRDProc {
CJBig2_HuffmanTable* SBHUFFRSIZE;
bool SBRTEMPLATE;
int8_t SBRAT[4];
+
+ private:
+ struct ComposeData {
+ int32_t x;
+ int32_t y;
+ uint32_t increment = 0;
+ };
+ ComposeData GetComposeData(int32_t SI,
+ int32_t TI,
+ uint32_t WI,
+ uint32_t HI) const;
};
#endif // CORE_FXCODEC_JBIG2_JBIG2_TRDPROC_H_