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_FPDFAPI_RENDER_CPDF_DIBSOURCE_H_ 8 #define CORE_FPDFAPI_RENDER_CPDF_DIBSOURCE_H_ 9 10 #include <map> 11 #include <memory> 12 #include <vector> 13 14 #include "core/fpdfapi/page/cpdf_clippath.h" 15 #include "core/fpdfapi/page/cpdf_countedobject.h" 16 #include "core/fpdfapi/page/cpdf_graphicstates.h" 17 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 18 #include "core/fpdfapi/render/cpdf_imageloader.h" 19 #include "core/fpdfapi/render/cpdf_rendercontext.h" 20 #include "core/fpdfapi/render/cpdf_renderoptions.h" 21 #include "core/fxcrt/retain_ptr.h" 22 #include "core/fxcrt/unowned_ptr.h" 23 #include "core/fxge/cfx_defaultrenderdevice.h" 24 #include "core/fxge/dib/cfx_dibsource.h" 25 26 class CCodec_Jbig2Context; 27 class CCodec_ScanlineDecoder; 28 class CPDF_Color; 29 class CPDF_Dictionary; 30 class CPDF_Document; 31 class CPDF_Stream; 32 33 typedef struct { 34 float m_DecodeMin; 35 float m_DecodeStep; 36 int m_ColorKeyMin; 37 int m_ColorKeyMax; 38 } DIB_COMP_DATA; 39 40 #define FPDF_HUGE_IMAGE_SIZE 60000000 41 42 class CPDF_DIBSource : public CFX_DIBSource { 43 public: 44 template <typename T, typename... Args> 45 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 46 47 ~CPDF_DIBSource() override; 48 49 bool Load(CPDF_Document* pDoc, const CPDF_Stream* pStream); 50 51 // CFX_DIBSource 52 bool SkipToScanline(int line, IFX_PauseIndicator* pPause) const override; 53 uint8_t* GetBuffer() const override; 54 const uint8_t* GetScanline(int line) const override; 55 void DownSampleScanline(int line, 56 uint8_t* dest_scan, 57 int dest_bpp, 58 int dest_width, 59 bool bFlipX, 60 int clip_left, 61 int clip_width) const override; 62 GetColorSpace()63 const CPDF_ColorSpace* GetColorSpace() const { return m_pColorSpace; } GetMatteColor()64 uint32_t GetMatteColor() const { return m_MatteColor; } 65 66 int StartLoadDIBSource(CPDF_Document* pDoc, 67 const CPDF_Stream* pStream, 68 bool bHasMask, 69 CPDF_Dictionary* pFormResources, 70 CPDF_Dictionary* pPageResources, 71 bool bStdCS = false, 72 uint32_t GroupFamily = 0, 73 bool bLoadMask = false); 74 int ContinueLoadDIBSource(IFX_PauseIndicator* pPause); 75 int StartLoadMask(); 76 int StartLoadMaskDIB(); 77 int ContinueLoadMaskDIB(IFX_PauseIndicator* pPause); 78 bool ContinueToLoadMask(); 79 RetainPtr<CPDF_DIBSource> DetachMask(); 80 81 private: 82 CPDF_DIBSource(); 83 84 bool LoadColorInfo(const CPDF_Dictionary* pFormResources, 85 const CPDF_Dictionary* pPageResources); 86 DIB_COMP_DATA* GetDecodeAndMaskArray(bool* bDefaultDecode, bool* bColorKey); 87 void LoadJpxBitmap(); 88 void LoadPalette(); 89 int CreateDecoder(); 90 bool CreateDCTDecoder(const uint8_t* src_data, 91 uint32_t src_size, 92 const CPDF_Dictionary* pParams); 93 void TranslateScanline24bpp(uint8_t* dest_scan, 94 const uint8_t* src_scan) const; 95 void ValidateDictParam(); 96 void DownSampleScanline1Bit(int orig_Bpp, 97 int dest_Bpp, 98 uint32_t src_width, 99 const uint8_t* pSrcLine, 100 uint8_t* dest_scan, 101 int dest_width, 102 bool bFlipX, 103 int clip_left, 104 int clip_width) const; 105 void DownSampleScanline8Bit(int orig_Bpp, 106 int dest_Bpp, 107 uint32_t src_width, 108 const uint8_t* pSrcLine, 109 uint8_t* dest_scan, 110 int dest_width, 111 bool bFlipX, 112 int clip_left, 113 int clip_width) const; 114 void DownSampleScanline32Bit(int orig_Bpp, 115 int dest_Bpp, 116 uint32_t src_width, 117 const uint8_t* pSrcLine, 118 uint8_t* dest_scan, 119 int dest_width, 120 bool bFlipX, 121 int clip_left, 122 int clip_width) const; 123 bool TransMask() const; 124 125 UnownedPtr<CPDF_Document> m_pDocument; 126 UnownedPtr<const CPDF_Stream> m_pStream; 127 UnownedPtr<const CPDF_Dictionary> m_pDict; 128 RetainPtr<CPDF_StreamAcc> m_pStreamAcc; 129 CPDF_ColorSpace* m_pColorSpace; 130 uint32_t m_Family; 131 uint32_t m_bpc; 132 uint32_t m_bpc_orig; 133 uint32_t m_nComponents; 134 uint32_t m_GroupFamily; 135 uint32_t m_MatteColor; 136 bool m_bLoadMask; 137 bool m_bDefaultDecode; 138 bool m_bImageMask; 139 bool m_bDoBpcCheck; 140 bool m_bColorKey; 141 bool m_bHasMask; 142 bool m_bStdCS; 143 DIB_COMP_DATA* m_pCompData; 144 uint8_t* m_pLineBuf; 145 uint8_t* m_pMaskedLine; 146 RetainPtr<CFX_DIBitmap> m_pCachedBitmap; 147 RetainPtr<CPDF_DIBSource> m_pMask; 148 RetainPtr<CPDF_StreamAcc> m_pGlobalStream; 149 std::unique_ptr<CCodec_ScanlineDecoder> m_pDecoder; 150 std::unique_ptr<CCodec_Jbig2Context> m_pJbig2Context; 151 UnownedPtr<CPDF_Stream> m_pMaskStream; 152 int m_Status; 153 }; 154 155 #endif // CORE_FPDFAPI_RENDER_CPDF_DIBSOURCE_H_ 156