• 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/fxcrt/unowned_ptr.h"
15 #include "core/fxge/dib/cfx_bitmapstorer.h"
16 #include "core/fxge/dib/cfx_dibitmap.h"
17 #include "core/fxge/dib/cfx_dibsource.h"
18 
19 class CFX_ImageStretcher;
20 
21 class CFX_ImageTransformer {
22  public:
23   CFX_ImageTransformer(const RetainPtr<CFX_DIBSource>& pSrc,
24                        const CFX_Matrix* pMatrix,
25                        int flags,
26                        const FX_RECT* pClip);
27   ~CFX_ImageTransformer();
28 
29   bool Continue(IFX_PauseIndicator* pPause);
30 
result()31   const FX_RECT& result() const { return m_result; }
32   RetainPtr<CFX_DIBitmap> DetachBitmap();
33 
34  private:
35   struct BilinearData {
36     int res_x;
37     int res_y;
38     int src_col_l;
39     int src_row_l;
40     int src_col_r;
41     int src_row_r;
42     int row_offset_l;
43     int row_offset_r;
44   };
45 
46   struct BicubicData {
47     int res_x;
48     int res_y;
49     int src_col_l;
50     int src_row_l;
51     int src_col_r;
52     int src_row_r;
53     int pos_pixel[8];
54     int u_w[4];
55     int v_w[4];
56   };
57 
58   struct DownSampleData {
59     int src_col;
60     int src_row;
61   };
62 
63   struct CalcData {
64     const CFX_DIBitmap* bitmap;
65     const CFX_Matrix& matrix;
66     const uint8_t* buf;
67     uint32_t pitch;
68   };
69 
70   void CalcMask(const CalcData& cdata);
71   void CalcAlpha(const CalcData& cdata);
72   void CalcMono(const CalcData& cdata, FXDIB_Format format);
73   void CalcColor(const CalcData& cdata, FXDIB_Format format, int Bpp);
74 
IsBilinear()75   bool IsBilinear() const {
76     return !(m_Flags & FXDIB_DOWNSAMPLE) && !IsBiCubic();
77   }
IsBiCubic()78   bool IsBiCubic() const { return !!(m_Flags & FXDIB_BICUBIC_INTERPOL); }
79 
stretch_width()80   int stretch_width() const { return m_StretchClip.Width(); }
stretch_height()81   int stretch_height() const { return m_StretchClip.Height(); }
82 
InStretchBounds(int col,int row)83   bool InStretchBounds(int col, int row) const {
84     return col >= 0 && col <= stretch_width() && row >= 0 &&
85            row <= stretch_height();
86   }
87 
88   void AdjustCoords(int* col, int* row) const;
89 
90   void DoBilinearLoop(const CalcData& cdata,
91                       int increment,
92                       std::function<void(const BilinearData&, uint8_t*)> func);
93   void DoBicubicLoop(const CalcData& cdata,
94                      int increment,
95                      std::function<void(const BicubicData&, uint8_t*)> func);
96   void DoDownSampleLoop(
97       const CalcData& cdata,
98       int increment,
99       std::function<void(const DownSampleData&, uint8_t*)> func);
100 
101   const RetainPtr<CFX_DIBSource> m_pSrc;
102   UnownedPtr<const CFX_Matrix> const m_pMatrix;
103   const FX_RECT* const m_pClip;
104   FX_RECT m_StretchClip;
105   FX_RECT m_result;
106   CFX_Matrix m_dest2stretch;
107   std::unique_ptr<CFX_ImageStretcher> m_Stretcher;
108   CFX_BitmapStorer m_Storer;
109   const uint32_t m_Flags;
110   int m_Status;
111 };
112 
113 #endif  // CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_
114