• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stddef.h>
11 #include <stdint.h>
12 
13 #include <memory>
14 
15 #include "core/fxcrt/fx_memory_wrappers.h"
16 #include "core/fxcrt/span.h"
17 #include "core/fxge/dib/fx_dib.h"
18 
19 class CFX_ScanlineCompositor {
20  public:
21   CFX_ScanlineCompositor();
22   ~CFX_ScanlineCompositor();
23 
24   bool Init(FXDIB_Format dest_format,
25             FXDIB_Format src_format,
26             pdfium::span<const uint32_t> src_palette,
27             uint32_t mask_color,
28             BlendMode blend_type,
29             bool bRgbByteOrder);
30 
31   void CompositeRgbBitmapLine(pdfium::span<uint8_t> dest_scan,
32                               pdfium::span<const uint8_t> src_scan,
33                               int width,
34                               pdfium::span<const uint8_t> clip_scan) const;
35 
36   void CompositePalBitmapLine(pdfium::span<uint8_t> dest_scan,
37                               pdfium::span<const uint8_t> src_scan,
38                               int src_left,
39                               int width,
40                               pdfium::span<const uint8_t> clip_scan) const;
41 
42   void CompositeByteMaskLine(pdfium::span<uint8_t> dest_scan,
43                              pdfium::span<const uint8_t> src_scan,
44                              int width,
45                              pdfium::span<const uint8_t> clip_scan) const;
46 
47   void CompositeBitMaskLine(pdfium::span<uint8_t> dest_scan,
48                             pdfium::span<const uint8_t> src_scan,
49                             int src_left,
50                             int width,
51                             pdfium::span<const uint8_t> clip_scan) const;
52 
53  private:
54   class Palette {
55    public:
56     Palette();
57     ~Palette();
58 
59     void Reset();
60     pdfium::span<uint8_t> Make8BitPalette(size_t nElements);
61     pdfium::span<uint32_t> Make32BitPalette(size_t nElements);
62 
63     // Hard CHECK() if mismatch between created and requested widths.
64     pdfium::span<const uint8_t> Get8BitPalette() const;
65     pdfium::span<const uint32_t> Get32BitPalette() const;
66 
67    private:
68     // If 0, then no |m_pData|.
69     // If 1, then |m_pData| is really uint8_t* instead.
70     // If 4, then |m_pData| is uint32_t* as expected.
71     size_t m_Width = 0;
72     size_t m_nElements = 0;
73 
74     // TODO(tsepez): convert to variant of FixedArray.
75     std::unique_ptr<uint32_t, FxFreeDeleter> m_pData;
76   };
77 
78   void InitSourcePalette(pdfium::span<const uint32_t> src_palette);
79 
80   void InitSourceMask(uint32_t mask_color);
81 
82   void CompositeRgbBitmapLineSrcBgrx(
83       pdfium::span<uint8_t> dest_scan,
84       pdfium::span<const uint8_t> src_scan,
85       int width,
86       pdfium::span<const uint8_t> clip_scan) const;
87   void CompositeRgbBitmapLineSrcBgra(
88       pdfium::span<uint8_t> dest_scan,
89       pdfium::span<const uint8_t> src_scan,
90       int width,
91       pdfium::span<const uint8_t> clip_scan) const;
92 #if defined(PDF_USE_SKIA)
93   void CompositeRgbBitmapLineSrcBgraPremul(pdfium::span<uint8_t> dest_scan,
94                                            pdfium::span<const uint8_t> src_scan,
95                                            int width) const;
96 #endif
97 
98   void CompositePalBitmapLineSrcBpp1(
99       pdfium::span<uint8_t> dest_scan,
100       pdfium::span<const uint8_t> src_scan,
101       int src_left,
102       int width,
103       pdfium::span<const uint8_t> clip_scan) const;
104   void CompositePalBitmapLineSrcBpp8(
105       pdfium::span<uint8_t> dest_scan,
106       pdfium::span<const uint8_t> src_scan,
107       int src_left,
108       int width,
109       pdfium::span<const uint8_t> clip_scan) const;
110 
111   FXDIB_Format m_SrcFormat;
112   FXDIB_Format m_DestFormat;
113   Palette m_SrcPalette;
114   int m_MaskAlpha;
115   int m_MaskRed;
116   int m_MaskGreen;
117   int m_MaskBlue;
118   BlendMode m_BlendType = BlendMode::kNormal;
119   bool m_bRgbByteOrder = false;
120 };
121 
122 #endif  // CORE_FXGE_DIB_CFX_SCANLINECOMPOSITOR_H_
123