From 2c4a805ac3d649caf34b125fdda1450c7ba8432f Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Thu, 20 Jul 2017 10:32:02 -0400 Subject: Create helper method in CJBig2_HTRDProc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Commit-Queue: Nicolás Peña --- core/fxcodec/jbig2/JBig2_HtrdProc.cpp | 34 ++++++++++------------------------ core/fxcodec/jbig2/JBig2_HtrdProc.h | 4 ++++ 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_HTRDProc::decode_Arith( JBig2ArithCtx* gbContext, IFX_Pause* pPause) { std::unique_ptr HSKIP; - auto HTREG = pdfium::MakeUnique(HBW, HBH); - HTREG->fill(HDEFPIXEL); if (HENABLESKIP == 1) { HSKIP = pdfium::MakeUnique(HGW, HGH); for (uint32_t mg = 0; mg < HGH; ++mg) { @@ -79,29 +77,11 @@ std::unique_ptr CJBig2_HTRDProc::decode_Arith( if (i < GSBPP - 1) GSPLANES[i]->composeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR); } - std::vector 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_HTRDProc::decode_MMR( CJBig2_BitStream* pStream) { - auto HTREG = pdfium::MakeUnique(HBW, HBH); - HTREG->fill(HDEFPIXEL); uint32_t HBPP = 1; while (static_cast(1 << HBPP) < HNUMPATS) ++HBPP; @@ -128,14 +108,20 @@ std::unique_ptr 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_HTRDProc::decode_image( + const std::vector>& GSPLANES) { + auto HTREG = pdfium::MakeUnique(HBW, HBH); + HTREG->fill(HDEFPIXEL); std::vector 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 decode_image( + const std::vector>& GSPLANES); }; #endif // CORE_FXCODEC_JBIG2_JBIG2_HTRDPROC_H_ -- cgit v1.2.3