• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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/page/cpdf_imageloader.h"
8 
9 #include <utility>
10 
11 #include "core/fpdfapi/page/cpdf_dib.h"
12 #include "core/fpdfapi/page/cpdf_image.h"
13 #include "core/fpdfapi/page/cpdf_imageobject.h"
14 #include "core/fpdfapi/page/cpdf_pageimagecache.h"
15 #include "core/fpdfapi/page/cpdf_transferfunc.h"
16 #include "core/fxcrt/check.h"
17 #include "core/fxge/dib/cfx_dibitmap.h"
18 
19 CPDF_ImageLoader::CPDF_ImageLoader() = default;
20 
21 CPDF_ImageLoader::~CPDF_ImageLoader() = default;
22 
Start(const CPDF_ImageObject * pImage,CPDF_PageImageCache * pPageImageCache,const CPDF_Dictionary * pFormResource,const CPDF_Dictionary * pPageResource,bool bStdCS,CPDF_ColorSpace::Family eFamily,bool bLoadMask,const CFX_Size & max_size_required)23 bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
24                              CPDF_PageImageCache* pPageImageCache,
25                              const CPDF_Dictionary* pFormResource,
26                              const CPDF_Dictionary* pPageResource,
27                              bool bStdCS,
28                              CPDF_ColorSpace::Family eFamily,
29                              bool bLoadMask,
30                              const CFX_Size& max_size_required) {
31   m_pCache = pPageImageCache;
32   m_pImageObject = pImage;
33   bool should_continue;
34   if (m_pCache) {
35     should_continue = m_pCache->StartGetCachedBitmap(
36         m_pImageObject->GetImage(), pFormResource, pPageResource, bStdCS,
37         eFamily, bLoadMask, max_size_required);
38   } else {
39     should_continue = m_pImageObject->GetImage()->StartLoadDIBBase(
40         pFormResource, pPageResource, bStdCS, eFamily, bLoadMask,
41         max_size_required);
42   }
43   if (!should_continue) {
44     Finish();
45   }
46   return should_continue;
47 }
48 
Continue(PauseIndicatorIface * pPause)49 bool CPDF_ImageLoader::Continue(PauseIndicatorIface* pPause) {
50   bool should_continue = m_pCache
51                              ? m_pCache->Continue(pPause)
52                              : m_pImageObject->GetImage()->Continue(pPause);
53   if (!should_continue) {
54     Finish();
55   }
56   return should_continue;
57 }
58 
TranslateImage(RetainPtr<CPDF_TransferFunc> pTransferFunc)59 RetainPtr<CFX_DIBBase> CPDF_ImageLoader::TranslateImage(
60     RetainPtr<CPDF_TransferFunc> pTransferFunc) {
61   DCHECK(pTransferFunc);
62   DCHECK(!pTransferFunc->GetIdentity());
63   m_pBitmap = pTransferFunc->TranslateImage(std::move(m_pBitmap));
64   if (m_bCached && m_pMask)
65     m_pMask = m_pMask->Realize();
66   m_bCached = false;
67   return m_pBitmap;
68 }
69 
Finish()70 void CPDF_ImageLoader::Finish() {
71   if (m_pCache) {
72     m_bCached = true;
73     m_pBitmap = m_pCache->DetachCurBitmap();
74     m_pMask = m_pCache->DetachCurMask();
75     m_MatteColor = m_pCache->GetCurMatteColor();
76     return;
77   }
78   RetainPtr<CPDF_Image> pImage = m_pImageObject->GetImage();
79   m_bCached = false;
80   m_pBitmap = pImage->DetachBitmap();
81   m_pMask = pImage->DetachMask();
82   m_MatteColor = pImage->GetMatteColor();
83 }
84