• 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_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/fxge/dib/cfx_bitmapstorer.h"
15 
16 class CFX_DIBBase;
17 class CFX_DIBitmap;
18 class CFX_ImageStretcher;
19 class PauseIndicatorIface;
20 
21 class CFX_ImageTransformer {
22  public:
23   struct BilinearData {
24     int res_x;
25     int res_y;
26     int src_col_l;
27     int src_row_l;
28     int src_col_r;
29     int src_row_r;
30     int row_offset_l;
31     int row_offset_r;
32   };
33 
34   struct BicubicData {
35     int res_x;
36     int res_y;
37     int src_col_l;
38     int src_row_l;
39     int src_col_r;
40     int src_row_r;
41     int pos_pixel[8];
42     int u_w[4];
43     int v_w[4];
44   };
45 
46   struct DownSampleData {
47     int src_col;
48     int src_row;
49   };
50 
51   struct CalcData {
52     CFX_DIBitmap* bitmap;
53     const CFX_Matrix& matrix;
54     const uint8_t* buf;
55     uint32_t pitch;
56   };
57 
58   CFX_ImageTransformer(const RetainPtr<CFX_DIBBase>& pSrc,
59                        const CFX_Matrix& matrix,
60                        const FXDIB_ResampleOptions& options,
61                        const FX_RECT* pClip);
62   ~CFX_ImageTransformer();
63 
64   bool Continue(PauseIndicatorIface* pPause);
65 
result()66   const FX_RECT& result() const { return m_result; }
67   RetainPtr<CFX_DIBitmap> DetachBitmap();
68 
69  private:
70   enum StretchType {
71     kNone,
72     kNormal,
73     kRotate,
74     kOther,
75   };
76 
77   void ContinueRotate(PauseIndicatorIface* pPause);
78   void ContinueOther(PauseIndicatorIface* pPause);
79 
80   void CalcMask(const CalcData& cdata);
81   void CalcAlpha(const CalcData& cdata);
82   void CalcMono(const CalcData& cdata, FXDIB_Format format);
83   void CalcColor(const CalcData& cdata, FXDIB_Format format, int Bpp);
84 
85   bool IsBilinear() const;
86   bool IsBiCubic() const;
87 
88   RetainPtr<CFX_DIBBase> const m_pSrc;
89   const CFX_Matrix m_matrix;
90   FX_RECT m_StretchClip;
91   FX_RECT m_result;
92   CFX_Matrix m_dest2stretch;
93   std::unique_ptr<CFX_ImageStretcher> m_Stretcher;
94   CFX_BitmapStorer m_Storer;
95   const FXDIB_ResampleOptions m_ResampleOptions;
96   StretchType m_type = kNone;
97 };
98 
99 #endif  // CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_
100