summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp123
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.cpp93
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.h52
-rw-r--r--core/fxcodec/jbig2/JBig2_GrrdProc.cpp30
-rw-r--r--core/fxcodec/jbig2/JBig2_GrrdProc.h33
-rw-r--r--core/fxcodec/jbig2/JBig2_GsidProc.cpp30
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.cpp16
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.h10
-rw-r--r--core/fxcodec/jbig2/JBig2_PddProc.cpp15
-rw-r--r--core/fxcodec/jbig2/JBig2_PddProc.h11
-rw-r--r--core/fxcodec/jbig2/JBig2_SddProc.cpp33
-rw-r--r--core/fxcodec/jbig2/JBig2_SddProc.h17
-rw-r--r--core/fxcodec/jbig2/JBig2_Segment.cpp19
-rw-r--r--core/fxcodec/jbig2/JBig2_Segment.h13
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.cpp53
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.h12
16 files changed, 273 insertions, 287 deletions
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 275c69915c..826f4be8ff 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -462,7 +462,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
CJBig2_Segment* pSeg =
findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
if (pSeg->m_cFlags.s.type == 0) {
- pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->NumImages();
+ pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_SymbolDict->NumImages();
pLRSeg = pSeg;
}
}
@@ -475,7 +475,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
CJBig2_Segment* pSeg =
findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
if (pSeg->m_cFlags.s.type == 0) {
- const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd;
+ const CJBig2_SymbolDict& dict = *pSeg->m_SymbolDict.get();
for (size_t j = 0; j < dict.NumImages(); ++j)
SDINSYMS.get()[dwTemp + j] = dict.GetImage(j);
dwTemp += dict.NumImages();
@@ -507,7 +507,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pSymbolDictDecoder->SDHUFFDH = pSeg->m_Result.ht;
+ pSymbolDictDecoder->SDHUFFDH = pSeg->m_HuffmanTable.get();
}
if (cSDHUFFDW == 0) {
Table_B2 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
@@ -522,7 +522,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pSymbolDictDecoder->SDHUFFDW = pSeg->m_Result.ht;
+ pSymbolDictDecoder->SDHUFFDW = pSeg->m_HuffmanTable.get();
}
if (cSDHUFFBMSIZE == 0) {
Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
@@ -533,7 +533,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_Result.ht;
+ pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_HuffmanTable.get();
}
if (pSymbolDictDecoder->SDREFAGG == 1) {
if (cSDHUFFAGGINST == 0) {
@@ -547,7 +547,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pSymbolDictDecoder->SDHUFFAGGINST = pSeg->m_Result.ht;
+ pSymbolDictDecoder->SDHUFFAGGINST = pSeg->m_HuffmanTable.get();
}
}
}
@@ -562,12 +562,12 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
std::vector<JBig2ArithCtx> grContext;
if ((wFlags & 0x0100) && pLRSeg) {
if (bUseGbContext) {
- gbContext = pLRSeg->m_Result.sd->GbContext();
+ gbContext = pLRSeg->m_SymbolDict->GbContext();
if (gbContext.size() != gbContextSize)
return JBIG2_ERROR_FATAL;
}
if (bUseGrContext) {
- grContext = pLRSeg->m_Result.sd->GrContext();
+ grContext = pLRSeg->m_SymbolDict->GrContext();
if (grContext.size() != grContextSize)
return JBIG2_ERROR_FATAL;
}
@@ -586,8 +586,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
for (auto it = m_pSymbolDictCache->begin(); it != m_pSymbolDictCache->end();
++it) {
if (it->first == key) {
- std::unique_ptr<CJBig2_SymbolDict> copy(it->second->DeepCopy());
- pSegment->m_Result.sd = copy.release();
+ pSegment->m_SymbolDict = it->second->DeepCopy();
m_pSymbolDictCache->push_front(
CJBig2_CachePair(key, std::move(it->second)));
m_pSymbolDictCache->erase(it);
@@ -600,23 +599,23 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
if (bUseGbContext) {
auto pArithDecoder =
pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
- pSegment->m_Result.sd = pSymbolDictDecoder->decode_Arith(
+ pSegment->m_SymbolDict = pSymbolDictDecoder->decode_Arith(
pArithDecoder.get(), &gbContext, &grContext);
- if (!pSegment->m_Result.sd)
+ if (!pSegment->m_SymbolDict)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
m_pStream->offset(2);
} else {
- pSegment->m_Result.sd = pSymbolDictDecoder->decode_Huffman(
+ pSegment->m_SymbolDict = pSymbolDictDecoder->decode_Huffman(
m_pStream.get(), &gbContext, &grContext);
- if (!pSegment->m_Result.sd)
+ if (!pSegment->m_SymbolDict)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
}
if (m_bIsGlobal) {
std::unique_ptr<CJBig2_SymbolDict> value =
- pSegment->m_Result.sd->DeepCopy();
+ pSegment->m_SymbolDict->DeepCopy();
int size = pdfium::CollectionSize<int>(*m_pSymbolDictCache);
while (size >= kSymbolDictCacheMaxSize) {
m_pSymbolDictCache->pop_back();
@@ -627,9 +626,9 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) {
}
if (wFlags & 0x0200) {
if (bUseGbContext)
- pSegment->m_Result.sd->SetGbContext(gbContext);
+ pSegment->m_SymbolDict->SetGbContext(gbContext);
if (bUseGrContext)
- pSegment->m_Result.sd->SetGrContext(grContext);
+ pSegment->m_SymbolDict->SetGrContext(grContext);
}
return JBIG2_SUCCESS;
}
@@ -699,7 +698,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
CJBig2_Segment* pSeg =
findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
if (pSeg->m_cFlags.s.type == 0) {
- pTRD->SBNUMSYMS += pSeg->m_Result.sd->NumImages();
+ pTRD->SBNUMSYMS += pSeg->m_SymbolDict->NumImages();
}
}
@@ -711,7 +710,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
CJBig2_Segment* pSeg =
findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
if (pSeg->m_cFlags.s.type == 0) {
- const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd;
+ const CJBig2_SymbolDict& dict = *pSeg->m_SymbolDict.get();
for (size_t j = 0; j < dict.NumImages(); ++j)
SBSYMS.get()[dwTemp + j] = dict.GetImage(j);
dwTemp += dict.NumImages();
@@ -769,7 +768,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pTRD->SBHUFFFS = pSeg->m_Result.ht;
+ pTRD->SBHUFFFS = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFDS == 0) {
Table_B8 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
@@ -788,7 +787,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pTRD->SBHUFFDS = pSeg->m_Result.ht;
+ pTRD->SBHUFFDS = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFDT == 0) {
Table_B11 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
@@ -807,7 +806,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pTRD->SBHUFFDT = pSeg->m_Result.ht;
+ pTRD->SBHUFFDT = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFRDW == 0) {
Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
@@ -822,7 +821,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pTRD->SBHUFFRDW = pSeg->m_Result.ht;
+ pTRD->SBHUFFRDW = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFRDH == 0) {
if (!Table_B14) {
@@ -841,7 +840,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pTRD->SBHUFFRDH = pSeg->m_Result.ht;
+ pTRD->SBHUFFRDH = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFRDX == 0) {
if (!Table_B14) {
@@ -860,7 +859,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pTRD->SBHUFFRDX = pSeg->m_Result.ht;
+ pTRD->SBHUFFRDX = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFRDY == 0) {
if (!Table_B14) {
@@ -879,7 +878,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pTRD->SBHUFFRDY = pSeg->m_Result.ht;
+ pTRD->SBHUFFRDY = pSeg->m_HuffmanTable.get();
}
if (cSBHUFFRSIZE == 0) {
Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>(
@@ -890,7 +889,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++);
if (!pSeg)
return JBIG2_ERROR_FATAL;
- pTRD->SBHUFFRSIZE = pSeg->m_Result.ht;
+ pTRD->SBHUFFRSIZE = pSeg->m_HuffmanTable.get();
}
}
std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext;
@@ -903,17 +902,16 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
auto pArithDecoder =
pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
- pSegment->m_Result.im =
+ pSegment->m_Image =
pTRD->decode_Arith(pArithDecoder.get(), grContext.get(), nullptr);
- if (!pSegment->m_Result.im)
+ if (!pSegment->m_Image)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
m_pStream->offset(2);
} else {
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
- pSegment->m_Result.im =
- pTRD->decode_Huffman(m_pStream.get(), grContext.get());
- if (!pSegment->m_Result.im)
+ pSegment->m_Image = pTRD->decode_Huffman(m_pStream.get(), grContext.get());
+ if (!pSegment->m_Image)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
}
@@ -925,10 +923,9 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0);
}
}
- m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im,
+ m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Image.get(),
(JBig2ComposeOp)(ri.flags & 0x03));
- delete pSegment->m_Result.im;
- pSegment->m_Result.im = nullptr;
+ pSegment->m_Image.reset();
}
return JBIG2_SUCCESS;
}
@@ -956,16 +953,16 @@ int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment,
JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size);
auto pArithDecoder =
pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
- pSegment->m_Result.pd =
+ pSegment->m_PatternDict =
pPDD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause);
- if (!pSegment->m_Result.pd)
+ if (!pSegment->m_PatternDict)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
m_pStream->offset(2);
} else {
- pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream.get());
- if (!pSegment->m_Result.pd)
+ pSegment->m_PatternDict = pPDD->decode_MMR(m_pStream.get());
+ if (!pSegment->m_PatternDict)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
}
@@ -1006,7 +1003,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
if (!pSeg || (pSeg->m_cFlags.s.type != 16))
return JBIG2_ERROR_FATAL;
- CJBig2_PatternDict* pPatternDict = pSeg->m_Result.pd;
+ const CJBig2_PatternDict* pPatternDict = pSeg->m_PatternDict.get();
if (!pPatternDict || (pPatternDict->NUMPATS == 0))
return JBIG2_ERROR_FATAL;
@@ -1022,16 +1019,16 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size);
auto pArithDecoder =
pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
- pSegment->m_Result.im =
+ pSegment->m_Image =
pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause);
- if (!pSegment->m_Result.im)
+ if (!pSegment->m_Image)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
m_pStream->offset(2);
} else {
- pSegment->m_Result.im = pHRD->decode_MMR(m_pStream.get());
- if (!pSegment->m_Result.im)
+ pSegment->m_Image = pHRD->decode_MMR(m_pStream.get());
+ if (!pSegment->m_Image)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
}
@@ -1043,10 +1040,9 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0);
}
}
- m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im,
+ m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Image.get(),
(JBig2ComposeOp)(ri.flags & 0x03));
- delete pSegment->m_Result.im;
- pSegment->m_Result.im = nullptr;
+ pSegment->m_Image.reset();
}
return JBIG2_SUCCESS;
}
@@ -1090,9 +1086,8 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
if (!m_pArithDecoder) {
m_pArithDecoder =
pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
- m_ProcessingStatus = m_pGRD->Start_decode_Arith(&pSegment->m_Result.im,
- m_pArithDecoder.get(),
- &m_gbContext[0], pPause);
+ m_ProcessingStatus = m_pGRD->Start_decode_Arith(
+ &pSegment->m_Image, m_pArithDecoder.get(), &m_gbContext[0], pPause);
} else {
m_ProcessingStatus =
m_pGRD->Continue_decode(pPause, m_pArithDecoder.get());
@@ -1109,14 +1104,14 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
}
FX_RECT Rect = m_pGRD->GetReplaceRect();
m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top,
- pSegment->m_Result.im,
+ pSegment->m_Image.get(),
(JBig2ComposeOp)(m_ri.flags & 0x03), &Rect);
}
return JBIG2_SUCCESS;
}
m_pArithDecoder.reset();
m_gbContext.clear();
- if (!pSegment->m_Result.im) {
+ if (!pSegment->m_Image) {
m_ProcessingStatus = FXCODEC_STATUS_ERROR;
m_pGRD.reset();
return JBIG2_ERROR_FATAL;
@@ -1124,8 +1119,8 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
m_pStream->alignByte();
m_pStream->offset(2);
} else {
- m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream.get());
- if (!pSegment->m_Result.im) {
+ m_pGRD->Start_decode_MMR(&pSegment->m_Image, m_pStream.get());
+ if (!pSegment->m_Image) {
m_pGRD.reset();
return JBIG2_ERROR_FATAL;
}
@@ -1142,10 +1137,9 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
}
FX_RECT Rect = m_pGRD->GetReplaceRect();
m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top,
- pSegment->m_Result.im,
+ pSegment->m_Image.get(),
(JBig2ComposeOp)(m_ri.flags & 0x03), &Rect);
- delete pSegment->m_Result.im;
- pSegment->m_Result.im = nullptr;
+ pSegment->m_Image.reset();
}
m_pGRD.reset();
return JBIG2_SUCCESS;
@@ -1185,7 +1179,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
if (i >= pSegment->m_nReferred_to_segment_count)
return JBIG2_ERROR_FATAL;
- pGRRD->GRREFERENCE = pSeg->m_Result.im;
+ pGRRD->GRREFERENCE = pSeg->m_Image.get();
} else {
pGRRD->GRREFERENCE = m_pPage.get();
}
@@ -1197,8 +1191,8 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size);
auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
- pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get());
- if (!pSegment->m_Result.im)
+ pSegment->m_Image = pGRRD->decode(pArithDecoder.get(), grContext.get());
+ if (!pSegment->m_Image)
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
@@ -1211,22 +1205,21 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0);
}
}
- m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im,
+ m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Image.get(),
(JBig2ComposeOp)(ri.flags & 0x03));
- delete pSegment->m_Result.im;
- pSegment->m_Result.im = nullptr;
+ pSegment->m_Image.reset();
}
return JBIG2_SUCCESS;
}
int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) {
pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER;
- pSegment->m_Result.ht = nullptr;
+ pSegment->m_HuffmanTable.reset();
auto pHuff = pdfium::MakeUnique<CJBig2_HuffmanTable>(m_pStream.get());
if (!pHuff->IsOK())
return JBIG2_ERROR_FATAL;
- pSegment->m_Result.ht = pHuff.release();
+ pSegment->m_HuffmanTable = std::move(pHuff);
m_pStream->alignByte();
return JBIG2_SUCCESS;
}
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;
}
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.h b/core/fxcodec/jbig2/JBig2_GrdProc.h
index 3e4d3d403e..ef02a7d45a 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_GRDPROC_H_
#define CORE_FXCODEC_JBIG2_JBIG2_GRDPROC_H_
+#include <memory>
+
#include "core/fxcodec/fx_codec_def.h"
#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_coordinates.h"
@@ -23,14 +25,14 @@ class CJBig2_GRDProc {
CJBig2_GRDProc();
~CJBig2_GRDProc();
- CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
- FXCODEC_STATUS Start_decode_Arith(CJBig2_Image** pImage,
+ FXCODEC_STATUS Start_decode_Arith(std::unique_ptr<CJBig2_Image>* pImage,
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext,
IFX_Pause* pPause);
- FXCODEC_STATUS Start_decode_MMR(CJBig2_Image** pImage,
+ FXCODEC_STATUS Start_decode_MMR(std::unique_ptr<CJBig2_Image>* pImage,
CJBig2_BitStream* pStream);
FXCODEC_STATUS Continue_decode(IFX_Pause* pPause,
CJBig2_ArithDecoder* pArithDecoder);
@@ -88,34 +90,42 @@ class CJBig2_GRDProc {
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext,
IFX_Pause* pPause);
- CJBig2_Image* decode_Arith_Template0_opt3(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith_Template0_opt3(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
- CJBig2_Image* decode_Arith_Template0_unopt(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith_Template0_unopt(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
- CJBig2_Image* decode_Arith_Template1_opt3(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith_Template1_opt3(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
- CJBig2_Image* decode_Arith_Template1_unopt(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith_Template1_unopt(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
- CJBig2_Image* decode_Arith_Template2_opt3(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith_Template2_opt3(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
- CJBig2_Image* decode_Arith_Template2_unopt(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith_Template2_unopt(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
- CJBig2_Image* decode_Arith_Template3_opt3(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith_Template3_opt3(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
- CJBig2_Image* decode_Arith_Template3_unopt(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext);
+ std::unique_ptr<CJBig2_Image> decode_Arith_Template3_unopt(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext);
uint32_t m_loopIndex;
uint8_t* m_pLine;
FXCODEC_STATUS m_ProssiveStatus;
- CJBig2_Image** m_pImage;
+ CJBig2_Image* m_pImage;
JBig2ArithCtx* m_gbContext;
uint16_t m_DecodeType;
int m_LTP;
diff --git a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp
index 936b851d37..11fa39945d 100644
--- a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp
@@ -13,10 +13,11 @@
#include "core/fxcodec/jbig2/JBig2_Image.h"
#include "third_party/base/ptr_util.h"
-CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* grContext) {
+std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* grContext) {
if (GRW == 0 || GRH == 0)
- return new CJBig2_Image(GRW, GRH);
+ return pdfium::MakeUnique<CJBig2_Image>(GRW, GRH);
if (!GRTEMPLATE) {
if ((GRAT[0] == -1) && (GRAT[1] == -1) && (GRAT[2] == -1) &&
@@ -29,10 +30,11 @@ CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder,
if ((GRREFERENCEDX == 0) && (GRW == (uint32_t)GRREFERENCE->width()))
return decode_Template1_opt(pArithDecoder, grContext);
+
return decode_Template1_unopt(pArithDecoder, grContext);
}
-CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt(
+std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template0_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* grContext) {
int LTP = 0;
@@ -145,10 +147,10 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt(
}
}
}
- return GRREG.release();
+ return GRREG;
}
-CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt(
+std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template0_opt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* grContext) {
if (!GRREFERENCE->m_pData)
@@ -273,14 +275,13 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt(
}
}
pLine += nStride;
- if (h < GRHR + GRREFERENCEDY) {
+ if (h < GRHR + GRREFERENCEDY)
pLineR += nStrideR;
- }
}
- return GRREG.release();
+ return GRREG;
}
-CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt(
+std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template1_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* grContext) {
int LTP = 0;
@@ -379,10 +380,10 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt(
}
}
}
- return GRREG.release();
+ return GRREG;
}
-CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt(
+std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template1_opt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* grContext) {
if (!GRREFERENCE->m_pData)
@@ -496,9 +497,8 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt(
}
}
pLine += nStride;
- if (h < GRHR + GRREFERENCEDY) {
+ if (h < GRHR + GRREFERENCEDY)
pLineR += nStrideR;
- }
}
- return GRREG.release();
+ return GRREG;
}
diff --git a/core/fxcodec/jbig2/JBig2_GrrdProc.h b/core/fxcodec/jbig2/JBig2_GrrdProc.h
index bdb49d7e91..43f535335d 100644
--- a/core/fxcodec/jbig2/JBig2_GrrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_GrrdProc.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_GRRDPROC_H_
#define CORE_FXCODEC_JBIG2_JBIG2_GRRDPROC_H_
+#include <memory>
+
#include "core/fxcrt/fx_system.h"
class CJBig2_ArithDecoder;
@@ -15,21 +17,9 @@ struct JBig2ArithCtx;
class CJBig2_GRRDProc {
public:
- CJBig2_Image* decode(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* grContext);
-
- CJBig2_Image* decode_Template0_unopt(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* grContext);
-
- CJBig2_Image* decode_Template0_opt(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* grContext);
-
- CJBig2_Image* decode_Template1_unopt(CJBig2_ArithDecoder* pArithDecoder,
+ std::unique_ptr<CJBig2_Image> decode(CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* grContext);
- CJBig2_Image* decode_Template1_opt(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* grContext);
-
uint32_t GRW;
uint32_t GRH;
bool GRTEMPLATE;
@@ -38,6 +28,23 @@ class CJBig2_GRRDProc {
int32_t GRREFERENCEDY;
bool TPGRON;
int8_t GRAT[4];
+
+ private:
+ std::unique_ptr<CJBig2_Image> decode_Template0_unopt(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* grContext);
+
+ std::unique_ptr<CJBig2_Image> decode_Template0_opt(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* grContext);
+
+ std::unique_ptr<CJBig2_Image> decode_Template1_unopt(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* grContext);
+
+ std::unique_ptr<CJBig2_Image> decode_Template1_opt(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* grContext);
};
#endif // CORE_FXCODEC_JBIG2_JBIG2_GRRDPROC_H_
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();
}
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
index 1e8710b417..f17e818588 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
@@ -6,15 +6,14 @@
#include "core/fxcodec/jbig2/JBig2_HtrdProc.h"
-#include <memory>
-
#include "core/fxcodec/jbig2/JBig2_GsidProc.h"
#include "core/fxcrt/fx_basic.h"
#include "third_party/base/ptr_util.h"
-CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext,
- IFX_Pause* pPause) {
+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;
@@ -65,10 +64,11 @@ CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
}
}
FX_Free(GI);
- return HTREG.release();
+ return HTREG;
}
-CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream) {
+std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_MMR(
+ CJBig2_BitStream* pStream) {
uint32_t ng, mg;
int32_t x, y;
uint32_t* GI;
@@ -100,5 +100,5 @@ CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream) {
}
}
FX_Free(GI);
- return HTREG.release();
+ return HTREG;
}
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.h b/core/fxcodec/jbig2/JBig2_HtrdProc.h
index e562123098..eff25a67bb 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_HTRDPROC_H_
#define CORE_FXCODEC_JBIG2_JBIG2_HTRDPROC_H_
+#include <memory>
+
#include "core/fxcodec/jbig2/JBig2_Image.h"
#include "core/fxcrt/fx_system.h"
@@ -17,11 +19,11 @@ struct JBig2ArithCtx;
class CJBig2_HTRDProc {
public:
- CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext,
- IFX_Pause* pPause);
+ std::unique_ptr<CJBig2_Image> decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext,
+ IFX_Pause* pPause);
- CJBig2_Image* decode_MMR(CJBig2_BitStream* pStream);
+ std::unique_ptr<CJBig2_Image> decode_MMR(CJBig2_BitStream* pStream);
public:
uint32_t HBW;
diff --git a/core/fxcodec/jbig2/JBig2_PddProc.cpp b/core/fxcodec/jbig2/JBig2_PddProc.cpp
index 040ee6666b..7a44dc7e39 100644
--- a/core/fxcodec/jbig2/JBig2_PddProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_PddProc.cpp
@@ -13,12 +13,12 @@
#include "core/fxcodec/jbig2/JBig2_PatternDict.h"
#include "third_party/base/ptr_util.h"
-CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith(
+std::unique_ptr<CJBig2_PatternDict> CJBig2_PDDProc::decode_Arith(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext,
IFX_Pause* pPause) {
uint32_t GRAY;
- CJBig2_Image* BHDC = nullptr;
+ std::unique_ptr<CJBig2_Image> BHDC;
auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>();
pDict->NUMPATS = GRAYMAX + 1;
pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS);
@@ -53,13 +53,13 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith(
pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH);
GRAY = GRAY + 1;
}
- delete BHDC;
- return pDict.release();
+ return pDict;
}
-CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream) {
+std::unique_ptr<CJBig2_PatternDict> CJBig2_PDDProc::decode_MMR(
+ CJBig2_BitStream* pStream) {
uint32_t GRAY;
- CJBig2_Image* BHDC = nullptr;
+ std::unique_ptr<CJBig2_Image> BHDC;
auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>();
pDict->NUMPATS = GRAYMAX + 1;
pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS);
@@ -78,6 +78,5 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream) {
pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH);
GRAY = GRAY + 1;
}
- delete BHDC;
- return pDict.release();
+ return pDict;
}
diff --git a/core/fxcodec/jbig2/JBig2_PddProc.h b/core/fxcodec/jbig2/JBig2_PddProc.h
index 3bb97d0614..af27889ff1 100644
--- a/core/fxcodec/jbig2/JBig2_PddProc.h
+++ b/core/fxcodec/jbig2/JBig2_PddProc.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_PDDPROC_H_
#define CORE_FXCODEC_JBIG2_JBIG2_PDDPROC_H_
+#include <memory>
+
#include "core/fxcrt/fx_system.h"
class CJBig2_ArithDecoder;
@@ -17,11 +19,12 @@ struct JBig2ArithCtx;
class CJBig2_PDDProc {
public:
- CJBig2_PatternDict* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* gbContext,
- IFX_Pause* pPause);
+ std::unique_ptr<CJBig2_PatternDict> decode_Arith(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext,
+ IFX_Pause* pPause);
- CJBig2_PatternDict* decode_MMR(CJBig2_BitStream* pStream);
+ std::unique_ptr<CJBig2_PatternDict> decode_MMR(CJBig2_BitStream* pStream);
public:
bool HDMMR;
diff --git a/core/fxcodec/jbig2/JBig2_SddProc.cpp b/core/fxcodec/jbig2/JBig2_SddProc.cpp
index e296e32d21..0d2f35581e 100644
--- a/core/fxcodec/jbig2/JBig2_SddProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_SddProc.cpp
@@ -22,7 +22,7 @@
#include "core/fxcrt/fx_basic.h"
#include "third_party/base/ptr_util.h"
-CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith(
+std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::decode_Arith(
CJBig2_ArithDecoder* pArithDecoder,
std::vector<JBig2ArithCtx>* gbContext,
std::vector<JBig2ArithCtx>* grContext) {
@@ -31,7 +31,6 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith(
int32_t HCDH;
uint32_t SYMWIDTH, TOTWIDTH;
int32_t DW;
- CJBig2_Image* BS;
uint32_t I, J, REFAGGNINST;
std::vector<bool> EXFLAGS;
uint32_t EXINDEX;
@@ -69,7 +68,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith(
HCHEIGHT = 0;
NSYMSDECODED = 0;
while (NSYMSDECODED < SDNUMNEWSYMS) {
- BS = nullptr;
+ std::unique_ptr<CJBig2_Image> BS;
IADH->decode(pArithDecoder, &HCDH);
HCHEIGHT = HCHEIGHT + HCDH;
if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE)
@@ -218,8 +217,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith(
return nullptr;
}
}
- SDNEWSYMS[NSYMSDECODED] = pdfium::WrapUnique<CJBig2_Image>(BS);
- BS = nullptr;
+ SDNEWSYMS[NSYMSDECODED] = std::move(BS);
NSYMSDECODED = NSYMSDECODED + 1;
}
}
@@ -259,10 +257,10 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith(
}
++J;
}
- return pDict.release();
+ return pDict;
}
-CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(
+std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::decode_Huffman(
CJBig2_BitStream* pStream,
std::vector<JBig2ArithCtx>* gbContext,
std::vector<JBig2ArithCtx>* grContext) {
@@ -272,7 +270,6 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(
int32_t HCDH;
uint32_t SYMWIDTH, TOTWIDTH, HCFIRSTSYM;
int32_t DW;
- CJBig2_Image *BS, *BHC;
uint32_t I, J, REFAGGNINST;
std::vector<bool> EXFLAGS;
uint32_t EXINDEX;
@@ -292,7 +289,6 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(
std::vector<CJBig2_Image*> SBSYMS;
auto pHuffmanDecoder = pdfium::MakeUnique<CJBig2_HuffmanDecoder>(pStream);
SDNEWSYMS.resize(SDNUMNEWSYMS);
- BHC = nullptr;
if (SDREFAGG == 0)
SDNEWSYMWIDTHS.resize(SDNUMNEWSYMS);
auto pDict = pdfium::MakeUnique<CJBig2_SymbolDict>();
@@ -300,7 +296,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(
HCHEIGHT = 0;
NSYMSDECODED = 0;
- BS = nullptr;
+ std::unique_ptr<CJBig2_Image> BS;
while (NSYMSDECODED < SDNUMNEWSYMS) {
if (pHuffmanDecoder->decodeAValue(SDHUFFDH, &HCDH) != 0)
return nullptr;
@@ -456,12 +452,10 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(
pStream->alignByte();
pStream->offset(2);
- if ((uint32_t)nVal != (pStream->getOffset() - nTmp)) {
- delete BS;
+ if ((uint32_t)nVal != (pStream->getOffset() - nTmp))
return nullptr;
- }
}
- SDNEWSYMS[NSYMSDECODED] = pdfium::WrapUnique<CJBig2_Image>(BS);
+ SDNEWSYMS[NSYMSDECODED] = std::move(BS);
}
if (SDREFAGG == 0)
SDNEWSYMWIDTHS[NSYMSDECODED] = SYMWIDTH;
@@ -472,10 +466,11 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(
return nullptr;
pStream->alignByte();
+ std::unique_ptr<CJBig2_Image> BHC;
if (BMSIZE == 0) {
stride = (TOTWIDTH + 7) >> 3;
if (pStream->getByteLeft() >= stride * HCHEIGHT) {
- BHC = new CJBig2_Image(TOTWIDTH, HCHEIGHT);
+ BHC = pdfium::MakeUnique<CJBig2_Image>(TOTWIDTH, HCHEIGHT);
for (I = 0; I < HCHEIGHT; I++) {
JBIG2_memcpy(BHC->m_pData + I * BHC->stride(),
pStream->getPointer(), stride);
@@ -493,16 +488,14 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(
pStream->alignByte();
}
nTmp = 0;
- if (!BHC) {
+ if (!BHC)
continue;
- }
+
for (I = HCFIRSTSYM; I < NSYMSDECODED; I++) {
SDNEWSYMS[I] = pdfium::WrapUnique<CJBig2_Image>(
BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT));
nTmp += SDNEWSYMWIDTHS[I];
}
- delete BHC;
- BHC = nullptr;
}
}
EXINDEX = 0;
@@ -545,5 +538,5 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(
}
++J;
}
- return pDict.release();
+ return pDict;
}
diff --git a/core/fxcodec/jbig2/JBig2_SddProc.h b/core/fxcodec/jbig2/JBig2_SddProc.h
index 20e0569935..80b988ef98 100644
--- a/core/fxcodec/jbig2/JBig2_SddProc.h
+++ b/core/fxcodec/jbig2/JBig2_SddProc.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_SDDPROC_H_
#define CORE_FXCODEC_JBIG2_JBIG2_SDDPROC_H_
+#include <memory>
#include <vector>
#include "core/fxcodec/jbig2/JBig2_ArithDecoder.h"
@@ -19,13 +20,15 @@ class CJBig2_SymbolDict;
class CJBig2_SDDProc {
public:
- CJBig2_SymbolDict* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
- std::vector<JBig2ArithCtx>* gbContext,
- std::vector<JBig2ArithCtx>* grContext);
-
- CJBig2_SymbolDict* decode_Huffman(CJBig2_BitStream* pStream,
- std::vector<JBig2ArithCtx>* gbContext,
- std::vector<JBig2ArithCtx>* grContext);
+ std::unique_ptr<CJBig2_SymbolDict> decode_Arith(
+ CJBig2_ArithDecoder* pArithDecoder,
+ std::vector<JBig2ArithCtx>* gbContext,
+ std::vector<JBig2ArithCtx>* grContext);
+
+ std::unique_ptr<CJBig2_SymbolDict> decode_Huffman(
+ CJBig2_BitStream* pStream,
+ std::vector<JBig2ArithCtx>* gbContext,
+ std::vector<JBig2ArithCtx>* grContext);
bool SDHUFF;
bool SDREFAGG;
diff --git a/core/fxcodec/jbig2/JBig2_Segment.cpp b/core/fxcodec/jbig2/JBig2_Segment.cpp
index 610246b6e2..886989abd8 100644
--- a/core/fxcodec/jbig2/JBig2_Segment.cpp
+++ b/core/fxcodec/jbig2/JBig2_Segment.cpp
@@ -20,25 +20,8 @@ CJBig2_Segment::CJBig2_Segment() {
m_dwDataOffset = 0;
m_State = JBIG2_SEGMENT_HEADER_UNPARSED;
m_nResultType = JBIG2_VOID_POINTER;
- m_Result.vd = nullptr;
}
+
CJBig2_Segment::~CJBig2_Segment() {
FX_Free(m_pReferred_to_segment_numbers);
-
- switch (m_nResultType) {
- case JBIG2_IMAGE_POINTER:
- delete m_Result.im;
- break;
- case JBIG2_SYMBOL_DICT_POINTER:
- delete m_Result.sd;
- break;
- case JBIG2_PATTERN_DICT_POINTER:
- delete m_Result.pd;
- break;
- case JBIG2_HUFFMAN_TABLE_POINTER:
- delete m_Result.ht;
- break;
- default:
- FX_Free(m_Result.vd);
- }
}
diff --git a/core/fxcodec/jbig2/JBig2_Segment.h b/core/fxcodec/jbig2/JBig2_Segment.h
index d89d652699..26af0f6890 100644
--- a/core/fxcodec/jbig2/JBig2_Segment.h
+++ b/core/fxcodec/jbig2/JBig2_Segment.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_SEGMENT_H_
#define CORE_FXCODEC_JBIG2_JBIG2_SEGMENT_H_
+#include <memory>
+
#include "core/fxcodec/jbig2/JBig2_Define.h"
#include "core/fxcodec/jbig2/JBig2_HuffmanTable.h"
#include "core/fxcodec/jbig2/JBig2_PatternDict.h"
@@ -54,13 +56,10 @@ class CJBig2_Segment {
uint32_t m_dwDataOffset;
JBig2_SegmentState m_State;
JBig2_ResultType m_nResultType;
- union {
- CJBig2_SymbolDict* sd;
- CJBig2_PatternDict* pd;
- CJBig2_Image* im;
- CJBig2_HuffmanTable* ht;
- void* vd;
- } m_Result;
+ std::unique_ptr<CJBig2_SymbolDict> m_SymbolDict;
+ std::unique_ptr<CJBig2_PatternDict> m_PatternDict;
+ std::unique_ptr<CJBig2_Image> m_Image;
+ std::unique_ptr<CJBig2_HuffmanTable> m_HuffmanTable;
};
#endif // CORE_FXCODEC_JBIG2_JBIG2_SEGMENT_H_
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
index f681e05569..b7661045dc 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
@@ -14,8 +14,9 @@
#include "core/fxcodec/jbig2/JBig2_HuffmanDecoder.h"
#include "third_party/base/ptr_util.h"
-CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
- JBig2ArithCtx* grContext) {
+std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::decode_Huffman(
+ CJBig2_BitStream* pStream,
+ JBig2ArithCtx* grContext) {
auto pHuffmanDecoder = pdfium::MakeUnique<CJBig2_HuffmanDecoder>(pStream);
auto SBREG = pdfium::MakeUnique<CJBig2_Image>(SBW, SBH);
SBREG->fill(SBDEFPIXEL);
@@ -48,20 +49,19 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
} else {
int32_t IDS;
int32_t nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS);
- if (nVal == JBIG2_OOB) {
+ if (nVal == JBIG2_OOB)
break;
- } else if (nVal != 0) {
+
+ if (nVal != 0)
return nullptr;
- } else {
- CURS = CURS + IDS + SBDSOFFSET;
- }
+
+ CURS = CURS + IDS + SBDSOFFSET;
}
uint8_t CURT = 0;
if (SBSTRIPS != 1) {
uint32_t nTmp = 1;
- while ((uint32_t)(1 << nTmp) < SBSTRIPS) {
- nTmp++;
- }
+ while (static_cast<uint32_t>(1 << nTmp) < SBSTRIPS)
+ ++nTmp;
int32_t nVal;
if (pStream->readNBits(nTmp, &nVal) != 0)
return nullptr;
@@ -89,14 +89,12 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
break;
}
}
- if (IDI < SBNUMSYMS) {
+ if (IDI < SBNUMSYMS)
break;
- }
}
bool RI = 0;
- if (SBREFINE != 0 && pStream->read1Bit(&RI) != 0) {
+ if (SBREFINE != 0 && pStream->read1Bit(&RI) != 0)
return nullptr;
- }
CJBig2_Image* IBI = nullptr;
if (RI == 0) {
IBI = SBSYMS[IDI];
@@ -137,12 +135,10 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
pGRRD->GRAT[2] = SBRAT[2];
pGRRD->GRAT[3] = SBRAT[3];
- {
- auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(pStream);
- IBI = pGRRD->decode(pArithDecoder.get(), grContext);
- if (!IBI)
- return nullptr;
- }
+ auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(pStream);
+ IBI = pGRRD->decode(pArithDecoder.get(), grContext).release();
+ if (!IBI)
+ return nullptr;
pStream->alignByte();
pStream->offset(2);
@@ -151,9 +147,9 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
return nullptr;
}
}
- if (!IBI) {
+ if (!IBI)
continue;
- }
+
uint32_t WI = IBI->width();
uint32_t HI = IBI->height();
if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) ||
@@ -208,12 +204,13 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
NINSTANCES = NINSTANCES + 1;
}
}
- return SBREG.release();
+ return SBREG;
}
-CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* grContext,
- JBig2IntDecoderState* pIDS) {
+std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::decode_Arith(
+ CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* grContext,
+ JBig2IntDecoderState* pIDS) {
std::unique_ptr<CJBig2_ArithIntDecoder> IADT;
std::unique_ptr<CJBig2_ArithIntDecoder> IAFS;
std::unique_ptr<CJBig2_ArithIntDecoder> IADS;
@@ -350,7 +347,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
pGRRD->GRAT[1] = SBRAT[1];
pGRRD->GRAT[2] = SBRAT[2];
pGRRD->GRAT[3] = SBRAT[3];
- IBI.reset(pGRRD->decode(pArithDecoder, grContext));
+ IBI = pGRRD->decode(pArithDecoder, grContext);
pIBI = IBI.get();
}
if (!pIBI)
@@ -407,5 +404,5 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
++NINSTANCES;
}
}
- return SBREG.release();
+ return SBREG;
}
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.h b/core/fxcodec/jbig2/JBig2_TrdProc.h
index be50ec152f..db35a8870a 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_TRDPROC_H_
#define CORE_FXCODEC_JBIG2_JBIG2_TRDPROC_H_
+#include <memory>
+
#include "core/fxcodec/jbig2/JBig2_Image.h"
#include "core/fxcrt/fx_system.h"
@@ -40,12 +42,12 @@ enum JBig2Corner {
class CJBig2_TRDProc {
public:
- CJBig2_Image* decode_Huffman(CJBig2_BitStream* pStream,
- JBig2ArithCtx* grContext);
+ std::unique_ptr<CJBig2_Image> decode_Huffman(CJBig2_BitStream* pStream,
+ JBig2ArithCtx* grContext);
- CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
- JBig2ArithCtx* grContext,
- JBig2IntDecoderState* pIDS);
+ std::unique_ptr<CJBig2_Image> decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* grContext,
+ JBig2IntDecoderState* pIDS);
bool SBHUFF;
bool SBREFINE;