summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render/cpdf_imagerenderer.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-05-09 19:24:59 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-10 17:22:24 +0000
commit3e2d1ac83977b0fc150b4b25532f4e82048dc3e1 (patch)
treed4875087fb8e3964695e8118b0a60a761a9bc9ed /core/fpdfapi/render/cpdf_imagerenderer.cpp
parent58577fd17020f52314bba8989be964a8c2fd010d (diff)
downloadpdfium-3e2d1ac83977b0fc150b4b25532f4e82048dc3e1.tar.xz
Simplify CPDF_ImageRenderer::StartRenderDIBSource().
Change-Id: Ia0a78be3320c5d6c3d0c40d4199cae1473e0e8dc Reviewed-on: https://pdfium-review.googlesource.com/5253 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/render/cpdf_imagerenderer.cpp')
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.cpp85
1 files changed, 45 insertions, 40 deletions
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index 8a963d2be9..6562e154fc 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -77,24 +77,20 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
if (!m_Loader.m_pBitmap)
return false;
- m_BitmapAlpha =
- FXSYS_round(255 * m_pImageObject->m_GeneralState.GetFillAlpha());
+ CPDF_GeneralState& state = m_pImageObject->m_GeneralState;
+ m_BitmapAlpha = FXSYS_round(255 * state.GetFillAlpha());
m_pDIBSource = m_Loader.m_pBitmap;
if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_ALPHA &&
!m_Loader.m_pMask) {
return StartBitmapAlpha();
}
- if (m_pImageObject->m_GeneralState.GetTR()) {
- if (!m_pImageObject->m_GeneralState.GetTransferFunc()) {
- m_pImageObject->m_GeneralState.SetTransferFunc(
- m_pRenderStatus->GetTransferFunc(
- m_pImageObject->m_GeneralState.GetTR()));
- }
- if (m_pImageObject->m_GeneralState.GetTransferFunc() &&
- !m_pImageObject->m_GeneralState.GetTransferFunc()->m_bIdentity) {
+ if (state.GetTR()) {
+ if (!state.GetTransferFunc())
+ state.SetTransferFunc(m_pRenderStatus->GetTransferFunc(state.GetTR()));
+
+ if (state.GetTransferFunc() && !state.GetTransferFunc()->m_bIdentity) {
m_pDIBSource = m_Loader.m_pBitmap =
- m_pImageObject->m_GeneralState.GetTransferFunc()->TranslateImage(
- m_Loader.m_pBitmap);
+ state.GetTransferFunc()->TranslateImage(m_Loader.m_pBitmap);
if (m_Loader.m_bCached && m_Loader.m_pMask)
m_Loader.m_pMask = m_Loader.m_pMask->Clone(nullptr);
m_Loader.m_bCached = false;
@@ -122,48 +118,30 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
m_Flags |= RENDER_FORCE_DOWNSAMPLE;
else if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_HALFTONE)
m_Flags |= RENDER_FORCE_HALFTONE;
- if (m_pRenderStatus->m_pDevice->GetDeviceClass() != FXDC_DISPLAY) {
- CPDF_Object* pFilters =
- m_pImageObject->GetImage()->GetStream()->GetDict()->GetDirectObjectFor(
- "Filter");
- if (pFilters) {
- if (pFilters->IsName()) {
- CFX_ByteString bsDecodeType = pFilters->GetString();
- if (bsDecodeType == "DCTDecode" || bsDecodeType == "JPXDecode")
- m_Flags |= FXRENDER_IMAGE_LOSSY;
- } else if (CPDF_Array* pArray = pFilters->AsArray()) {
- for (size_t i = 0; i < pArray->GetCount(); i++) {
- CFX_ByteString bsDecodeType = pArray->GetStringAt(i);
- if (bsDecodeType == "DCTDecode" || bsDecodeType == "JPXDecode") {
- m_Flags |= FXRENDER_IMAGE_LOSSY;
- break;
- }
- }
- }
- }
- }
+
+ if (m_pRenderStatus->m_pDevice->GetDeviceClass() != FXDC_DISPLAY)
+ HandleFilters();
+
if (m_pRenderStatus->m_Options.m_Flags & RENDER_NOIMAGESMOOTH)
m_Flags |= FXDIB_NOSMOOTH;
else if (m_pImageObject->GetImage()->IsInterpol())
m_Flags |= FXDIB_INTERPOL;
+
if (m_Loader.m_pMask)
return DrawMaskedImage();
if (m_bPatternColor)
return DrawPatternImage(m_pObj2Device);
- if (m_BitmapAlpha != 255 || !m_pImageObject->m_GeneralState ||
- !m_pImageObject->m_GeneralState.GetFillOP() ||
- m_pImageObject->m_GeneralState.GetOPMode() != 0 ||
- m_pImageObject->m_GeneralState.GetBlendType() != FXDIB_BLEND_NORMAL ||
- m_pImageObject->m_GeneralState.GetStrokeAlpha() != 1.0f ||
- m_pImageObject->m_GeneralState.GetFillAlpha() != 1.0f) {
+ if (m_BitmapAlpha != 255 || !state || !state.GetFillOP() ||
+ state.GetOPMode() != 0 || state.GetBlendType() != FXDIB_BLEND_NORMAL ||
+ state.GetStrokeAlpha() != 1.0f || state.GetFillAlpha() != 1.0f) {
return StartDIBSource();
}
CPDF_Document* pDocument = nullptr;
CPDF_Page* pPage = nullptr;
- if (m_pRenderStatus->m_pContext->GetPageCache()) {
- pPage = m_pRenderStatus->m_pContext->GetPageCache()->GetPage();
+ if (auto* pPageCache = m_pRenderStatus->m_pContext->GetPageCache()) {
+ pPage = pPageCache->GetPage();
pDocument = pPage->m_pDocument;
} else {
pDocument = m_pImageObject->GetImage()->GetDocument();
@@ -571,3 +549,30 @@ bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) {
}
return false;
}
+
+void CPDF_ImageRenderer::HandleFilters() {
+ CPDF_Object* pFilters =
+ m_pImageObject->GetImage()->GetStream()->GetDict()->GetDirectObjectFor(
+ "Filter");
+ if (!pFilters)
+ return;
+
+ if (pFilters->IsName()) {
+ CFX_ByteString bsDecodeType = pFilters->GetString();
+ if (bsDecodeType == "DCTDecode" || bsDecodeType == "JPXDecode")
+ m_Flags |= FXRENDER_IMAGE_LOSSY;
+ return;
+ }
+
+ CPDF_Array* pArray = pFilters->AsArray();
+ if (!pArray)
+ return;
+
+ for (size_t i = 0; i < pArray->GetCount(); i++) {
+ CFX_ByteString bsDecodeType = pArray->GetStringAt(i);
+ if (bsDecodeType == "DCTDecode" || bsDecodeType == "JPXDecode") {
+ m_Flags |= FXRENDER_IMAGE_LOSSY;
+ break;
+ }
+ }
+}