• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_FXGE_DIB_CFX_DIBITMAP_H_
8 #define CORE_FXGE_DIB_CFX_DIBITMAP_H_
9 
10 #include "core/fxcrt/fx_coordinates.h"
11 #include "core/fxcrt/maybe_owned.h"
12 #include "core/fxcrt/retain_ptr.h"
13 #include "core/fxge/dib/cfx_dibsource.h"
14 #include "third_party/base/stl_util.h"
15 
16 class CFX_DIBitmap : public CFX_DIBSource {
17  public:
18   template <typename T, typename... Args>
19   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
20 
21   ~CFX_DIBitmap() override;
22 
23   bool Create(int width,
24               int height,
25               FXDIB_Format format,
26               uint8_t* pBuffer = nullptr,
27               uint32_t pitch = 0);
28 
29   bool Copy(const RetainPtr<CFX_DIBSource>& pSrc);
30 
31   // CFX_DIBSource
32   uint8_t* GetBuffer() const override;
33   const uint8_t* GetScanline(int line) const override;
34   void DownSampleScanline(int line,
35                           uint8_t* dest_scan,
36                           int dest_bpp,
37                           int dest_width,
38                           bool bFlipX,
39                           int clip_left,
40                           int clip_width) const override;
41 
42   void TakeOver(RetainPtr<CFX_DIBitmap>&& pSrcBitmap);
43   bool ConvertFormat(FXDIB_Format format);
44   void Clear(uint32_t color);
45 
46   uint32_t GetPixel(int x, int y) const;
47   void SetPixel(int x, int y, uint32_t color);
48 
49   bool LoadChannel(FXDIB_Channel destChannel,
50                    const RetainPtr<CFX_DIBSource>& pSrcBitmap,
51                    FXDIB_Channel srcChannel);
52   bool LoadChannel(FXDIB_Channel destChannel, int value);
53 
54   bool MultiplyAlpha(int alpha);
55   bool MultiplyAlpha(const RetainPtr<CFX_DIBSource>& pAlphaMask);
56 
57   bool TransferBitmap(int dest_left,
58                       int dest_top,
59                       int width,
60                       int height,
61                       const RetainPtr<CFX_DIBSource>& pSrcBitmap,
62                       int src_left,
63                       int src_top);
64 
65   bool CompositeBitmap(int dest_left,
66                        int dest_top,
67                        int width,
68                        int height,
69                        const RetainPtr<CFX_DIBSource>& pSrcBitmap,
70                        int src_left,
71                        int src_top,
72                        int blend_type = FXDIB_BLEND_NORMAL,
73                        const CFX_ClipRgn* pClipRgn = nullptr,
74                        bool bRgbByteOrder = false);
75 
76   bool CompositeMask(int dest_left,
77                      int dest_top,
78                      int width,
79                      int height,
80                      const RetainPtr<CFX_DIBSource>& pMask,
81                      uint32_t color,
82                      int src_left,
83                      int src_top,
84                      int blend_type = FXDIB_BLEND_NORMAL,
85                      const CFX_ClipRgn* pClipRgn = nullptr,
86                      bool bRgbByteOrder = false,
87                      int alpha_flag = 0);
88 
89   bool CompositeRect(int dest_left,
90                      int dest_top,
91                      int width,
92                      int height,
93                      uint32_t color,
94                      int alpha_flag);
95 
96   bool ConvertColorScale(uint32_t forecolor, uint32_t backcolor);
97 
98   static bool CalculatePitchAndSize(int height,
99                                     int width,
100                                     FXDIB_Format format,
101                                     uint32_t* pitch,
102                                     uint32_t* size);
103 
104 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_
105   void PreMultiply();
106 #endif
107 #if defined _SKIA_SUPPORT_PATHS_
108   void UnPreMultiply();
109 #endif
110 
111  protected:
112   CFX_DIBitmap();
113   CFX_DIBitmap(const CFX_DIBitmap& src);
114 
115 #if defined _SKIA_SUPPORT_PATHS_
116   enum class Format { kCleared, kPreMultiplied, kUnPreMultiplied };
117 #endif
118 
119   MaybeOwned<uint8_t, FxFreeDeleter> m_pBuffer;
120 #if defined _SKIA_SUPPORT_PATHS_
121   Format m_nFormat;
122 #endif
123 
124  private:
125   void ConvertRGBColorScale(uint32_t forecolor, uint32_t backcolor);
126   void ConvertCMYKColorScale(uint32_t forecolor, uint32_t backcolor);
127 };
128 
129 #endif  // CORE_FXGE_DIB_CFX_DIBITMAP_H_
130