diff options
author | Lei Zhang <thestig@chromium.org> | 2017-08-24 00:54:01 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-28 18:38:03 +0000 |
commit | 959279182e2ef325aa2a2a8a45ec4143916ef17c (patch) | |
tree | 5c4663daae286060c554e1f5f5c1f0af3e2dab83 /core/fxcodec/jbig2/JBig2_GrrdProc.cpp | |
parent | 91f443f4f3b9682959435a5417b48975729b9338 (diff) | |
download | pdfium-959279182e2ef325aa2a2a8a45ec4143916ef17c.tar.xz |
Add helper methods in CJBig2_GRRDProc.
Refactor identical code used in decode_Template0_unopt() into their own
methods.
Change-Id: I37348a280ecc66d91fdcd3c9aabe49d2a8065417
Reviewed-on: https://pdfium-review.googlesource.com/11950
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcodec/jbig2/JBig2_GrrdProc.cpp')
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GrrdProc.cpp | 143 |
1 files changed, 59 insertions, 84 deletions
diff --git a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp index 049e50a1a9..71bd8e53e4 100644 --- a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp @@ -45,71 +45,31 @@ std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template0_unopt( for (uint32_t h = 0; h < GRH; h++) { if (TPGRON) LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0010]); + + uint32_t lines[5]; + lines[0] = GRREG->getPixel(1, h - 1); + lines[0] |= GRREG->getPixel(0, h - 1) << 1; + lines[1] = 0; + lines[2] = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); + lines[2] |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) + << 1; + lines[3] = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); + lines[3] |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; + lines[3] |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) + << 2; + lines[4] = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); + lines[4] |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) + << 1; + lines[4] |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) + << 2; if (!LTP) { - uint32_t line1 = GRREG->getPixel(1, h - 1); - line1 |= GRREG->getPixel(0, h - 1) << 1; - uint32_t line2 = 0; - uint32_t line3 = - GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); - line3 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) - << 1; - uint32_t line4 = - GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); - line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; - line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) - << 2; - uint32_t line5 = - GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); - line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) - << 1; - line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) - << 2; for (uint32_t w = 0; w < GRW; w++) { - uint32_t CONTEXT = line5; - CONTEXT |= line4 << 3; - CONTEXT |= line3 << 6; - CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], - h - GRREFERENCEDY + GRAT[3]) - << 8; - CONTEXT |= line2 << 9; - CONTEXT |= line1 << 10; - CONTEXT |= GRREG->getPixel(w + GRAT[0], h + GRAT[1]) << 12; + uint32_t CONTEXT = + decode_Template0_unopt_CalculateContext(*GRREG, lines, w, h); int bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); - GRREG->setPixel(w, h, bVal); - line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x03; - line2 = ((line2 << 1) | bVal) & 0x01; - line3 = ((line3 << 1) | - GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, - h - GRREFERENCEDY - 1)) & - 0x03; - line4 = - ((line4 << 1) | - GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & - 0x07; - line5 = ((line5 << 1) | - GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, - h - GRREFERENCEDY + 1)) & - 0x07; + decode_Template0_unopt_SetPixel(GRREG.get(), lines, w, h, bVal); } } else { - uint32_t line1 = GRREG->getPixel(1, h - 1); - line1 |= GRREG->getPixel(0, h - 1) << 1; - uint32_t line2 = 0; - uint32_t line3 = - GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); - line3 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) - << 1; - uint32_t line4 = - GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); - line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; - line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) - << 2; - uint32_t line5 = - GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); - line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) - << 1; - line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) - << 2; for (uint32_t w = 0; w < GRW; w++) { int bVal = GRREFERENCE->getPixel(w, h); if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w - 1, h - 1)) && @@ -120,38 +80,53 @@ std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template0_unopt( (bVal == GRREFERENCE->getPixel(w - 1, h + 1)) && (bVal == GRREFERENCE->getPixel(w, h + 1)) && (bVal == GRREFERENCE->getPixel(w + 1, h + 1)))) { - uint32_t CONTEXT = line5; - CONTEXT |= line4 << 3; - CONTEXT |= line3 << 6; - CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], - h - GRREFERENCEDY + GRAT[3]) - << 8; - CONTEXT |= line2 << 9; - CONTEXT |= line1 << 10; - CONTEXT |= GRREG->getPixel(w + GRAT[0], h + GRAT[1]) << 12; + uint32_t CONTEXT = + decode_Template0_unopt_CalculateContext(*GRREG, lines, w, h); bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); } - GRREG->setPixel(w, h, bVal); - line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x03; - line2 = ((line2 << 1) | bVal) & 0x01; - line3 = ((line3 << 1) | - GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, - h - GRREFERENCEDY - 1)) & - 0x03; - line4 = - ((line4 << 1) | - GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & - 0x07; - line5 = ((line5 << 1) | - GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, - h - GRREFERENCEDY + 1)) & - 0x07; + decode_Template0_unopt_SetPixel(GRREG.get(), lines, w, h, bVal); } } } return GRREG; } +uint32_t CJBig2_GRRDProc::decode_Template0_unopt_CalculateContext( + const CJBig2_Image& GRREG, + const uint32_t* lines, + uint32_t w, + uint32_t h) const { + uint32_t CONTEXT = lines[4]; + CONTEXT |= lines[3] << 3; + CONTEXT |= lines[2] << 6; + CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], + h - GRREFERENCEDY + GRAT[3]) + << 8; + CONTEXT |= lines[1] << 9; + CONTEXT |= lines[0] << 10; + CONTEXT |= GRREG.getPixel(w + GRAT[0], h + GRAT[1]) << 12; + return CONTEXT; +} + +void CJBig2_GRRDProc::decode_Template0_unopt_SetPixel(CJBig2_Image* GRREG, + uint32_t* lines, + uint32_t w, + uint32_t h, + int bVal) { + GRREG->setPixel(w, h, bVal); + lines[0] = ((lines[0] << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x03; + lines[1] = ((lines[1] << 1) | bVal) & 0x01; + lines[2] = ((lines[2] << 1) | GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, + h - GRREFERENCEDY - 1)) & + 0x03; + lines[3] = ((lines[3] << 1) | + GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & + 0x07; + lines[4] = ((lines[4] << 1) | GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, + h - GRREFERENCEDY + 1)) & + 0x07; +} + std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template0_opt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { |