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_CSTRETCHENGINE_H_
8#define CORE_FXGE_DIB_CSTRETCHENGINE_H_
9
10#include <vector>
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/fx_dib.h"
16
17class IFX_PauseIndicator;
18class IFX_ScanlineComposer;
19
20class CStretchEngine {
21 public:
22  CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
23                 FXDIB_Format dest_format,
24                 int dest_width,
25                 int dest_height,
26                 const FX_RECT& clip_rect,
27                 const RetainPtr<CFX_DIBSource>& pSrcBitmap,
28                 int flags);
29  ~CStretchEngine();
30
31  bool Continue(IFX_PauseIndicator* pPause);
32
33  bool StartStretchHorz();
34  bool ContinueStretchHorz(IFX_PauseIndicator* pPause);
35  void StretchVert();
36
37  class CWeightTable {
38   public:
39    CWeightTable();
40    ~CWeightTable();
41
42    bool Calc(int dest_len,
43              int dest_min,
44              int dest_max,
45              int src_len,
46              int src_min,
47              int src_max,
48              int flags);
49    PixelWeight* GetPixelWeight(int pixel) const;
50    int* GetValueFromPixelWeight(PixelWeight* pWeight, int index) const;
51    size_t GetPixelWeightSize() const;
52
53   private:
54    int m_DestMin;
55    int m_ItemSize;
56    std::vector<uint8_t> m_WeightTables;
57    size_t m_dwWeightTablesSize;
58  };
59
60  FXDIB_Format m_DestFormat;
61  int m_DestBpp;
62  int m_SrcBpp;
63  int m_bHasAlpha;
64  UnownedPtr<IFX_ScanlineComposer> m_pDestBitmap;
65  int m_DestWidth;
66  int m_DestHeight;
67  FX_RECT m_DestClip;
68  std::vector<uint8_t> m_DestScanline;
69  std::vector<uint8_t> m_DestMaskScanline;
70  FX_RECT m_SrcClip;
71  RetainPtr<CFX_DIBSource> m_pSource;
72  uint32_t* m_pSrcPalette;
73  int m_SrcWidth;
74  int m_SrcHeight;
75  int m_SrcPitch;
76  int m_InterPitch;
77  int m_ExtraMaskPitch;
78  std::vector<uint8_t> m_InterBuf;
79  std::vector<uint8_t> m_ExtraAlphaBuf;
80  int m_TransMethod;
81  int m_Flags;
82  CWeightTable m_WeightTable;
83  int m_CurRow;
84  int m_State;
85};
86
87#endif  // CORE_FXGE_DIB_CSTRETCHENGINE_H_
88