From 0b6e9aed1756d19ed812895208be5cae5633325b Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Wed, 12 Jul 2017 11:00:16 -0400 Subject: Nits in CFX_RenderDevice and CPDF_ContentParser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I29f1c4f68356e335cd55e38014699780bf658249 Reviewed-on: https://pdfium-review.googlesource.com/7610 Reviewed-by: dsinclair Commit-Queue: Nicolás Peña --- core/fpdfapi/page/cpdf_contentparser.h | 4 +- core/fpdfapi/page/cpdf_pageobjectholder.cpp | 4 +- core/fxge/cfx_renderdevice.cpp | 97 ++++++++++++++--------------- 3 files changed, 52 insertions(+), 53 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/page/cpdf_contentparser.h b/core/fpdfapi/page/cpdf_contentparser.h index b18e07036c..982a624346 100644 --- a/core/fpdfapi/page/cpdf_contentparser.h +++ b/core/fpdfapi/page/cpdf_contentparser.h @@ -29,7 +29,9 @@ class CPDF_ContentParser { ~CPDF_ContentParser(); ParseStatus GetStatus() const { return m_Status; } - CPDF_StreamContentParser* GetParser() const { return m_pParser.get(); } + const CPDF_AllStates* GetCurStates() const { + return m_pParser ? m_pParser->GetCurStates() : nullptr; + } void Start(CPDF_Page* pPage); void Start(CPDF_Form* pForm, CPDF_AllStates* pGraphicStates, diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp index 2b7e62b535..138cb0d204 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp +++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp @@ -39,8 +39,8 @@ void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { return; m_ParseState = CONTENT_PARSED; - if (m_pParser->GetParser() && m_pParser->GetParser()->GetCurStates()) - m_LastCTM = m_pParser->GetParser()->GetCurStates()->m_CTM; + if (m_pParser->GetCurStates()) + m_LastCTM = m_pParser->GetCurStates()->m_CTM; m_pParser.reset(); } diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp index b14829e41a..5d2ae86f2c 100644 --- a/core/fxge/cfx_renderdevice.cpp +++ b/core/fxge/cfx_renderdevice.cpp @@ -138,18 +138,6 @@ void ApplyDestAlpha(uint8_t back_alpha, dest[3] = dest_alpha; } -void NormalizeRgbDst(int src_value, int r, int g, int b, int a, uint8_t* dest) { - ApplyAlpha(dest, b, g, r, CalcAlpha(TextGammaAdjust(src_value), a)); -} - -void NormalizeRgbSrc(int src_value, int r, int g, int b, int a, uint8_t* dest) { - int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); - if (src_alpha == 0) - return; - - ApplyAlpha(dest, b, g, r, src_alpha); -} - void NormalizeArgb(int src_value, int r, int g, @@ -164,22 +152,36 @@ void NormalizeArgb(int src_value, ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); } -void NormalizeArgbDest(int src_value, - int r, - int g, - int b, - int a, - uint8_t* dest) { - NormalizeArgb(src_value, r, g, b, a, dest, - CalcAlpha(TextGammaAdjust(src_value), a)); +void NormalizeDest(bool has_alpha, + int src_value, + int r, + int g, + int b, + int a, + uint8_t* dest) { + if (has_alpha) { + NormalizeArgb(src_value, r, g, b, a, dest, + CalcAlpha(TextGammaAdjust(src_value), a)); + return; + } + int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); + if (src_alpha == 0) + return; + + ApplyAlpha(dest, b, g, r, src_alpha); } -void NormalizeArgbSrc(int src_value, - int r, - int g, - int b, - int a, - uint8_t* dest) { +void NormalizeSrc(bool has_alpha, + int src_value, + int r, + int g, + int b, + int a, + uint8_t* dest) { + if (!has_alpha) { + ApplyAlpha(dest, b, g, r, CalcAlpha(TextGammaAdjust(src_value), a)); + return; + } int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); if (src_alpha != 0) NormalizeArgb(src_value, r, g, b, a, dest, src_alpha); @@ -190,12 +192,11 @@ void NextPixel(uint8_t** src_scan, uint8_t** dst_scan, int bpp) { *dst_scan += bpp; } -void SetAlpha(uint8_t* alpha) { - alpha[3] = 255; +void SetAlpha(bool has_alpha, uint8_t* alpha) { + if (has_alpha) + alpha[3] = 255; } -void SetAlphaDoNothing(uint8_t* alpha) {} - void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, const CFX_RetainPtr& pGlyph, int nrows, @@ -216,10 +217,6 @@ void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, uint8_t* dest_buf = bitmap->GetBuffer(); int dest_pitch = bitmap->GetPitch(); const int Bpp = has_alpha ? 4 : bitmap->GetBPP() / 8; - auto* pNormalizeSrcFunc = has_alpha ? &NormalizeArgbSrc : &NormalizeRgbDst; - auto* pNormalizeDstFunc = has_alpha ? &NormalizeArgbDest : &NormalizeRgbSrc; - auto* pSetAlpha = has_alpha ? &SetAlpha : &SetAlphaDoNothing; - for (int row = 0; row < nrows; ++row) { int dest_row = row + top; if (dest_row < 0 || dest_row >= bitmap->GetHeight()) @@ -229,7 +226,7 @@ void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, uint8_t* dest_scan = dest_buf + dest_row * dest_pitch + start_col * Bpp; if (bBGRStripe) { if (x_subpixel == 0) { - for (int col = start_col; col < end_col; col++) { + for (int col = start_col; col < end_col; ++col) { if (has_alpha) { Merge(src_scan[2], r, a, &dest_scan[2]); Merge(src_scan[1], g, a, &dest_scan[1]); @@ -237,7 +234,7 @@ void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, } else { MergeGammaAdjustBgr(&src_scan[0], r, g, b, a, &dest_scan[0]); } - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); } continue; @@ -247,11 +244,11 @@ void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); if (start_col > left) MergeGammaAdjust(src_scan[-1], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); for (int col = start_col + 1; col < end_col - 1; ++col) { MergeGammaAdjustBgr(&src_scan[-1], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); } continue; @@ -261,11 +258,11 @@ void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); MergeGammaAdjust(src_scan[-2], b, a, &dest_scan[0]); } - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); for (int col = start_col + 1; col < end_col - 1; ++col) { MergeGammaAdjustBgr(&src_scan[-2], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); } continue; @@ -274,10 +271,10 @@ void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, for (int col = start_col; col < end_col; ++col) { if (bNormal) { int src_value = AverageRgb(&src_scan[0]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); + NormalizeDest(has_alpha, src_value, r, g, b, a, dest_scan); } else { MergeGammaAdjustRgb(&src_scan[0], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); } NextPixel(&src_scan, &dest_scan, Bpp); } @@ -287,22 +284,22 @@ void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, if (bNormal) { int src_value = start_col > left ? AverageRgb(&src_scan[-1]) : (src_scan[0] + src_scan[1]) / 3; - pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); + NormalizeSrc(has_alpha, src_value, r, g, b, a, dest_scan); } else { if (start_col > left) MergeGammaAdjust(src_scan[-1], r, a, &dest_scan[2]); MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); MergeGammaAdjust(src_scan[1], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); } NextPixel(&src_scan, &dest_scan, Bpp); for (int col = start_col + 1; col < end_col; ++col) { if (bNormal) { int src_value = AverageRgb(&src_scan[-1]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); + NormalizeDest(has_alpha, src_value, r, g, b, a, dest_scan); } else { MergeGammaAdjustRgb(&src_scan[-1], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); } NextPixel(&src_scan, &dest_scan, Bpp); } @@ -311,23 +308,23 @@ void DrawNormalTextHelper(const CFX_RetainPtr& bitmap, if (bNormal) { int src_value = start_col > left ? AverageRgb(&src_scan[-2]) : src_scan[0] / 3; - pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); + NormalizeSrc(has_alpha, src_value, r, g, b, a, dest_scan); } else { if (start_col > left) { MergeGammaAdjust(src_scan[-2], r, a, &dest_scan[2]); MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); } MergeGammaAdjust(src_scan[0], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); } NextPixel(&src_scan, &dest_scan, Bpp); for (int col = start_col + 1; col < end_col; ++col) { if (bNormal) { int src_value = AverageRgb(&src_scan[-2]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); + NormalizeDest(has_alpha, src_value, r, g, b, a, dest_scan); } else { MergeGammaAdjustRgb(&src_scan[-2], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); } NextPixel(&src_scan, &dest_scan, Bpp); } -- cgit v1.2.3