diff options
author | thestig <thestig@chromium.org> | 2016-08-05 22:34:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-05 22:34:58 -0700 |
commit | f41d9dc1ead47a1218e1cd37bd74ec850c8baaa3 (patch) | |
tree | d8d32b58909814f9835898c4a87f03b5bc510e69 /core/fpdfapi/fpdf_render | |
parent | 8ca63de14d522d3d259d74fa43b28b05b02728e8 (diff) | |
download | pdfium-f41d9dc1ead47a1218e1cd37bd74ec850c8baaa3.tar.xz |
Add CPDF_ImageObject::GetImage().
And use it where appropriate.
Review-Url: https://codereview.chromium.org/2224623002
Diffstat (limited to 'core/fpdfapi/fpdf_render')
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render.cpp | 9 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_image.cpp | 11 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 70 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/render_int.h | 5 |
4 files changed, 45 insertions, 50 deletions
diff --git a/core/fpdfapi/fpdf_render/fpdf_render.cpp b/core/fpdfapi/fpdf_render/fpdf_render.cpp index ef208b54fd..f4e1414172 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render.cpp @@ -6,6 +6,8 @@ #include "core/fpdfapi/fpdf_render/render_int.h" +#include <memory> + #include "core/fpdfapi/fpdf_font/cpdf_type3char.h" #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" #include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h" @@ -686,7 +688,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : nullptr; if (pSMaskDict) { if (pPageObj->IsImage() && - pPageObj->AsImage()->m_pImage->GetDict()->KeyExist("SMask")) { + pPageObj->AsImage()->GetImage()->GetDict()->KeyExist("SMask")) { pSMaskDict = nullptr; } } @@ -721,11 +723,12 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, pPage = m_pContext->GetPageCache()->GetPage(); pDocument = pPage->m_pDocument; } else { - pDocument = pPageObj->AsImage()->m_pImage->GetDocument(); + pDocument = pPageObj->AsImage()->GetImage()->GetDocument(); } CPDF_Dictionary* pPageResources = pPage ? pPage->m_pPageResources : nullptr; CPDF_Object* pCSObj = pPageObj->AsImage() - ->m_pImage->GetStream() + ->GetImage() + ->GetStream() ->GetDict() ->GetDirectObjectBy("ColorSpace"); CPDF_ColorSpace* pColorSpace = diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp index fc0321b46b..f4f82a131e 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/fpdf_render/render_int.h" +#include <memory> #include <utility> #include <vector> @@ -442,7 +443,7 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { } if (m_pRenderStatus->m_pDevice->GetDeviceClass() != FXDC_DISPLAY) { CPDF_Object* pFilters = - m_pImageObject->m_pImage->GetStream()->GetDict()->GetDirectObjectBy( + m_pImageObject->GetImage()->GetStream()->GetDict()->GetDirectObjectBy( "Filter"); if (pFilters) { if (pFilters->IsName()) { @@ -463,7 +464,7 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { } if (m_pRenderStatus->m_Options.m_Flags & RENDER_NOIMAGESMOOTH) { m_Flags |= FXDIB_NOSMOOTH; - } else if (m_pImageObject->m_pImage->IsInterpol()) { + } else if (m_pImageObject->GetImage()->IsInterpol()) { m_Flags |= FXDIB_INTERPOL; } if (m_Loader.m_pMask) { @@ -482,11 +483,11 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { pPage = m_pRenderStatus->m_pContext->GetPageCache()->GetPage(); pDocument = pPage->m_pDocument; } else { - pDocument = m_pImageObject->m_pImage->GetDocument(); + pDocument = m_pImageObject->GetImage()->GetDocument(); } CPDF_Dictionary* pPageResources = pPage ? pPage->m_pPageResources : nullptr; CPDF_Object* pCSObj = - m_pImageObject->m_pImage->GetStream()->GetDict()->GetDirectObjectBy( + m_pImageObject->GetImage()->GetStream()->GetDict()->GetDirectObjectBy( "ColorSpace"); CPDF_ColorSpace* pColorSpace = pDocument->LoadColorSpace(pCSObj, pPageResources); @@ -512,7 +513,7 @@ FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus, m_pImageObject = pObj->AsImage(); m_BlendType = blendType; m_pObj2Device = pObj2Device; - CPDF_Dictionary* pOC = m_pImageObject->m_pImage->GetOC(); + CPDF_Dictionary* pOC = m_pImageObject->GetImage()->GetOC(); if (pOC && m_pRenderStatus->m_Options.m_pOCContext && !m_pRenderStatus->m_Options.m_pOCContext->CheckOCGVisible(pOC)) { return FALSE; diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 3edfe58f07..2fe6730479 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -28,11 +28,11 @@ unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16); ASSERT((bitpos & (nbits - 1)) == 0); unsigned int byte = pData[bitpos / 8]; - if (nbits == 8) { + if (nbits == 8) return byte; - } else if (nbits == 16) { + + if (nbits == 16) return byte * 256 + pData[bitpos / 8 + 1]; - } return (byte >> (8 - nbits - (bitpos % 8))) & ((1 << nbits) - 1); } @@ -1492,53 +1492,41 @@ FX_BOOL CPDF_ImageLoaderHandle::Start(CPDF_ImageLoader* pImageLoader, m_nDownsampleHeight = nDownsampleHeight; FX_BOOL ret; if (pCache) { - ret = pCache->StartGetCachedBitmap(pImage->m_pImage->GetStream(), bStdCS, - GroupFamily, bLoadMask, pRenderStatus, - m_nDownsampleWidth, m_nDownsampleHeight); - if (!ret) { - m_pImageLoader->m_bCached = TRUE; - m_pImageLoader->m_pBitmap = - pCache->GetCurImageCacheEntry()->DetachBitmap(); - m_pImageLoader->m_pMask = pCache->GetCurImageCacheEntry()->DetachMask(); - m_pImageLoader->m_MatteColor = - pCache->GetCurImageCacheEntry()->m_MatteColor; - } + ret = pCache->StartGetCachedBitmap( + m_pImage->GetImage()->GetStream(), bStdCS, GroupFamily, bLoadMask, + pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); } else { - ret = pImage->m_pImage->StartLoadDIBSource(pRenderStatus->m_pFormResource, - pRenderStatus->m_pPageResource, - bStdCS, GroupFamily, bLoadMask); - if (!ret) { - m_pImageLoader->m_bCached = FALSE; - m_pImageLoader->m_pBitmap = m_pImage->m_pImage->DetachBitmap(); - m_pImageLoader->m_pMask = m_pImage->m_pImage->DetachMask(); - m_pImageLoader->m_MatteColor = m_pImage->m_pImage->m_MatteColor; - } + ret = m_pImage->GetImage()->StartLoadDIBSource( + pRenderStatus->m_pFormResource, pRenderStatus->m_pPageResource, bStdCS, + GroupFamily, bLoadMask); } + if (!ret) + HandleFailure(); return ret; } FX_BOOL CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) { - FX_BOOL ret; + FX_BOOL ret = m_pCache ? m_pCache->Continue(pPause) + : m_pImage->GetImage()->Continue(pPause); + if (!ret) + HandleFailure(); + return ret; +} + +void CPDF_ImageLoaderHandle::HandleFailure() { if (m_pCache) { - ret = m_pCache->Continue(pPause); - if (!ret) { - m_pImageLoader->m_bCached = TRUE; - m_pImageLoader->m_pBitmap = - m_pCache->GetCurImageCacheEntry()->DetachBitmap(); - m_pImageLoader->m_pMask = m_pCache->GetCurImageCacheEntry()->DetachMask(); - m_pImageLoader->m_MatteColor = - m_pCache->GetCurImageCacheEntry()->m_MatteColor; - } + CPDF_ImageCacheEntry* entry = m_pCache->GetCurImageCacheEntry(); + m_pImageLoader->m_bCached = TRUE; + m_pImageLoader->m_pBitmap = entry->DetachBitmap(); + m_pImageLoader->m_pMask = entry->DetachMask(); + m_pImageLoader->m_MatteColor = entry->m_MatteColor; } else { - ret = m_pImage->m_pImage->Continue(pPause); - if (!ret) { - m_pImageLoader->m_bCached = FALSE; - m_pImageLoader->m_pBitmap = m_pImage->m_pImage->DetachBitmap(); - m_pImageLoader->m_pMask = m_pImage->m_pImage->DetachMask(); - m_pImageLoader->m_MatteColor = m_pImage->m_pImage->m_MatteColor; - } + CPDF_Image* pImage = m_pImage->GetImage(); + m_pImageLoader->m_bCached = FALSE; + m_pImageLoader->m_pBitmap = pImage->DetachBitmap(); + m_pImageLoader->m_pMask = pImage->DetachMask(); + m_pImageLoader->m_MatteColor = pImage->m_MatteColor; } - return ret; } FX_BOOL CPDF_ImageLoader::Start( diff --git a/core/fpdfapi/fpdf_render/render_int.h b/core/fpdfapi/fpdf_render/render_int.h index 4494b8cefb..e3e1a8ad42 100644 --- a/core/fpdfapi/fpdf_render/render_int.h +++ b/core/fpdfapi/fpdf_render/render_int.h @@ -102,7 +102,7 @@ class CPDF_TransferFunc { class CPDF_DocRenderData { public: - CPDF_DocRenderData(CPDF_Document* pPDFDoc = nullptr); + explicit CPDF_DocRenderData(CPDF_Document* pPDFDoc); ~CPDF_DocRenderData(); CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont); CPDF_TransferFunc* GetTransferFunc(CPDF_Object* pObj); @@ -313,6 +313,7 @@ class CPDF_ImageLoader { int32_t m_nDownsampleWidth; int32_t m_nDownsampleHeight; }; + class CPDF_ImageLoaderHandle { public: CPDF_ImageLoaderHandle(); @@ -330,6 +331,8 @@ class CPDF_ImageLoaderHandle { FX_BOOL Continue(IFX_Pause* pPause); protected: + void HandleFailure(); + CPDF_ImageLoader* m_pImageLoader; CPDF_PageRenderCache* m_pCache; CPDF_ImageObject* m_pImage; |