• 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_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 #include "core/fxcrt/fx_basic.h"
16 
CPDF_ImageLoader()17 CPDF_ImageLoader::CPDF_ImageLoader()
18     : m_pBitmap(nullptr),
19       m_pMask(nullptr),
20       m_MatteColor(0),
21       m_bCached(false),
22       m_nDownsampleWidth(0),
23       m_nDownsampleHeight(0),
24       m_pCache(nullptr),
25       m_pImage(nullptr) {}
26 
~CPDF_ImageLoader()27 CPDF_ImageLoader::~CPDF_ImageLoader() {
28   if (!m_bCached) {
29     delete m_pBitmap;
30     delete m_pMask;
31   }
32 }
33 
Start(const CPDF_ImageObject * pImage,CPDF_PageRenderCache * pCache,bool bStdCS,uint32_t GroupFamily,bool bLoadMask,CPDF_RenderStatus * pRenderStatus,int32_t nDownsampleWidth,int32_t nDownsampleHeight)34 bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
35                              CPDF_PageRenderCache* pCache,
36                              bool bStdCS,
37                              uint32_t GroupFamily,
38                              bool bLoadMask,
39                              CPDF_RenderStatus* pRenderStatus,
40                              int32_t nDownsampleWidth,
41                              int32_t nDownsampleHeight) {
42   m_nDownsampleWidth = nDownsampleWidth;
43   m_nDownsampleHeight = nDownsampleHeight;
44   m_pCache = pCache;
45   m_pImage = const_cast<CPDF_ImageObject*>(pImage);
46   bool ret;
47   if (pCache) {
48     ret = pCache->StartGetCachedBitmap(
49         m_pImage->GetImage()->GetStream(), bStdCS, GroupFamily, bLoadMask,
50         pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight);
51   } else {
52     ret = m_pImage->GetImage()->StartLoadDIBSource(
53         pRenderStatus->m_pFormResource, pRenderStatus->m_pPageResource, bStdCS,
54         GroupFamily, bLoadMask);
55   }
56   if (!ret)
57     HandleFailure();
58   return ret;
59 }
60 
Continue(IFX_Pause * pPause)61 bool CPDF_ImageLoader::Continue(IFX_Pause* pPause) {
62   bool ret = m_pCache ? m_pCache->Continue(pPause)
63                       : m_pImage->GetImage()->Continue(pPause);
64   if (!ret)
65     HandleFailure();
66   return ret;
67 }
68 
HandleFailure()69 void CPDF_ImageLoader::HandleFailure() {
70   if (m_pCache) {
71     CPDF_ImageCacheEntry* entry = m_pCache->GetCurImageCacheEntry();
72     m_bCached = true;
73     m_pBitmap = entry->DetachBitmap();
74     m_pMask = entry->DetachMask();
75     m_MatteColor = entry->m_MatteColor;
76     return;
77   }
78   CPDF_Image* pImage = m_pImage->GetImage();
79   m_bCached = false;
80   m_pBitmap = pImage->DetachBitmap();
81   m_pMask = pImage->DetachMask();
82   m_MatteColor = pImage->m_MatteColor;
83 }
84