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 17 class CFX_DIBBase; 18 class PauseIndicatorIface; 19 class ScanlineComposerIface; 20 21 class CStretchEngine { 22 public: 23 CStretchEngine(ScanlineComposerIface* pDestBitmap, 24 FXDIB_Format dest_format, 25 int dest_width, 26 int dest_height, 27 const FX_RECT& clip_rect, 28 const RetainPtr<CFX_DIBBase>& pSrcBitmap, 29 const FXDIB_ResampleOptions& options); 30 ~CStretchEngine(); 31 32 bool Continue(PauseIndicatorIface* pPause); 33 34 bool StartStretchHorz(); 35 bool ContinueStretchHorz(PauseIndicatorIface* pPause); 36 void StretchVert(); 37 38 class CWeightTable { 39 public: 40 CWeightTable(); 41 ~CWeightTable(); 42 43 bool Calc(int dest_len, 44 int dest_min, 45 int dest_max, 46 int src_len, 47 int src_min, 48 int src_max, 49 const FXDIB_ResampleOptions& options); 50 51 const PixelWeight* GetPixelWeight(int pixel) const; GetPixelWeight(int pixel)52 PixelWeight* GetPixelWeight(int pixel) { 53 return const_cast<PixelWeight*>( 54 static_cast<const CWeightTable*>(this)->GetPixelWeight(pixel)); 55 } 56 57 int* GetValueFromPixelWeight(PixelWeight* pWeight, int index) const; 58 size_t GetPixelWeightSize() const; 59 60 private: 61 int m_DestMin = 0; 62 int m_ItemSize = 0; 63 size_t m_dwWeightTablesSize = 0; 64 std::vector<uint8_t> m_WeightTables; 65 }; 66 67 enum class State : uint8_t { kInitial, kHorizontal, kVertical }; 68 69 enum class TransformMethod : uint8_t { 70 k1BppTo8Bpp, 71 k1BppToManyBpp, 72 k8BppTo8Bpp, 73 k8BppTo8BppWithAlpha, 74 k8BppToManyBpp, 75 k8BppToManyBppWithAlpha, 76 kManyBpptoManyBpp, 77 kManyBpptoManyBppWithAlpha 78 }; 79 80 const FXDIB_Format m_DestFormat; 81 const int m_DestBpp; 82 const int m_SrcBpp; 83 const int m_bHasAlpha; 84 RetainPtr<CFX_DIBBase> const m_pSource; 85 const uint32_t* m_pSrcPalette; 86 const int m_SrcWidth; 87 const int m_SrcHeight; 88 UnownedPtr<ScanlineComposerIface> const m_pDestBitmap; 89 const int m_DestWidth; 90 const int m_DestHeight; 91 const FX_RECT m_DestClip; 92 std::vector<uint8_t> m_DestScanline; 93 std::vector<uint8_t> m_DestMaskScanline; 94 std::vector<uint8_t> m_InterBuf; 95 std::vector<uint8_t> m_ExtraAlphaBuf; 96 FX_RECT m_SrcClip; 97 int m_InterPitch; 98 int m_ExtraMaskPitch; 99 FXDIB_ResampleOptions m_ResampleOptions; 100 TransformMethod m_TransMethod; 101 State m_State = State::kInitial; 102 int m_CurRow; 103 CWeightTable m_WeightTable; 104 }; 105 106 #endif // CORE_FXGE_DIB_CSTRETCHENGINE_H_ 107