1 // Copyright 2017 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_FXGE_DIB_CFX_SCANLINECOMPOSITOR_H_ 8 #define CORE_FXGE_DIB_CFX_SCANLINECOMPOSITOR_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/fx_memory_wrappers.h" 13 #include "core/fxge/dib/fx_dib.h" 14 #include "third_party/base/containers/span.h" 15 16 class CFX_ScanlineCompositor { 17 public: 18 CFX_ScanlineCompositor(); 19 ~CFX_ScanlineCompositor(); 20 21 bool Init(FXDIB_Format dest_format, 22 FXDIB_Format src_format, 23 pdfium::span<const uint32_t> src_palette, 24 uint32_t mask_color, 25 BlendMode blend_type, 26 bool bClip, 27 bool bRgbByteOrder); 28 29 void CompositeRgbBitmapLine(pdfium::span<uint8_t> dest_scan, 30 pdfium::span<const uint8_t> src_scan, 31 int width, 32 pdfium::span<const uint8_t> clip_scan) const; 33 34 void CompositePalBitmapLine(pdfium::span<uint8_t> dest_scan, 35 pdfium::span<const uint8_t> src_scan, 36 int src_left, 37 int width, 38 pdfium::span<const uint8_t> clip_scan) const; 39 40 void CompositeByteMaskLine(pdfium::span<uint8_t> dest_scan, 41 pdfium::span<const uint8_t> src_scan, 42 int width, 43 pdfium::span<const uint8_t> clip_scan) const; 44 45 void CompositeBitMaskLine(pdfium::span<uint8_t> dest_scan, 46 pdfium::span<const uint8_t> src_scan, 47 int src_left, 48 int width, 49 pdfium::span<const uint8_t> clip_scan) const; 50 51 private: 52 class Palette { 53 public: 54 Palette(); 55 ~Palette(); 56 57 void Reset(); 58 pdfium::span<uint8_t> Make8BitPalette(size_t nElements); 59 pdfium::span<uint32_t> Make32BitPalette(size_t nElements); 60 61 // Hard CHECK() if mismatch between created and requested widths. 62 pdfium::span<const uint8_t> Get8BitPalette() const; 63 pdfium::span<const uint32_t> Get32BitPalette() const; 64 65 private: 66 // If 0, then no |m_pData|. 67 // If 1, then |m_pData| is really uint8_t* instead. 68 // If 4, then |m_pData| is uint32_t* as expected. 69 size_t m_Width = 0; 70 size_t m_nElements = 0; 71 std::unique_ptr<uint32_t, FxFreeDeleter> m_pData; 72 }; 73 74 void InitSourcePalette(pdfium::span<const uint32_t> src_palette); 75 76 void InitSourceMask(uint32_t mask_color); 77 78 FXDIB_Format m_SrcFormat; 79 FXDIB_Format m_DestFormat; 80 Palette m_SrcPalette; 81 int m_MaskAlpha; 82 int m_MaskRed; 83 int m_MaskGreen; 84 int m_MaskBlue; 85 BlendMode m_BlendType = BlendMode::kNormal; 86 bool m_bRgbByteOrder = false; 87 bool m_bClip = false; 88 }; 89 90 #endif // CORE_FXGE_DIB_CFX_SCANLINECOMPOSITOR_H_ 91