• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_dib.h"
10 #include "core/fpdfapi/page/cpdf_image.h"
11 #include "core/fpdfapi/page/cpdf_imageobject.h"
12 #include "core/fpdfapi/page/cpdf_transferfunc.h"
13 #include "core/fpdfapi/render/cpdf_imagecacheentry.h"
14 #include "core/fpdfapi/render/cpdf_pagerendercache.h"
15 #include "core/fpdfapi/render/cpdf_renderstatus.h"
16 #include "core/fxge/dib/cfx_dibitmap.h"
17 
18 CPDF_ImageLoader::CPDF_ImageLoader() = default;
19 
20 CPDF_ImageLoader::~CPDF_ImageLoader() = default;
21 
Start(CPDF_ImageObject * pImage,CPDF_PageRenderCache * pCache,bool bStdCS,uint32_t GroupFamily,bool bLoadMask,CPDF_RenderStatus * pRenderStatus)22 bool CPDF_ImageLoader::Start(CPDF_ImageObject* pImage,
23                              CPDF_PageRenderCache* pCache,
24                              bool bStdCS,
25                              uint32_t GroupFamily,
26                              bool bLoadMask,
27                              CPDF_RenderStatus* pRenderStatus) {
28   m_pCache = pCache;
29   m_pImageObject = pImage;
30   bool ret;
31   if (pCache) {
32     ret = pCache->StartGetCachedBitmap(m_pImageObject->GetImage(), bStdCS,
33                                        GroupFamily, bLoadMask, pRenderStatus);
34   } else {
35     ret = m_pImageObject->GetImage()->StartLoadDIBBase(
36         pRenderStatus->GetFormResource(), pRenderStatus->GetPageResource(),
37         bStdCS, GroupFamily, bLoadMask);
38   }
39   if (!ret)
40     HandleFailure();
41   return ret;
42 }
43 
Continue(PauseIndicatorIface * pPause,CPDF_RenderStatus * pRenderStatus)44 bool CPDF_ImageLoader::Continue(PauseIndicatorIface* pPause,
45                                 CPDF_RenderStatus* pRenderStatus) {
46   bool ret = m_pCache ? m_pCache->Continue(pPause, pRenderStatus)
47                       : m_pImageObject->GetImage()->Continue(pPause);
48   if (!ret)
49     HandleFailure();
50   return ret;
51 }
52 
TranslateImage(const RetainPtr<CPDF_TransferFunc> & pTransferFunc)53 RetainPtr<CFX_DIBBase> CPDF_ImageLoader::TranslateImage(
54     const RetainPtr<CPDF_TransferFunc>& pTransferFunc) {
55   ASSERT(pTransferFunc);
56   ASSERT(!pTransferFunc->GetIdentity());
57 
58   m_pBitmap = pTransferFunc->TranslateImage(m_pBitmap);
59   if (m_bCached && m_pMask)
60     m_pMask = m_pMask->Clone(nullptr);
61   m_bCached = false;
62   return m_pBitmap;
63 }
64 
HandleFailure()65 void CPDF_ImageLoader::HandleFailure() {
66   if (m_pCache) {
67     CPDF_ImageCacheEntry* entry = m_pCache->GetCurImageCacheEntry();
68     m_bCached = true;
69     m_pBitmap = entry->DetachBitmap();
70     m_pMask = entry->DetachMask();
71     m_MatteColor = entry->m_MatteColor;
72     return;
73   }
74   RetainPtr<CPDF_Image> pImage = m_pImageObject->GetImage();
75   m_bCached = false;
76   m_pBitmap = pImage->DetachBitmap();
77   m_pMask = pImage->DetachMask();
78   m_MatteColor = pImage->m_MatteColor;
79 }
80