summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-01 14:32:54 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-01 14:32:54 +0000
commitea603b9f0baf33462b61fa4ee6364e4f4161f55a (patch)
tree0a1f18531181ac30a4a87cd5e67909f4248bfb66
parent723543481bea9c6ea14fc39b71333b34eb8d89b4 (diff)
downloadpdfium-ea603b9f0baf33462b61fa4ee6364e4f4161f55a.tar.xz
Clean up CJBig2_Image compose methods.
- Mark them private when possible. - Disambiguate method names. - Make method names match the style guide. - Pass in rects by reference. Change-Id: I0bf848756e81a92d20e46a81cd6260b660eaf482 Reviewed-on: https://pdfium-review.googlesource.com/31772 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp22
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.cpp4
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.h2
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.cpp6
-rw-r--r--core/fxcodec/jbig2/JBig2_Image.cpp75
-rw-r--r--core/fxcodec/jbig2/JBig2_Image.h45
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.cpp32
7 files changed, 86 insertions, 100 deletions
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 8d416ffc3c..76dff1d592 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -931,7 +931,7 @@ 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_Image.get(),
+ m_pPage->ComposeFrom(ri.x, ri.y, pSegment->m_Image.get(),
(JBig2ComposeOp)(ri.flags & 0x03));
pSegment->m_Image.reset();
}
@@ -1051,7 +1051,7 @@ 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_Image.get(),
+ m_pPage->ComposeFrom(ri.x, ri.y, pSegment->m_Image.get(),
(JBig2ComposeOp)(ri.flags & 0x03));
pSegment->m_Image.reset();
}
@@ -1113,10 +1113,10 @@ int32_t CJBig2_Context::ParseGenericRegion(CJBig2_Segment* pSegment,
(pPageInfo->m_cFlags & 4) ? 1 : 0);
}
}
- FX_RECT Rect = m_pGRD->GetReplaceRect();
- m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top,
- pSegment->m_Image.get(),
- (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect);
+ const FX_RECT& rect = m_pGRD->GetReplaceRect();
+ m_pPage->ComposeFromWithRect(m_ri.x + rect.left, m_ri.y + rect.top,
+ pSegment->m_Image.get(), rect,
+ (JBig2ComposeOp)(m_ri.flags & 0x03));
}
return JBIG2_SUCCESS;
}
@@ -1146,10 +1146,10 @@ int32_t CJBig2_Context::ParseGenericRegion(CJBig2_Segment* pSegment,
(pPageInfo->m_cFlags & 4) ? 1 : 0);
}
}
- FX_RECT Rect = m_pGRD->GetReplaceRect();
- m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top,
- pSegment->m_Image.get(),
- (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect);
+ const FX_RECT& rect = m_pGRD->GetReplaceRect();
+ m_pPage->ComposeFromWithRect(m_ri.x + rect.left, m_ri.y + rect.top,
+ pSegment->m_Image.get(), rect,
+ (JBig2ComposeOp)(m_ri.flags & 0x03));
pSegment->m_Image.reset();
}
m_pGRD.reset();
@@ -1219,7 +1219,7 @@ 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_Image.get(),
+ m_pPage->ComposeFrom(ri.x, ri.y, pSegment->m_Image.get(),
(JBig2ComposeOp)(ri.flags & 0x03));
pSegment->m_Image.reset();
}
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
index bc256f7b2a..ef3c2d8562 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
@@ -22,10 +22,6 @@ CJBig2_GRDProc::CJBig2_GRDProc()
m_pLine(nullptr),
m_DecodeType(0),
m_LTP(0) {
- m_ReplaceRect.left = 0;
- m_ReplaceRect.bottom = 0;
- m_ReplaceRect.top = 0;
- m_ReplaceRect.right = 0;
}
CJBig2_GRDProc::~CJBig2_GRDProc() {}
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.h b/core/fxcodec/jbig2/JBig2_GrdProc.h
index 30c0fa6b6b..08081dde3d 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.h
@@ -36,7 +36,7 @@ class CJBig2_GRDProc {
CJBig2_BitStream* pStream);
FXCODEC_STATUS ContinueDecode(PauseIndicatorIface* pPause,
CJBig2_ArithDecoder* pArithDecoder);
- FX_RECT GetReplaceRect() const { return m_ReplaceRect; }
+ const FX_RECT& GetReplaceRect() const { return m_ReplaceRect; }
bool MMR;
uint32_t GBW;
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
index c1eaf918b5..8618236264 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
@@ -74,7 +74,7 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::DecodeArith(
GSPLANES[i] = std::move(pImage);
if (i < GSBPP - 1)
- GSPLANES[i]->composeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR);
+ GSPLANES[i]->ComposeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR);
}
return DecodeImage(GSPLANES);
}
@@ -105,7 +105,7 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::DecodeMMR(
pStream->alignByte();
pStream->offset(3);
- GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1].get(), JBIG2_COMPOSE_XOR);
+ GSPLANES[J]->ComposeFrom(0, 0, GSPLANES[J + 1].get(), JBIG2_COMPOSE_XOR);
}
return DecodeImage(GSPLANES);
}
@@ -126,7 +126,7 @@ std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::DecodeImage(
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);
+ HTREG->ComposeFrom(x, y, (*HPATS)[pat_index].get(), HCOMBOP);
}
}
return HTREG;
diff --git a/core/fxcodec/jbig2/JBig2_Image.cpp b/core/fxcodec/jbig2/JBig2_Image.cpp
index 7a01d01d64..3a45223c1e 100644
--- a/core/fxcodec/jbig2/JBig2_Image.cpp
+++ b/core/fxcodec/jbig2/JBig2_Image.cpp
@@ -126,44 +126,37 @@ void CJBig2_Image::fill(bool v) {
JBIG2_memset(data(), v ? 0xff : 0, m_nStride * m_nHeight);
}
-bool CJBig2_Image::composeTo(CJBig2_Image* pDst,
+bool CJBig2_Image::ComposeTo(CJBig2_Image* pDst,
int32_t x,
int32_t y,
JBig2ComposeOp op) {
- if (!m_pData)
- return false;
-
- return composeTo_opt2(pDst, x, y, op);
+ return m_pData ? ComposeToOpt2(pDst, x, y, op) : false;
}
-bool CJBig2_Image::composeTo(CJBig2_Image* pDst,
- int32_t x,
- int32_t y,
- JBig2ComposeOp op,
- const FX_RECT* pSrcRect) {
+bool CJBig2_Image::ComposeToWithRect(CJBig2_Image* pDst,
+ int32_t x,
+ int32_t y,
+ const FX_RECT& rtSrc,
+ JBig2ComposeOp op) {
if (!m_pData)
return false;
- if (!pSrcRect || *pSrcRect == FX_RECT(0, 0, m_nWidth, m_nHeight))
- return composeTo_opt2(pDst, x, y, op);
-
- return composeTo_opt2(pDst, x, y, op, pSrcRect);
+ if (rtSrc == FX_RECT(0, 0, m_nWidth, m_nHeight))
+ return ComposeToOpt2(pDst, x, y, op);
+ return ComposeToOpt2WithRect(pDst, x, y, op, rtSrc);
}
-bool CJBig2_Image::composeFrom(int32_t x,
+bool CJBig2_Image::ComposeFrom(int32_t x,
int32_t y,
CJBig2_Image* pSrc,
JBig2ComposeOp op) {
- if (!m_pData)
- return false;
-
- return pSrc->composeTo(this, x, y, op);
+ return m_pData ? pSrc->ComposeTo(this, x, y, op) : false;
}
-bool CJBig2_Image::composeFrom(int32_t x,
- int32_t y,
- CJBig2_Image* pSrc,
- JBig2ComposeOp op,
- const FX_RECT* pSrcRect) {
- return m_pData ? pSrc->composeTo(this, x, y, op, pSrcRect) : false;
+bool CJBig2_Image::ComposeFromWithRect(int32_t x,
+ int32_t y,
+ CJBig2_Image* pSrc,
+ const FX_RECT& rtSrc,
+ JBig2ComposeOp op) {
+ return m_pData ? pSrc->ComposeToWithRect(this, x, y, rtSrc, op) : false;
}
#define JBIG2_GETDWORD(buf) \
@@ -253,12 +246,11 @@ void CJBig2_Image::expand(int32_t h, bool v) {
m_nHeight = h;
}
-bool CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst,
- int32_t x,
- int32_t y,
- JBig2ComposeOp op) {
- if (!m_pData)
- return false;
+bool CJBig2_Image::ComposeToOpt2(CJBig2_Image* pDst,
+ int32_t x,
+ int32_t y,
+ JBig2ComposeOp op) {
+ ASSERT(m_pData);
if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576)
return false;
@@ -686,20 +678,19 @@ bool CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst,
return true;
}
-bool CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst,
- int32_t x,
- int32_t y,
- JBig2ComposeOp op,
- const FX_RECT* pSrcRect) {
- if (!m_pData)
- return false;
+bool CJBig2_Image::ComposeToOpt2WithRect(CJBig2_Image* pDst,
+ int32_t x,
+ int32_t y,
+ JBig2ComposeOp op,
+ const FX_RECT& rtSrc) {
+ ASSERT(m_pData);
// TODO(weili): Check whether the range check is correct. Should x>=1048576?
if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) {
return false;
}
- int32_t sw = pSrcRect->Width();
- int32_t sh = pSrcRect->Height();
+ int32_t sw = rtSrc.Width();
+ int32_t sh = rtSrc.Height();
int32_t ys0 = y < 0 ? -y : 0;
int32_t ys1 = y + sh > pDst->m_nHeight ? pDst->m_nHeight - y : sh;
int32_t xs0 = x < 0 ? -x : 0;
@@ -719,8 +710,8 @@ bool CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst,
int32_t maskL = 0xffffffff >> d1;
int32_t maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32);
int32_t maskM = maskL & maskR;
- uint8_t* lineSrc = data() + (pSrcRect->top + ys0) * m_nStride +
- (((xs0 + pSrcRect->left) >> 5) << 2);
+ uint8_t* lineSrc =
+ data() + (rtSrc.top + ys0) * m_nStride + (((xs0 + rtSrc.left) >> 5) << 2);
int32_t lineLeft = m_nStride - ((xs0 >> 5) << 2);
uint8_t* lineDst = pDst->data() + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2);
if ((xd0 & ~31) == ((xd1 - 1) & ~31)) {
diff --git a/core/fxcodec/jbig2/JBig2_Image.h b/core/fxcodec/jbig2/JBig2_Image.h
index 51ccaeb8f7..0d0a7f0794 100644
--- a/core/fxcodec/jbig2/JBig2_Image.h
+++ b/core/fxcodec/jbig2/JBig2_Image.h
@@ -42,29 +42,12 @@ class CJBig2_Image {
void copyLine(int32_t hTo, int32_t hFrom);
void fill(bool v);
- bool composeTo(CJBig2_Image* pDst, int32_t x, int32_t y, JBig2ComposeOp op);
- bool composeTo(CJBig2_Image* pDst,
- int32_t x,
- int32_t y,
- JBig2ComposeOp op,
- const FX_RECT* pSrcRect);
-
- bool composeTo_opt2(CJBig2_Image* pDst,
- int32_t x,
- int32_t y,
- JBig2ComposeOp op);
- bool composeTo_opt2(CJBig2_Image* pDst,
- int32_t x,
- int32_t y,
- JBig2ComposeOp op,
- const FX_RECT* pSrcRect);
-
- bool composeFrom(int32_t x, int32_t y, CJBig2_Image* pSrc, JBig2ComposeOp op);
- bool composeFrom(int32_t x,
- int32_t y,
- CJBig2_Image* pSrc,
- JBig2ComposeOp op,
- const FX_RECT* pSrcRect);
+ bool ComposeFrom(int32_t x, int32_t y, CJBig2_Image* pSrc, JBig2ComposeOp op);
+ bool ComposeFromWithRect(int32_t x,
+ int32_t y,
+ CJBig2_Image* pSrc,
+ const FX_RECT& rtSrc,
+ JBig2ComposeOp op);
std::unique_ptr<CJBig2_Image> subImage(int32_t x,
int32_t y,
@@ -74,6 +57,22 @@ class CJBig2_Image {
private:
+ bool ComposeTo(CJBig2_Image* pDst, int32_t x, int32_t y, JBig2ComposeOp op);
+ bool ComposeToWithRect(CJBig2_Image* pDst,
+ int32_t x,
+ int32_t y,
+ const FX_RECT& rtSrc,
+ JBig2ComposeOp op);
+ bool ComposeToOpt2(CJBig2_Image* pDst,
+ int32_t x,
+ int32_t y,
+ JBig2ComposeOp op);
+ bool ComposeToOpt2WithRect(CJBig2_Image* pDst,
+ int32_t x,
+ int32_t y,
+ JBig2ComposeOp op,
+ const FX_RECT& rtSrc);
+
MaybeOwned<uint8_t, FxFreeDeleter> m_pData;
int32_t m_nWidth; // 1-bit pixels
int32_t m_nHeight; // lines
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
index 140d948956..b59f63bab4 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
@@ -179,31 +179,31 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeHuffman(
if (TRANSPOSED == 0) {
switch (REFCORNER) {
case JBIG2_CORNER_TOPLEFT:
- SBREG->composeFrom(SI, TI, IBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(SI, TI, IBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_TOPRIGHT:
- SBREG->composeFrom(SI - WI + 1, TI, IBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(SI - WI + 1, TI, IBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_BOTTOMLEFT:
- SBREG->composeFrom(SI, TI - HI + 1, IBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(SI, TI - HI + 1, IBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_BOTTOMRIGHT:
- SBREG->composeFrom(SI - WI + 1, TI - HI + 1, IBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(SI - WI + 1, TI - HI + 1, IBI.Get(), SBCOMBOP);
break;
}
} else {
switch (REFCORNER) {
case JBIG2_CORNER_TOPLEFT:
- SBREG->composeFrom(TI, SI, IBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(TI, SI, IBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_TOPRIGHT:
- SBREG->composeFrom(TI - WI + 1, SI, IBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(TI - WI + 1, SI, IBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_BOTTOMLEFT:
- SBREG->composeFrom(TI, SI - HI + 1, IBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(TI, SI - HI + 1, IBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_BOTTOMRIGHT:
- SBREG->composeFrom(TI - WI + 1, SI - HI + 1, IBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(TI - WI + 1, SI - HI + 1, IBI.Get(), SBCOMBOP);
break;
}
}
@@ -372,31 +372,31 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeArith(
if (TRANSPOSED == 0) {
switch (REFCORNER) {
case JBIG2_CORNER_TOPLEFT:
- SBREG->composeFrom(SI, TI, pIBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(SI, TI, pIBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_TOPRIGHT:
- SBREG->composeFrom(SI - WI + 1, TI, pIBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(SI - WI + 1, TI, pIBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_BOTTOMLEFT:
- SBREG->composeFrom(SI, TI - HI + 1, pIBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(SI, TI - HI + 1, pIBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_BOTTOMRIGHT:
- SBREG->composeFrom(SI - WI + 1, TI - HI + 1, pIBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(SI - WI + 1, TI - HI + 1, pIBI.Get(), SBCOMBOP);
break;
}
} else {
switch (REFCORNER) {
case JBIG2_CORNER_TOPLEFT:
- SBREG->composeFrom(TI, SI, pIBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(TI, SI, pIBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_TOPRIGHT:
- SBREG->composeFrom(TI - WI + 1, SI, pIBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(TI - WI + 1, SI, pIBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_BOTTOMLEFT:
- SBREG->composeFrom(TI, SI - HI + 1, pIBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(TI, SI - HI + 1, pIBI.Get(), SBCOMBOP);
break;
case JBIG2_CORNER_BOTTOMRIGHT:
- SBREG->composeFrom(TI - WI + 1, SI - HI + 1, pIBI.Get(), SBCOMBOP);
+ SBREG->ComposeFrom(TI - WI + 1, SI - HI + 1, pIBI.Get(), SBCOMBOP);
break;
}
}