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