xref: /aosp_15_r20/external/pdfium/core/fxge/dib/cfx_imagetransformer.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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_IMAGETRANSFORMER_H_
8 #define CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/fx_coordinates.h"
13 #include "core/fxcrt/retain_ptr.h"
14 #include "core/fxcrt/unowned_ptr_exclusion.h"
15 #include "core/fxge/dib/cfx_bitmapstorer.h"
16 
17 class CFX_DIBBase;
18 class CFX_DIBitmap;
19 class CFX_ImageStretcher;
20 class PauseIndicatorIface;
21 
22 class CFX_ImageTransformer {
23  public:
24   struct BilinearData {
25     int res_x;
26     int res_y;
27     int src_col_l;
28     int src_row_l;
29     int src_col_r;
30     int src_row_r;
31     int row_offset_l;
32     int row_offset_r;
33   };
34 
35   struct CalcData {
36     UNOWNED_PTR_EXCLUSION CFX_DIBitmap* bitmap;  // POD struct.
37     const CFX_Matrix& matrix;
38     const uint8_t* buf;
39     uint32_t pitch;
40   };
41 
42   CFX_ImageTransformer(const RetainPtr<const CFX_DIBBase>& pSrc,
43                        const CFX_Matrix& matrix,
44                        const FXDIB_ResampleOptions& options,
45                        const FX_RECT* pClip);
46   ~CFX_ImageTransformer();
47 
48   bool Continue(PauseIndicatorIface* pPause);
49 
result()50   const FX_RECT& result() const { return m_result; }
51   RetainPtr<CFX_DIBitmap> DetachBitmap();
52 
53  private:
54   enum class StretchType {
55     kNone,
56     kNormal,
57     kRotate,
58     kOther,
59   };
60 
61   void ContinueRotate(PauseIndicatorIface* pPause);
62   void ContinueOther(PauseIndicatorIface* pPause);
63 
64   void CalcAlpha(const CalcData& calc_data);
65   void CalcMono(const CalcData& calc_data);
66   void CalcColor(const CalcData& calc_data, FXDIB_Format format, int Bpp);
67 
68   RetainPtr<const CFX_DIBBase> const m_pSrc;
69   const CFX_Matrix m_matrix;
70   FX_RECT m_StretchClip;
71   FX_RECT m_result;
72   CFX_Matrix m_dest2stretch;
73   std::unique_ptr<CFX_ImageStretcher> m_Stretcher;
74   CFX_BitmapStorer m_Storer;
75   const FXDIB_ResampleOptions m_ResampleOptions;
76   StretchType m_type = StretchType::kNone;
77 };
78 
79 #endif  // CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_
80