From f41d9dc1ead47a1218e1cd37bd74ec850c8baaa3 Mon Sep 17 00:00:00 2001 From: thestig Date: Fri, 5 Aug 2016 22:34:58 -0700 Subject: Add CPDF_ImageObject::GetImage(). And use it where appropriate. Review-Url: https://codereview.chromium.org/2224623002 --- .../fpdf_edit/cpdf_pagecontentgenerator.cpp | 10 ++-- core/fpdfapi/fpdf_font/cpdf_type3char.cpp | 2 +- core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 4 +- core/fpdfapi/fpdf_page/include/cpdf_imageobject.h | 1 + core/fpdfapi/fpdf_render/fpdf_render.cpp | 9 ++- core/fpdfapi/fpdf_render/fpdf_render_image.cpp | 11 ++-- core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 70 +++++++++------------- core/fpdfapi/fpdf_render/render_int.h | 5 +- 8 files changed, 55 insertions(+), 57 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp index 0b87e75f62..a85591ceef 100644 --- a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp @@ -58,6 +58,7 @@ void CPDF_PageContentGenerator::GenerateContent() { m_pDocument->AddIndirectObject(pStream); pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); } + CFX_ByteString CPDF_PageContentGenerator::RealizeResource( CPDF_Object* pResourceObj, const CFX_ByteString& bsType) { @@ -84,6 +85,7 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( pResList->SetAtReference(name, m_pDocument, pResourceObj->GetObjNum()); return name; } + void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, CPDF_ImageObject* pImageObj) { if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || @@ -91,13 +93,13 @@ void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, return; } buf << "q " << pImageObj->m_Matrix << " cm "; - if (!pImageObj->m_pImage->IsInline()) { - CPDF_Stream* pStream = pImageObj->m_pImage->GetStream(); + CPDF_Image* pImage = pImageObj->GetImage(); + if (!pImage->IsInline()) { + CPDF_Stream* pStream = pImage->GetStream(); uint32_t dwSavedObjNum = pStream->GetObjNum(); CFX_ByteString name = RealizeResource(pStream, "XObject"); if (dwSavedObjNum == 0) { - if (pImageObj->m_pImage) - pImageObj->m_pImage->Release(); + pImage->Release(); pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pStream); } buf << "/" << PDF_NameEncode(name) << " Do Q\n"; diff --git a/core/fpdfapi/fpdf_font/cpdf_type3char.cpp b/core/fpdfapi/fpdf_font/cpdf_type3char.cpp index 9bfda99fd1..b80a4ccdd0 100644 --- a/core/fpdfapi/fpdf_font/cpdf_type3char.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_type3char.cpp @@ -31,7 +31,7 @@ FX_BOOL CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) { m_ImageMatrix = pPageObj->AsImage()->m_Matrix; std::unique_ptr pSource( - pPageObj->AsImage()->m_pImage->LoadDIBSource()); + pPageObj->AsImage()->GetImage()->LoadDIBSource()); if (pSource) m_pBitmap.reset(pSource->Clone()); m_pForm.reset(); diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 5a77ba70b2..e20fe44db8 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -743,7 +743,7 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() { if (type == "Image") { CPDF_ImageObject* pObj = AddImage(pXObject, nullptr, false); m_LastImageName = name; - m_pLastImage = pObj->m_pImage; + m_pLastImage = pObj->GetImage(); if (!m_pObjectHolder->HasImageMask()) m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask()); } else if (type == "Form") { @@ -792,7 +792,7 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, pImageObj->m_pImage = new CPDF_Image(m_pDocument); pImageObj->m_pImage->LoadImageF(pStream, bInline); } - SetGraphicStates(pImageObj.get(), pImageObj->m_pImage->IsMask(), FALSE, + SetGraphicStates(pImageObj.get(), pImageObj->GetImage()->IsMask(), FALSE, FALSE); pImageObj->m_Matrix = ImageMatrix; pImageObj->CalcBoundingBox(); diff --git a/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h b/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h index 1128d12f8b..b2bffa707c 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h @@ -26,6 +26,7 @@ class CPDF_ImageObject : public CPDF_PageObject { const CPDF_ImageObject* AsImage() const override; void CalcBoundingBox(); + CPDF_Image* GetImage() const { return m_pImage; } CPDF_Image* m_pImage; CFX_Matrix m_Matrix; 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 + #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 #include #include @@ -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; -- cgit v1.2.3