summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2/JBig2_GrdProc.cpp
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-07-13 10:06:15 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-13 14:29:34 +0000
commit17453d03c3bdd18a893ae86058a6184939aee026 (patch)
tree2a87278c98e851744f20cd9aaa1460f849ef097e /core/fxcodec/jbig2/JBig2_GrdProc.cpp
parent360d1fce569b57aa2c487f6e171ba19b9dc8885e (diff)
downloadpdfium-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_GrdProc.cpp')
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.cpp93
1 files changed, 47 insertions, 46 deletions
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
index c63a40dc33..764723bc6d 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
@@ -7,6 +7,7 @@
#include "core/fxcodec/jbig2/JBig2_GrdProc.h"
#include <memory>
+#include <utility>
#include "core/fxcodec/fx_codec.h"
#include "core/fxcodec/jbig2/JBig2_ArithDecoder.h"
@@ -41,10 +42,11 @@ bool CJBig2_GRDProc::UseTemplate23Opt3() const {
return (GBAT[0] == 2) && (GBAT[1] == -1);
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext) {
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext) {
if (GBW == 0 || GBH == 0)
- return new CJBig2_Image(GBW, GBH);
+ return pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (GBTEMPLATE == 0) {
if (UseTemplate0Opt3())
@@ -64,7 +66,8 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
return decode_Arith_Template3_unopt(pArithDecoder, gbContext);
}
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
+
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template0_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
@@ -159,10 +162,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
}
pLine += nStride;
}
- return GBREG.release();
+ return GBREG;
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt(
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template0_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
@@ -210,10 +213,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt(
}
}
}
- return GBREG.release();
+ return GBREG;
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template1_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
@@ -307,10 +310,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
}
pLine += nStride;
}
- return GBREG.release();
+ return GBREG;
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt(
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template1_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
@@ -356,10 +359,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt(
}
}
}
- return GBREG.release();
+ return GBREG;
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template2_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
@@ -453,10 +456,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
}
pLine += nStride;
}
- return GBREG.release();
+ return GBREG;
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt(
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template2_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
@@ -500,10 +503,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt(
}
}
}
- return GBREG.release();
+ return GBREG;
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template3_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
@@ -585,10 +588,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
}
pLine += nStride;
}
- return GBREG.release();
+ return GBREG;
}
-CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt(
+std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template3_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
@@ -628,11 +631,11 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt(
}
}
}
- return GBREG.release();
+ return GBREG;
}
FXCODEC_STATUS CJBig2_GRDProc::Start_decode_Arith(
- CJBig2_Image** pImage,
+ std::unique_ptr<CJBig2_Image>* pImage,
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext,
IFX_Pause* pPause) {
@@ -642,16 +645,15 @@ FXCODEC_STATUS CJBig2_GRDProc::Start_decode_Arith(
}
m_ProssiveStatus = FXCODEC_STATUS_DECODE_READY;
if (!*pImage)
- *pImage = new CJBig2_Image(GBW, GBH);
+ *pImage = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!(*pImage)->m_pData) {
- delete *pImage;
*pImage = nullptr;
m_ProssiveStatus = FXCODEC_STATUS_ERROR;
return FXCODEC_STATUS_ERROR;
}
m_DecodeType = 1;
- m_pImage = pImage;
- (*m_pImage)->fill(0);
+ m_pImage = pImage->get();
+ m_pImage->fill(0);
m_gbContext = gbContext;
m_LTP = 0;
m_pLine = nullptr;
@@ -663,42 +665,41 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith(
IFX_Pause* pPause,
CJBig2_ArithDecoder* pArithDecoder) {
int iline = m_loopIndex;
- CJBig2_Image* pImage = *m_pImage;
if (GBTEMPLATE == 0) {
if (UseTemplate0Opt3()) {
- m_ProssiveStatus = decode_Arith_Template0_opt3(pImage, pArithDecoder,
+ m_ProssiveStatus = decode_Arith_Template0_opt3(m_pImage, pArithDecoder,
m_gbContext, pPause);
} else {
- m_ProssiveStatus = decode_Arith_Template0_unopt(pImage, pArithDecoder,
+ m_ProssiveStatus = decode_Arith_Template0_unopt(m_pImage, pArithDecoder,
m_gbContext, pPause);
}
} else if (GBTEMPLATE == 1) {
if (UseTemplate1Opt3()) {
- m_ProssiveStatus = decode_Arith_Template1_opt3(pImage, pArithDecoder,
+ m_ProssiveStatus = decode_Arith_Template1_opt3(m_pImage, pArithDecoder,
m_gbContext, pPause);
} else {
- m_ProssiveStatus = decode_Arith_Template1_unopt(pImage, pArithDecoder,
+ m_ProssiveStatus = decode_Arith_Template1_unopt(m_pImage, pArithDecoder,
m_gbContext, pPause);
}
} else if (GBTEMPLATE == 2) {
if (UseTemplate23Opt3()) {
- m_ProssiveStatus = decode_Arith_Template2_opt3(pImage, pArithDecoder,
+ m_ProssiveStatus = decode_Arith_Template2_opt3(m_pImage, pArithDecoder,
m_gbContext, pPause);
} else {
- m_ProssiveStatus = decode_Arith_Template2_unopt(pImage, pArithDecoder,
+ m_ProssiveStatus = decode_Arith_Template2_unopt(m_pImage, pArithDecoder,
m_gbContext, pPause);
}
} else {
if (UseTemplate23Opt3()) {
- m_ProssiveStatus = decode_Arith_Template3_opt3(pImage, pArithDecoder,
+ m_ProssiveStatus = decode_Arith_Template3_opt3(m_pImage, pArithDecoder,
m_gbContext, pPause);
} else {
- m_ProssiveStatus = decode_Arith_Template3_unopt(pImage, pArithDecoder,
+ m_ProssiveStatus = decode_Arith_Template3_unopt(m_pImage, pArithDecoder,
m_gbContext, pPause);
}
}
m_ReplaceRect.left = 0;
- m_ReplaceRect.right = pImage->width();
+ m_ReplaceRect.right = m_pImage->width();
m_ReplaceRect.top = iline;
m_ReplaceRect.bottom = m_loopIndex;
if (m_ProssiveStatus == FXCODEC_STATUS_DECODE_FINISH)
@@ -707,24 +708,24 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith(
return m_ProssiveStatus;
}
-FXCODEC_STATUS CJBig2_GRDProc::Start_decode_MMR(CJBig2_Image** pImage,
- CJBig2_BitStream* pStream) {
+FXCODEC_STATUS CJBig2_GRDProc::Start_decode_MMR(
+ std::unique_ptr<CJBig2_Image>* pImage,
+ CJBig2_BitStream* pStream) {
int bitpos, i;
- *pImage = new CJBig2_Image(GBW, GBH);
- if (!(*pImage)->m_pData) {
- delete (*pImage);
- (*pImage) = nullptr;
+ auto image = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
+ if (!image->m_pData) {
+ *pImage = nullptr;
m_ProssiveStatus = FXCODEC_STATUS_ERROR;
return m_ProssiveStatus;
}
- bitpos = (int)pStream->getBitPos();
- FaxG4Decode(pStream->getBuf(), pStream->getLength(), &bitpos,
- (*pImage)->m_pData, GBW, GBH, (*pImage)->stride());
+ bitpos = static_cast<int>(pStream->getBitPos());
+ FaxG4Decode(pStream->getBuf(), pStream->getLength(), &bitpos, image->m_pData,
+ GBW, GBH, image->stride());
pStream->setBitPos(bitpos);
- for (i = 0; (uint32_t)i < (*pImage)->stride() * GBH; i++) {
- (*pImage)->m_pData[i] = ~(*pImage)->m_pData[i];
- }
+ for (i = 0; (uint32_t)i < image->stride() * GBH; ++i)
+ image->m_pData[i] = ~image->m_pData[i];
m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH;
+ *pImage = std::move(image);
return m_ProssiveStatus;
}