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 #include <optional> 12 13 #include "build/build_config.h" 14 #include "core/fxcrt/fx_coordinates.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 #include "core/fxge/dib/fx_dib.h" 18 19 class CFX_AggImageRenderer; 20 class CFX_DIBBase; 21 class CFX_DIBitmap; 22 class CFX_DefaultRenderDevice; 23 class CPDF_ImageLoader; 24 class CPDF_ImageObject; 25 class CPDF_Pattern; 26 class CPDF_RenderOptions; 27 class CPDF_RenderStatus; 28 class PauseIndicatorIface; 29 30 #if BUILDFLAG(IS_WIN) 31 class CFX_ImageTransformer; 32 #endif 33 34 class CPDF_ImageRenderer { 35 public: 36 explicit CPDF_ImageRenderer(CPDF_RenderStatus* pStatus); 37 ~CPDF_ImageRenderer(); 38 39 bool Start(CPDF_ImageObject* pImageObject, 40 const CFX_Matrix& mtObj2Device, 41 bool bStdCS); 42 43 bool Start(RetainPtr<CFX_DIBBase> pDIBBase, 44 FX_ARGB bitmap_argb, 45 const CFX_Matrix& mtImage2Device, 46 const FXDIB_ResampleOptions& options, 47 bool bStdCS); 48 49 bool Continue(PauseIndicatorIface* pPause); GetResult()50 bool GetResult() const { return m_Result; } 51 52 private: 53 enum class Mode { 54 kNone = 0, 55 kDefault, 56 kBlend, // AGG-specific 57 #if BUILDFLAG(IS_WIN) 58 kTransform, 59 #endif 60 }; 61 62 bool StartBitmapAlpha(); 63 bool StartDIBBase(); 64 bool StartRenderDIBBase(); 65 bool StartLoadDIBBase(); 66 bool ContinueDefault(PauseIndicatorIface* pPause); 67 bool ContinueBlend(PauseIndicatorIface* pPause); 68 bool DrawMaskedImage(); 69 bool DrawPatternImage(); 70 #if BUILDFLAG(IS_WIN) 71 bool StartDIBBaseFallback(); 72 bool ContinueTransform(PauseIndicatorIface* pPause); 73 bool IsPrinting() const; 74 void HandleFilters(); 75 #endif 76 FX_RECT GetDrawRect() const; 77 CFX_Matrix GetDrawMatrix(const FX_RECT& rect) const; 78 // Returns the mask, or nullptr if the mask could not be created. 79 RetainPtr<const CFX_DIBitmap> CalculateDrawImage( 80 CFX_DefaultRenderDevice& bitmap_device, 81 RetainPtr<CFX_DIBBase> pDIBBase, 82 const CFX_Matrix& mtNewMatrix, 83 const FX_RECT& rect) const; 84 const CPDF_RenderOptions& GetRenderOptions() const; 85 std::optional<FX_RECT> GetUnitRect() const; 86 bool GetDimensionsFromUnitRect(const FX_RECT& rect, 87 int* left, 88 int* top, 89 int* width, 90 int* height) const; 91 92 UnownedPtr<CPDF_RenderStatus> const m_pRenderStatus; 93 UnownedPtr<CPDF_ImageObject> m_pImageObject; 94 RetainPtr<CPDF_Pattern> m_pPattern; 95 RetainPtr<CFX_DIBBase> m_pDIBBase; 96 CFX_Matrix m_mtObj2Device; 97 CFX_Matrix m_ImageMatrix; 98 std::unique_ptr<CPDF_ImageLoader> const m_pLoader; 99 #if BUILDFLAG(IS_WIN) 100 std::unique_ptr<CFX_ImageTransformer> m_pTransformer; 101 #endif 102 std::unique_ptr<CFX_AggImageRenderer> m_DeviceHandle; 103 Mode m_Mode = Mode::kNone; 104 float m_Alpha = 0.0f; 105 BlendMode m_BlendType = BlendMode::kNormal; 106 FX_ARGB m_FillArgb = 0; 107 FXDIB_ResampleOptions m_ResampleOptions; 108 bool m_bPatternColor = false; 109 bool m_bStdCS = false; 110 bool m_Result = true; 111 }; 112 113 #endif // CORE_FPDFAPI_RENDER_CPDF_IMAGERENDERER_H_ 114