From 575ceba24463a2211e8669f8d919d3c91385d72b Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 9 May 2018 18:35:36 +0000 Subject: Make memory usage in CJBig2_HTRDProc::DecodeImage() O(1). Instead of allocating an N-pixel array to store some temporary values, just use a single integer. BUG=chromium:840728 Change-Id: I7a0ff83d814eff127033f25020a7c398db3c2062 Reviewed-on: https://pdfium-review.googlesource.com/32290 Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- core/fxcodec/jbig2/JBig2_HtrdProc.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp index 7d11482225..29c8118883 100644 --- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp @@ -121,19 +121,15 @@ std::unique_ptr CJBig2_HTRDProc::DecodeImage( return nullptr; 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 (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; - 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); + uint32_t gsval = 0; + for (uint8_t i = 0; i < GSPLANES.size(); ++i) + gsval |= GSPLANES[i]->getPixel(x, y) << i; + uint32_t pat_index = std::min(gsval, HNUMPATS - 1); + int32_t out_x = (HGX + y * HRY + x * HRX) >> 8; + int32_t out_y = (HGY + y * HRX - x * HRY) >> 8; + HTREG->ComposeFrom(out_x, out_y, (*HPATS)[pat_index].get(), HCOMBOP); } } return HTREG; -- cgit v1.2.3