summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-07-20 10:32:02 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-20 14:49:10 +0000
commit2c4a805ac3d649caf34b125fdda1450c7ba8432f (patch)
treebfd6cb076dfba83ec7ff30947704c591985545da
parent40870db0aadef4e145fd3b2b95fa5a083afb3161 (diff)
downloadpdfium-2c4a805ac3d649caf34b125fdda1450c7ba8432f.tar.xz
Create helper method in CJBig2_HTRDProc
This CL creates CJBig2_HTRDProc::decode_image to reduce duplicated code in the class. Change-Id: Ie348179c96ff534f95cba401c4b9bd46e1c4e6ac Reviewed-on: https://pdfium-review.googlesource.com/8410 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Nicolás Peña <npm@chromium.org>
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.cpp34
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.h4
2 files changed, 14 insertions, 24 deletions
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
index 25e6b9cf3f..11070c11b9 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
@@ -20,8 +20,6 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_Arith(
JBig2ArithCtx* gbContext,
IFX_Pause* pPause) {
std::unique_ptr<CJBig2_Image> HSKIP;
- auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH);
- HTREG->fill(HDEFPIXEL);
if (HENABLESKIP == 1) {
HSKIP = pdfium::MakeUnique<CJBig2_Image>(HGW, HGH);
for (uint32_t mg = 0; mg < HGH; ++mg) {
@@ -79,29 +77,11 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_Arith(
if (i < GSBPP - 1)
GSPLANES[i]->composeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR);
}
- std::vector<uint32_t> GSVALS(HGW * HGH);
- for (uint32_t y = 0; y < HGH; ++y) {
- for (uint32_t x = 0; x < HGW; ++x) {
- for (int32_t i = 0; i < GSBPP; ++i)
- GSVALS[y * HGW + x] |= GSPLANES[i]->getPixel(x, y) << i;
- }
- }
-
- for (uint32_t mg = 0; mg < HGH; ++mg) {
- for (uint32_t ng = 0; ng < HGW; ++ng) {
- int32_t x = (HGX + mg * HRY + ng * HRX) >> 8;
- int32_t y = (HGY + mg * HRX - ng * HRY) >> 8;
- uint32_t pat_index = std::min(GSVALS[mg * HGW + ng], HNUMPATS - 1);
- HTREG->composeFrom(x, y, (*HPATS)[pat_index].get(), HCOMBOP);
- }
- }
- return HTREG;
+ return decode_image(GSPLANES);
}
std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_MMR(
CJBig2_BitStream* pStream) {
- auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH);
- HTREG->fill(HDEFPIXEL);
uint32_t HBPP = 1;
while (static_cast<uint32_t>(1 << HBPP) < HNUMPATS)
++HBPP;
@@ -128,14 +108,20 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_MMR(
pStream->offset(3);
GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1].get(), JBIG2_COMPOSE_XOR);
}
+ return decode_image(GSPLANES);
+}
+
+std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_image(
+ const std::vector<std::unique_ptr<CJBig2_Image>>& GSPLANES) {
+ auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH);
+ HTREG->fill(HDEFPIXEL);
std::vector<uint32_t> GSVALS(HGW * HGH);
for (uint32_t y = 0; y < HGH; ++y) {
for (uint32_t x = 0; x < HGW; ++x) {
- for (int32_t i = 0; i < GSBPP; ++i)
- GSVALS[y * HGW + x] |= GSPLANES[i]->getPixel(x, y) << i;
+ for (uint8_t J = 0; J < GSPLANES.size(); ++J)
+ GSVALS[y * HGW + x] |= GSPLANES[J]->getPixel(x, y) << J;
}
}
-
for (uint32_t mg = 0; mg < HGH; ++mg) {
for (uint32_t ng = 0; ng < HGW; ++ng) {
int32_t x = (HGX + mg * HRY + ng * HRX) >> 8;
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.h b/core/fxcodec/jbig2/JBig2_HtrdProc.h
index 85e9059d66..75041ac41b 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.h
@@ -44,6 +44,10 @@ class CJBig2_HTRDProc {
uint16_t HRY;
uint8_t HPW;
uint8_t HPH;
+
+ private:
+ std::unique_ptr<CJBig2_Image> decode_image(
+ const std::vector<std::unique_ptr<CJBig2_Image>>& GSPLANES);
};
#endif // CORE_FXCODEC_JBIG2_JBIG2_HTRDPROC_H_