diff options
author | Nicolas Pena <npm@chromium.org> | 2017-07-18 17:57:37 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-19 13:51:58 +0000 |
commit | 0add284c1a2b3bee022bef34c7efddcb304f2e21 (patch) | |
tree | 4ff8a4010d8d02e415fd4d6dbb9067c877ef23f9 | |
parent | 23c93ef6e3b9a289cdcece487b314325a21b28ff (diff) | |
download | pdfium-0add284c1a2b3bee022bef34c7efddcb304f2e21.tar.xz |
Remove JBig2_GsidProc class
This CL removes the JBig2_GsidProc since it is only used as a single
instance in each of the methods in CJBig2_HTRDProc, so it is completely
unnecessary.
Change-Id: I69d0a4a059b9eb6ebcbbb79b92ea1cd6c22cb1cb
Reviewed-on: https://pdfium-review.googlesource.com/7930
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | BUILD.gn | 2 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GsidProc.cpp | 106 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GsidProc.h | 36 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_HtrdProc.cpp | 150 |
4 files changed, 99 insertions, 195 deletions
@@ -719,8 +719,6 @@ static_library("fxcodec") { "core/fxcodec/jbig2/JBig2_GrdProc.h", "core/fxcodec/jbig2/JBig2_GrrdProc.cpp", "core/fxcodec/jbig2/JBig2_GrrdProc.h", - "core/fxcodec/jbig2/JBig2_GsidProc.cpp", - "core/fxcodec/jbig2/JBig2_GsidProc.h", "core/fxcodec/jbig2/JBig2_HtrdProc.cpp", "core/fxcodec/jbig2/JBig2_HtrdProc.h", "core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp", diff --git a/core/fxcodec/jbig2/JBig2_GsidProc.cpp b/core/fxcodec/jbig2/JBig2_GsidProc.cpp deleted file mode 100644 index 6510f08487..0000000000 --- a/core/fxcodec/jbig2/JBig2_GsidProc.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2015 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxcodec/jbig2/JBig2_GsidProc.h" - -#include <memory> -#include <utility> -#include <vector> - -#include "core/fxcodec/jbig2/JBig2_BitStream.h" -#include "core/fxcodec/jbig2/JBig2_GrdProc.h" -#include "core/fxcodec/jbig2/JBig2_Image.h" -#include "core/fxcrt/fx_basic.h" -#include "third_party/base/ptr_util.h" - -uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext, - IFX_Pause* pPause) { - auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); - pGRD->MMR = GSMMR; - pGRD->GBW = GSW; - pGRD->GBH = GSH; - pGRD->GBTEMPLATE = GSTEMPLATE; - pGRD->TPGDON = 0; - pGRD->USESKIP = GSUSESKIP; - pGRD->SKIP = GSKIP; - if (GSTEMPLATE <= 1) { - pGRD->GBAT[0] = 3; - } else { - pGRD->GBAT[0] = 2; - } - pGRD->GBAT[1] = -1; - if (pGRD->GBTEMPLATE == 0) { - pGRD->GBAT[2] = -3; - pGRD->GBAT[3] = -1; - pGRD->GBAT[4] = 2; - pGRD->GBAT[5] = -2; - pGRD->GBAT[6] = -2; - pGRD->GBAT[7] = -2; - } - - std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); - for (int32_t i = GSBPP - 1; i >= 0; --i) { - std::unique_ptr<CJBig2_Image> pImage; - FXCODEC_STATUS status = - pGRD->Start_decode_Arith(&pImage, pArithDecoder, gbContext, nullptr); - while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) - status = pGRD->Continue_decode(pPause, pArithDecoder); - - if (!pImage) - return nullptr; - - GSPLANES[i] = std::move(pImage); - if (i < GSBPP - 1) - GSPLANES[i]->composeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR); - } - std::unique_ptr<uint32_t, FxFreeDeleter> GSVALS( - FX_Alloc2D(uint32_t, GSW, GSH)); - JBIG2_memset(GSVALS.get(), 0, sizeof(uint32_t) * GSW * GSH); - for (uint32_t y = 0; y < GSH; ++y) { - for (uint32_t x = 0; x < GSW; ++x) { - for (int32_t i = 0; i < GSBPP; ++i) - GSVALS.get()[y * GSW + x] |= GSPLANES[i]->getPixel(x, y) << i; - } - } - return GSVALS.release(); -} - -uint32_t* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream) { - auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); - pGRD->MMR = GSMMR; - pGRD->GBW = GSW; - pGRD->GBH = GSH; - - std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); - pGRD->Start_decode_MMR(&GSPLANES[GSBPP - 1], pStream); - if (!GSPLANES[GSBPP - 1]) - return nullptr; - - pStream->alignByte(); - pStream->offset(3); - int32_t J = GSBPP - 2; - while (J >= 0) { - pGRD->Start_decode_MMR(&GSPLANES[J], pStream); - if (!GSPLANES[J]) - return nullptr; - - pStream->alignByte(); - pStream->offset(3); - GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1].get(), JBIG2_COMPOSE_XOR); - J = J - 1; - } - std::unique_ptr<uint32_t> GSVALS(FX_Alloc2D(uint32_t, GSW, GSH)); - JBIG2_memset(GSVALS.get(), 0, sizeof(uint32_t) * GSW * GSH); - for (uint32_t y = 0; y < GSH; ++y) { - for (uint32_t x = 0; x < GSW; ++x) { - for (J = 0; J < GSBPP; ++J) { - GSVALS.get()[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; - } - } - } - return GSVALS.release(); -} diff --git a/core/fxcodec/jbig2/JBig2_GsidProc.h b/core/fxcodec/jbig2/JBig2_GsidProc.h deleted file mode 100644 index 45e759968e..0000000000 --- a/core/fxcodec/jbig2/JBig2_GsidProc.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXCODEC_JBIG2_JBIG2_GSIDPROC_H_ -#define CORE_FXCODEC_JBIG2_JBIG2_GSIDPROC_H_ - -#include "core/fxcrt/fx_system.h" - -class CJBig2_ArithDecoder; -class CJBig2_BitStream; -class CJBig2_Image; -class IFX_Pause; -struct JBig2ArithCtx; - -class CJBig2_GSIDProc { - public: - uint32_t* decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext, - IFX_Pause* pPause); - - uint32_t* decode_MMR(CJBig2_BitStream* pStream); - - public: - bool GSMMR; - bool GSUSESKIP; - uint8_t GSBPP; - uint32_t GSW; - uint32_t GSH; - uint8_t GSTEMPLATE; - CJBig2_Image* GSKIP; -}; - -#endif // CORE_FXCODEC_JBIG2_JBIG2_GSIDPROC_H_ diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp index a7de28607e..25e6b9cf3f 100644 --- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp @@ -7,8 +7,11 @@ #include "core/fxcodec/jbig2/JBig2_HtrdProc.h" #include <algorithm> +#include <utility> -#include "core/fxcodec/jbig2/JBig2_GsidProc.h" +#include "core/fxcodec/jbig2/JBig2_BitStream.h" +#include "core/fxcodec/jbig2/JBig2_GrdProc.h" +#include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/fx_basic.h" #include "third_party/base/ptr_util.h" @@ -16,21 +19,17 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_Arith( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - uint32_t ng, mg; - int32_t x, y; - uint32_t HBPP; - uint32_t* GI; 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 (mg = 0; mg < HGH; mg++) { - for (ng = 0; ng < HGW; ng++) { - x = (HGX + mg * HRY + ng * HRX) >> 8; - y = (HGY + mg * HRX - ng * HRY) >> 8; - if ((x + HPW <= 0) | (x >= (int32_t)HBW) | (y + HPH <= 0) | - (y >= (int32_t)HPH)) { + 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; + if ((x + HPW <= 0) | (x >= static_cast<int32_t>(HBW)) | (y + HPH <= 0) | + (y >= static_cast<int32_t>(HPH))) { HSKIP->setPixel(ng, mg, 1); } else { HSKIP->setPixel(ng, mg, 0); @@ -38,63 +37,112 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_Arith( } } } - HBPP = 1; - while ((uint32_t)(1 << HBPP) < HNUMPATS) { - HBPP++; + uint32_t HBPP = 1; + while (static_cast<uint32_t>(1 << HBPP) < HNUMPATS) + ++HBPP; + + CJBig2_GRDProc GRD; + GRD.MMR = HMMR; + GRD.GBW = HGW; + GRD.GBH = HGH; + GRD.GBTEMPLATE = HTEMPLATE; + GRD.TPGDON = 0; + GRD.USESKIP = HENABLESKIP; + GRD.SKIP = HSKIP.get(); + if (HTEMPLATE <= 1) + GRD.GBAT[0] = 3; + else + GRD.GBAT[0] = 2; + GRD.GBAT[1] = -1; + if (GRD.GBTEMPLATE == 0) { + GRD.GBAT[2] = -3; + GRD.GBAT[3] = -1; + GRD.GBAT[4] = 2; + GRD.GBAT[5] = -2; + GRD.GBAT[6] = -2; + GRD.GBAT[7] = -2; + } + + uint8_t GSBPP = static_cast<uint8_t>(HBPP); + std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); + for (int32_t i = GSBPP - 1; i >= 0; --i) { + std::unique_ptr<CJBig2_Image> pImage; + FXCODEC_STATUS status = + GRD.Start_decode_Arith(&pImage, pArithDecoder, gbContext, nullptr); + while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) + status = GRD.Continue_decode(pPause, pArithDecoder); + + if (!pImage) + return nullptr; + + GSPLANES[i] = std::move(pImage); + 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; + } } - auto pGID = pdfium::MakeUnique<CJBig2_GSIDProc>(); - pGID->GSMMR = HMMR; - pGID->GSW = HGW; - pGID->GSH = HGH; - pGID->GSBPP = (uint8_t)HBPP; - pGID->GSUSESKIP = HENABLESKIP; - pGID->GSKIP = HSKIP.get(); - pGID->GSTEMPLATE = HTEMPLATE; - GI = pGID->decode_Arith(pArithDecoder, gbContext, pPause); - if (!GI) - return nullptr; - for (mg = 0; mg < HGH; mg++) { - for (ng = 0; ng < HGW; ng++) { - x = (HGX + mg * HRY + ng * HRX) >> 8; - y = (HGY + mg * HRX - ng * HRY) >> 8; - uint32_t pat_index = std::min(GI[mg * HGW + ng], HNUMPATS - 1); + 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); } } - FX_Free(GI); return HTREG; } std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_MMR( CJBig2_BitStream* pStream) { - uint32_t ng, mg; - int32_t x, y; - uint32_t* GI; auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH); HTREG->fill(HDEFPIXEL); uint32_t HBPP = 1; - while ((uint32_t)(1 << HBPP) < HNUMPATS) { - HBPP++; - } - auto pGID = pdfium::MakeUnique<CJBig2_GSIDProc>(); - pGID->GSMMR = HMMR; - pGID->GSW = HGW; - pGID->GSH = HGH; - pGID->GSBPP = (uint8_t)HBPP; - pGID->GSUSESKIP = 0; - GI = pGID->decode_MMR(pStream); - if (!GI) + while (static_cast<uint32_t>(1 << HBPP) < HNUMPATS) + ++HBPP; + + CJBig2_GRDProc GRD; + GRD.MMR = HMMR; + GRD.GBW = HGW; + GRD.GBH = HGH; + + uint8_t GSBPP = static_cast<uint8_t>(HBPP); + std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); + GRD.Start_decode_MMR(&GSPLANES[GSBPP - 1], pStream); + if (!GSPLANES[GSBPP - 1]) return nullptr; - for (mg = 0; mg < HGH; mg++) { - for (ng = 0; ng < HGW; ng++) { - x = (HGX + mg * HRY + ng * HRX) >> 8; - y = (HGY + mg * HRX - ng * HRY) >> 8; - uint32_t pat_index = std::min(GI[mg * HGW + ng], HNUMPATS - 1); + pStream->alignByte(); + pStream->offset(3); + for (int32_t J = GSBPP - 2; J >= 0; --J) { + GRD.Start_decode_MMR(&GSPLANES[J], pStream); + if (!GSPLANES[J]) + return nullptr; + + pStream->alignByte(); + pStream->offset(3); + GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 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); } } - FX_Free(GI); return HTREG; } |