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 <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
index 7d11482..29c8118 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
@@ -121,19 +121,15 @@
return nullptr;
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 (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;