summaryrefslogtreecommitdiff
path: root/core/fxge/dib/cfx_imagetransformer.h
blob: dcda687d42201baec9f56406071e9c64afa0e8ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_
#define CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_

#include <memory>

#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxge/dib/cfx_bitmapstorer.h"
#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/dib/cfx_dibsource.h"

class CFX_ImageStretcher;

class CFX_ImageTransformer {
 public:
  CFX_ImageTransformer(const RetainPtr<CFX_DIBSource>& pSrc,
                       const CFX_Matrix* pMatrix,
                       int flags,
                       const FX_RECT* pClip);
  ~CFX_ImageTransformer();

  bool Continue(IFX_PauseIndicator* pPause);

  const FX_RECT& result() const { return m_result; }
  RetainPtr<CFX_DIBitmap> DetachBitmap();

 private:
  bool IsBilinear() const {
    return !(m_Flags & FXDIB_DOWNSAMPLE) && !IsBiCubic();
  }
  bool IsBiCubic() const { return !!(m_Flags & FXDIB_BICUBIC_INTERPOL); }

  int stretch_width() const { return m_StretchClip.Width(); }
  int stretch_height() const { return m_StretchClip.Height(); }

  bool InStretchBounds(int col, int row) const {
    return col >= 0 && col <= stretch_width() && row >= 0 &&
           row <= stretch_height();
  }

  void AdjustCoords(int* col, int* row) const;

  const RetainPtr<CFX_DIBSource> m_pSrc;
  UnownedPtr<const CFX_Matrix> const m_pMatrix;
  const FX_RECT* const m_pClip;
  FX_RECT m_StretchClip;
  FX_RECT m_result;
  CFX_Matrix m_dest2stretch;
  std::unique_ptr<CFX_ImageStretcher> m_Stretcher;
  CFX_BitmapStorer m_Storer;
  const uint32_t m_Flags;
  int m_Status;
};

#endif  // CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_