• 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 #ifndef CORE_FPDFAPI_RENDER_CPDF_IMAGERENDERER_H_
8 #define CORE_FPDFAPI_RENDER_CPDF_IMAGERENDERER_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/fx_coordinates.h"
13 #include "core/fxcrt/retain_ptr.h"
14 #include "core/fxcrt/unowned_ptr.h"
15 #include "core/fxge/dib/cfx_imagerenderer.h"
16 #include "core/fxge/dib/fx_dib.h"
17 #include "third_party/abseil-cpp/absl/types/optional.h"
18 
19 class CFX_DIBBase;
20 class CFX_DefaultRenderDevice;
21 class CFX_ImageTransformer;
22 class CPDF_ImageLoader;
23 class CPDF_ImageObject;
24 class CPDF_Pattern;
25 class CPDF_RenderOptions;
26 class CPDF_RenderStatus;
27 
28 class CPDF_ImageRenderer {
29  public:
30   explicit CPDF_ImageRenderer(CPDF_RenderStatus* pStatus);
31   ~CPDF_ImageRenderer();
32 
33   bool Start(CPDF_ImageObject* pImageObject,
34              const CFX_Matrix& mtObj2Device,
35              bool bStdCS,
36              BlendMode blendType);
37 
38   bool Start(RetainPtr<CFX_DIBBase> pDIBBase,
39              FX_ARGB bitmap_argb,
40              const CFX_Matrix& mtImage2Device,
41              const FXDIB_ResampleOptions& options,
42              bool bStdCS);
43 
44   bool Continue(PauseIndicatorIface* pPause);
GetResult()45   bool GetResult() const { return m_Result; }
46 
47  private:
48   enum class Mode {
49     kNone = 0,
50     kDefault,
51     kBlend,
52     kTransform,
53   };
54 
55   bool StartBitmapAlpha();
56   bool StartDIBBase();
57   bool StartRenderDIBBase();
58   bool StartLoadDIBBase();
59   bool ContinueDefault(PauseIndicatorIface* pPause);
60   bool ContinueBlend(PauseIndicatorIface* pPause);
61   bool ContinueTransform(PauseIndicatorIface* pPause);
62   bool DrawMaskedImage();
63   bool DrawPatternImage();
64   bool NotDrawing() const;
65   FX_RECT GetDrawRect() const;
66   CFX_Matrix GetDrawMatrix(const FX_RECT& rect) const;
67   void CalculateDrawImage(CFX_DefaultRenderDevice* pBitmapDevice1,
68                           CFX_DefaultRenderDevice* pBitmapDevice2,
69                           RetainPtr<CFX_DIBBase> pDIBBase,
70                           const CFX_Matrix& mtNewMatrix,
71                           const FX_RECT& rect) const;
72   const CPDF_RenderOptions& GetRenderOptions() const;
73   void HandleFilters();
74   absl::optional<FX_RECT> GetUnitRect() const;
75   bool GetDimensionsFromUnitRect(const FX_RECT& rect,
76                                  int* left,
77                                  int* top,
78                                  int* width,
79                                  int* height) const;
80 
81   UnownedPtr<CPDF_RenderStatus> const m_pRenderStatus;
82   UnownedPtr<CPDF_ImageObject> m_pImageObject;
83   RetainPtr<CPDF_Pattern> m_pPattern;
84   RetainPtr<CFX_DIBBase> m_pDIBBase;
85   CFX_Matrix m_mtObj2Device;
86   CFX_Matrix m_ImageMatrix;
87   std::unique_ptr<CPDF_ImageLoader> const m_pLoader;
88   std::unique_ptr<CFX_ImageTransformer> m_pTransformer;
89   std::unique_ptr<CFX_ImageRenderer> m_DeviceHandle;
90   Mode m_Mode = Mode::kNone;
91   int m_BitmapAlpha = 0;
92   BlendMode m_BlendType = BlendMode::kNormal;
93   FX_ARGB m_FillArgb = 0;
94   FXDIB_ResampleOptions m_ResampleOptions;
95   bool m_bPatternColor = false;
96   bool m_bStdCS = false;
97   bool m_Result = true;
98 };
99 
100 #endif  // CORE_FPDFAPI_RENDER_CPDF_IMAGERENDERER_H_
101