summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec/jbig2')
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp2
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.cpp16
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.h3
-rw-r--r--core/fxcodec/jbig2/JBig2_Image.cpp38
-rw-r--r--core/fxcodec/jbig2/JBig2_Image.h7
-rw-r--r--core/fxcodec/jbig2/JBig2_PatternDict.cpp15
-rw-r--r--core/fxcodec/jbig2/JBig2_PatternDict.h7
-rw-r--r--core/fxcodec/jbig2/JBig2_PddProc.cpp10
-rw-r--r--core/fxcodec/jbig2/JBig2_SddProc.cpp9
9 files changed, 51 insertions, 56 deletions
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 826f4be8ff..219946d219 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -1008,7 +1008,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
return JBIG2_ERROR_FATAL;
pHRD->HNUMPATS = pPatternDict->NUMPATS;
- pHRD->HPATS = pPatternDict->HDPATS;
+ pHRD->HPATS = &pPatternDict->HDPATS;
pHRD->HPW = pPatternDict->HDPATS[0]->width();
pHRD->HPH = pPatternDict->HDPATS[0]->height();
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
index f17e818588..a7de28607e 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
@@ -6,6 +6,8 @@
#include "core/fxcodec/jbig2/JBig2_HtrdProc.h"
+#include <algorithm>
+
#include "core/fxcodec/jbig2/JBig2_GsidProc.h"
#include "core/fxcrt/fx_basic.h"
#include "third_party/base/ptr_util.h"
@@ -56,11 +58,8 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_Arith(
for (ng = 0; ng < HGW; ng++) {
x = (HGX + mg * HRY + ng * HRX) >> 8;
y = (HGY + mg * HRX - ng * HRY) >> 8;
- uint32_t pat_index = GI[mg * HGW + ng];
- if (pat_index >= HNUMPATS) {
- pat_index = HNUMPATS - 1;
- }
- HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP);
+ uint32_t pat_index = std::min(GI[mg * HGW + ng], HNUMPATS - 1);
+ HTREG->composeFrom(x, y, (*HPATS)[pat_index].get(), HCOMBOP);
}
}
FX_Free(GI);
@@ -92,11 +91,8 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_MMR(
for (ng = 0; ng < HGW; ng++) {
x = (HGX + mg * HRY + ng * HRX) >> 8;
y = (HGY + mg * HRX - ng * HRY) >> 8;
- uint32_t pat_index = GI[mg * HGW + ng];
- if (pat_index >= HNUMPATS) {
- pat_index = HNUMPATS - 1;
- }
- HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP);
+ uint32_t pat_index = std::min(GI[mg * HGW + ng], HNUMPATS - 1);
+ HTREG->composeFrom(x, y, (*HPATS)[pat_index].get(), HCOMBOP);
}
}
FX_Free(GI);
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.h b/core/fxcodec/jbig2/JBig2_HtrdProc.h
index eff25a67bb..85e9059d66 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.h
@@ -8,6 +8,7 @@
#define CORE_FXCODEC_JBIG2_JBIG2_HTRDPROC_H_
#include <memory>
+#include <vector>
#include "core/fxcodec/jbig2/JBig2_Image.h"
#include "core/fxcrt/fx_system.h"
@@ -31,7 +32,7 @@ class CJBig2_HTRDProc {
bool HMMR;
uint8_t HTEMPLATE;
uint32_t HNUMPATS;
- CJBig2_Image** HPATS;
+ const std::vector<std::unique_ptr<CJBig2_Image>>* HPATS;
bool HDEFPIXEL;
JBig2ComposeOp HCOMBOP;
bool HENABLESKIP;
diff --git a/core/fxcodec/jbig2/JBig2_Image.cpp b/core/fxcodec/jbig2/JBig2_Image.cpp
index 8f935ceb1f..f026ce660b 100644
--- a/core/fxcodec/jbig2/JBig2_Image.cpp
+++ b/core/fxcodec/jbig2/JBig2_Image.cpp
@@ -9,6 +9,7 @@
#include "core/fxcodec/jbig2/JBig2_Image.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_safe_types.h"
+#include "third_party/base/ptr_util.h"
namespace {
@@ -162,32 +163,37 @@ bool CJBig2_Image::composeFrom(int32_t x,
CJBig2_Image* pSrc,
JBig2ComposeOp op,
const FX_RECT* pSrcRect) {
- if (!m_pData) {
- return false;
- }
- return pSrc->composeTo(this, x, y, op, pSrcRect);
+ return m_pData ? pSrc->composeTo(this, x, y, op, pSrcRect) : false;
}
+
#define JBIG2_GETDWORD(buf) \
((uint32_t)(((buf)[0] << 24) | ((buf)[1] << 16) | ((buf)[2] << 8) | (buf)[3]))
-CJBig2_Image* CJBig2_Image::subImage(int32_t x,
- int32_t y,
- int32_t w,
- int32_t h) {
- int32_t m, n, j;
- uint8_t *pLineSrc, *pLineDst;
+
+std::unique_ptr<CJBig2_Image> CJBig2_Image::subImage(int32_t x,
+ int32_t y,
+ int32_t w,
+ int32_t h) {
+ int32_t m;
+ int32_t n;
+ int32_t j;
+ uint8_t* pLineSrc;
+ uint8_t* pLineDst;
uint32_t wTmp;
- uint8_t *pSrc, *pSrcEnd, *pDst, *pDstEnd;
- if (w == 0 || h == 0) {
+ uint8_t* pSrc;
+ uint8_t* pSrcEnd;
+ uint8_t* pDst;
+ uint8_t* pDstEnd;
+ if (w == 0 || h == 0)
return nullptr;
- }
- CJBig2_Image* pImage = new CJBig2_Image(w, h);
+
+ auto pImage = pdfium::MakeUnique<CJBig2_Image>(w, h);
if (!m_pData) {
pImage->fill(0);
return pImage;
}
- if (!pImage->m_pData) {
+ if (!pImage->m_pData)
return pImage;
- }
+
pLineSrc = m_pData + m_nStride * y;
pLineDst = pImage->m_pData;
m = (x >> 5) << 2;
diff --git a/core/fxcodec/jbig2/JBig2_Image.h b/core/fxcodec/jbig2/JBig2_Image.h
index 54529ef868..807468aa0b 100644
--- a/core/fxcodec/jbig2/JBig2_Image.h
+++ b/core/fxcodec/jbig2/JBig2_Image.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_IMAGE_H_
#define CORE_FXCODEC_JBIG2_JBIG2_IMAGE_H_
+#include <memory>
+
#include "core/fxcodec/jbig2/JBig2_Define.h"
struct FX_RECT;
@@ -60,7 +62,10 @@ class CJBig2_Image {
JBig2ComposeOp op,
const FX_RECT* pSrcRect);
- CJBig2_Image* subImage(int32_t x, int32_t y, int32_t w, int32_t h);
+ std::unique_ptr<CJBig2_Image> subImage(int32_t x,
+ int32_t y,
+ int32_t w,
+ int32_t h);
void expand(int32_t h, bool v);
uint8_t* m_pData;
diff --git a/core/fxcodec/jbig2/JBig2_PatternDict.cpp b/core/fxcodec/jbig2/JBig2_PatternDict.cpp
index cd6a2ad3c2..450e78a8fa 100644
--- a/core/fxcodec/jbig2/JBig2_PatternDict.cpp
+++ b/core/fxcodec/jbig2/JBig2_PatternDict.cpp
@@ -8,16 +8,7 @@
#include "core/fxcrt/fx_memory.h"
-CJBig2_PatternDict::CJBig2_PatternDict() {
- NUMPATS = 0;
- HDPATS = nullptr;
-}
+CJBig2_PatternDict::CJBig2_PatternDict(uint32_t dict_size)
+ : NUMPATS(dict_size), HDPATS(dict_size) {}
-CJBig2_PatternDict::~CJBig2_PatternDict() {
- if (HDPATS) {
- for (uint32_t i = 0; i < NUMPATS; i++) {
- delete HDPATS[i];
- }
- FX_Free(HDPATS);
- }
-}
+CJBig2_PatternDict::~CJBig2_PatternDict() {}
diff --git a/core/fxcodec/jbig2/JBig2_PatternDict.h b/core/fxcodec/jbig2/JBig2_PatternDict.h
index dddd4747f0..ad55917d6b 100644
--- a/core/fxcodec/jbig2/JBig2_PatternDict.h
+++ b/core/fxcodec/jbig2/JBig2_PatternDict.h
@@ -7,17 +7,20 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_PATTERNDICT_H_
#define CORE_FXCODEC_JBIG2_JBIG2_PATTERNDICT_H_
+#include <memory>
+#include <vector>
+
#include "core/fxcodec/jbig2/JBig2_Define.h"
#include "core/fxcodec/jbig2/JBig2_Image.h"
class CJBig2_PatternDict {
public:
- CJBig2_PatternDict();
+ explicit CJBig2_PatternDict(uint32_t dict_size);
~CJBig2_PatternDict();
uint32_t NUMPATS;
- CJBig2_Image** HDPATS;
+ std::vector<std::unique_ptr<CJBig2_Image>> HDPATS;
};
#endif // CORE_FXCODEC_JBIG2_JBIG2_PATTERNDICT_H_
diff --git a/core/fxcodec/jbig2/JBig2_PddProc.cpp b/core/fxcodec/jbig2/JBig2_PddProc.cpp
index 7a44dc7e39..e195d8f403 100644
--- a/core/fxcodec/jbig2/JBig2_PddProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_PddProc.cpp
@@ -19,10 +19,7 @@ std::unique_ptr<CJBig2_PatternDict> CJBig2_PDDProc::decode_Arith(
IFX_Pause* pPause) {
uint32_t GRAY;
std::unique_ptr<CJBig2_Image> BHDC;
- auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>();
- pDict->NUMPATS = GRAYMAX + 1;
- pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS);
- JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS);
+ auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>(GRAYMAX + 1);
auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>();
pGRD->MMR = HDMMR;
@@ -60,10 +57,7 @@ std::unique_ptr<CJBig2_PatternDict> CJBig2_PDDProc::decode_MMR(
CJBig2_BitStream* pStream) {
uint32_t GRAY;
std::unique_ptr<CJBig2_Image> BHDC;
- auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>();
- pDict->NUMPATS = GRAYMAX + 1;
- pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS);
- JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS);
+ auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>(GRAYMAX + 1);
auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>();
pGRD->MMR = HDMMR;
diff --git a/core/fxcodec/jbig2/JBig2_SddProc.cpp b/core/fxcodec/jbig2/JBig2_SddProc.cpp
index 0d2f35581e..d23fb049b1 100644
--- a/core/fxcodec/jbig2/JBig2_SddProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_SddProc.cpp
@@ -491,9 +491,8 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::decode_Huffman(
if (!BHC)
continue;
- for (I = HCFIRSTSYM; I < NSYMSDECODED; I++) {
- SDNEWSYMS[I] = pdfium::WrapUnique<CJBig2_Image>(
- BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT));
+ for (I = HCFIRSTSYM; I < NSYMSDECODED; ++I) {
+ SDNEWSYMS[I] = BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT);
nTmp += SDNEWSYMWIDTHS[I];
}
}
@@ -512,7 +511,7 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::decode_Huffman(
return nullptr;
if (EXRUNLENGTH != 0) {
- for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; I++) {
+ for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; ++I) {
if (CUREXFLAG)
num_ex_syms++;
@@ -526,7 +525,7 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::decode_Huffman(
return nullptr;
I = J = 0;
- for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) {
+ for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; ++I) {
if (!EXFLAGS[I] || J >= SDNUMEXSYMS)
continue;
if (I < SDNUMINSYMS) {