diff options
author | Nicolas Pena <npm@chromium.org> | 2017-07-13 10:06:15 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-13 14:29:34 +0000 |
commit | 17453d03c3bdd18a893ae86058a6184939aee026 (patch) | |
tree | 2a87278c98e851744f20cd9aaa1460f849ef097e /core/fxcodec/jbig2/JBig2_GsidProc.cpp | |
parent | 360d1fce569b57aa2c487f6e171ba19b9dc8885e (diff) | |
download | pdfium-17453d03c3bdd18a893ae86058a6184939aee026.tar.xz |
More unique_ptrs in JBig2 code
This CL makes CJBig2_Segment own the results: symbol, pattern, huffman,
and huffman. This causes a lot more unique_ptr usage in JBig2 code.
Change-Id: I1f0a5bfaaf85053658b467bef5325c72d1f496c7
Reviewed-on: https://pdfium-review.googlesource.com/7690
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcodec/jbig2/JBig2_GsidProc.cpp')
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GsidProc.cpp | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/core/fxcodec/jbig2/JBig2_GsidProc.cpp b/core/fxcodec/jbig2/JBig2_GsidProc.cpp index 842d7df3bf..6510f08487 100644 --- a/core/fxcodec/jbig2/JBig2_GsidProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GsidProc.cpp @@ -7,6 +7,7 @@ #include "core/fxcodec/jbig2/JBig2_GsidProc.h" #include <memory> +#include <utility> #include <vector> #include "core/fxcodec/jbig2/JBig2_BitStream.h" @@ -43,7 +44,7 @@ uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); for (int32_t i = GSBPP - 1; i >= 0; --i) { - CJBig2_Image* pImage = nullptr; + std::unique_ptr<CJBig2_Image> pImage; FXCODEC_STATUS status = pGRD->Start_decode_Arith(&pImage, pArithDecoder, gbContext, nullptr); while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) @@ -52,9 +53,9 @@ uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, if (!pImage) return nullptr; - GSPLANES[i].reset(pImage); + GSPLANES[i] = std::move(pImage); if (i < GSBPP - 1) - pImage->composeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR); + 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)); @@ -74,26 +75,22 @@ uint32_t* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream) { pGRD->GBW = GSW; pGRD->GBH = GSH; - std::unique_ptr<CJBig2_Image*> GSPLANES(FX_Alloc(CJBig2_Image*, GSBPP)); - JBIG2_memset(GSPLANES.get(), 0, sizeof(CJBig2_Image*) * GSBPP); - pGRD->Start_decode_MMR(&GSPLANES.get()[GSBPP - 1], pStream); - if (!GSPLANES.get()[GSBPP - 1]) + 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.get()[J], pStream); - if (!GSPLANES.get()[J]) { - for (int32_t K = GSBPP - 1; K > J; --K) - delete GSPLANES.get()[K]; + pGRD->Start_decode_MMR(&GSPLANES[J], pStream); + if (!GSPLANES[J]) return nullptr; - } + pStream->alignByte(); pStream->offset(3); - GSPLANES.get()[J]->composeFrom(0, 0, GSPLANES.get()[J + 1], - JBIG2_COMPOSE_XOR); + 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)); @@ -101,12 +98,9 @@ uint32_t* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream) { 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.get()[J]->getPixel(x, y) << J; + GSVALS.get()[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; } } } - for (J = 0; J < GSBPP; ++J) { - delete GSPLANES.get()[J]; - } return GSVALS.release(); } |