1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fpdfapi/render/cpdf_imageloader.h"
8
9 #include "core/fpdfapi/page/cpdf_image.h"
10 #include "core/fpdfapi/page/cpdf_imageobject.h"
11 #include "core/fpdfapi/render/cpdf_dibsource.h"
12 #include "core/fpdfapi/render/cpdf_imagecacheentry.h"
13 #include "core/fpdfapi/render/cpdf_pagerendercache.h"
14 #include "core/fpdfapi/render/cpdf_renderstatus.h"
15
CPDF_ImageLoader()16 CPDF_ImageLoader::CPDF_ImageLoader()
17 : m_MatteColor(0),
18 m_bCached(false),
19 m_pCache(nullptr),
20 m_pImageObject(nullptr) {}
21
~CPDF_ImageLoader()22 CPDF_ImageLoader::~CPDF_ImageLoader() {}
23
Start(const CPDF_ImageObject * pImage,CPDF_PageRenderCache * pCache,bool bStdCS,uint32_t GroupFamily,bool bLoadMask,CPDF_RenderStatus * pRenderStatus)24 bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
25 CPDF_PageRenderCache* pCache,
26 bool bStdCS,
27 uint32_t GroupFamily,
28 bool bLoadMask,
29 CPDF_RenderStatus* pRenderStatus) {
30 m_pCache = pCache;
31 m_pImageObject = const_cast<CPDF_ImageObject*>(pImage);
32 bool ret;
33 if (pCache) {
34 ret = pCache->StartGetCachedBitmap(m_pImageObject->GetImage(), bStdCS,
35 GroupFamily, bLoadMask, pRenderStatus);
36 } else {
37 ret = m_pImageObject->GetImage()->StartLoadDIBSource(
38 pRenderStatus->GetFormResource(), pRenderStatus->GetPageResource(),
39 bStdCS, GroupFamily, bLoadMask);
40 }
41 if (!ret)
42 HandleFailure();
43 return ret;
44 }
45
Continue(IFX_PauseIndicator * pPause,CPDF_RenderStatus * pRenderStatus)46 bool CPDF_ImageLoader::Continue(IFX_PauseIndicator* pPause,
47 CPDF_RenderStatus* pRenderStatus) {
48 bool ret = m_pCache ? m_pCache->Continue(pPause, pRenderStatus)
49 : m_pImageObject->GetImage()->Continue(pPause);
50 if (!ret)
51 HandleFailure();
52 return ret;
53 }
54
HandleFailure()55 void CPDF_ImageLoader::HandleFailure() {
56 if (m_pCache) {
57 CPDF_ImageCacheEntry* entry = m_pCache->GetCurImageCacheEntry();
58 m_bCached = true;
59 m_pBitmap = entry->DetachBitmap();
60 m_pMask = entry->DetachMask();
61 m_MatteColor = entry->m_MatteColor;
62 return;
63 }
64 RetainPtr<CPDF_Image> pImage = m_pImageObject->GetImage();
65 m_bCached = false;
66 m_pBitmap = pImage->DetachBitmap();
67 m_pMask = pImage->DetachMask();
68 m_MatteColor = pImage->m_MatteColor;
69 }
70