1 // Copyright 2016 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_PAGE_CPDF_IMAGE_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_IMAGE_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/fx_system.h" 13 #include "core/fxcrt/retain_ptr.h" 14 #include "core/fxcrt/unowned_ptr.h" 15 #include "third_party/base/span.h" 16 17 class CFX_DIBBase; 18 class CFX_DIBitmap; 19 class CPDF_Dictionary; 20 class CPDF_Document; 21 class CPDF_Page; 22 class CPDF_Stream; 23 class PauseIndicatorIface; 24 class IFX_SeekableReadStream; 25 26 class CPDF_Image final : public Retainable { 27 public: 28 template <typename T, typename... Args> 29 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 30 31 static bool IsValidJpegComponent(int32_t comps); 32 static bool IsValidJpegBitsPerComponent(int32_t bpc); 33 34 void ConvertStreamToIndirectObject(); 35 36 CPDF_Dictionary* GetDict() const; GetStream()37 CPDF_Stream* GetStream() const { return m_pStream.Get(); } GetOC()38 const CPDF_Dictionary* GetOC() const { return m_pOC.Get(); } GetDocument()39 CPDF_Document* GetDocument() const { return m_pDocument.Get(); } 40 GetPixelHeight()41 int32_t GetPixelHeight() const { return m_Height; } GetPixelWidth()42 int32_t GetPixelWidth() const { return m_Width; } 43 IsInline()44 bool IsInline() const { return m_bIsInline; } IsMask()45 bool IsMask() const { return m_bIsMask; } IsInterpol()46 bool IsInterpol() const { return m_bInterpolate; } 47 48 RetainPtr<CFX_DIBBase> LoadDIBBase() const; 49 50 void SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap); 51 void SetJpegImage(const RetainPtr<IFX_SeekableReadStream>& pFile); 52 void SetJpegImageInline(const RetainPtr<IFX_SeekableReadStream>& pFile); 53 54 void ResetCache(CPDF_Page* pPage); 55 56 // Returns whether to Continue() or not. 57 bool StartLoadDIBBase(const CPDF_Dictionary* pFormResource, 58 CPDF_Dictionary* pPageResource, 59 bool bStdCS, 60 uint32_t GroupFamily, 61 bool bLoadMask); 62 63 // Returns whether to Continue() or not. 64 bool Continue(PauseIndicatorIface* pPause); 65 66 RetainPtr<CFX_DIBBase> DetachBitmap(); 67 RetainPtr<CFX_DIBBase> DetachMask(); 68 69 RetainPtr<CFX_DIBBase> m_pDIBBase; 70 RetainPtr<CFX_DIBBase> m_pMask; 71 uint32_t m_MatteColor = 0; 72 73 private: 74 explicit CPDF_Image(CPDF_Document* pDoc); 75 CPDF_Image(CPDF_Document* pDoc, RetainPtr<CPDF_Stream> pStream); 76 CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum); 77 ~CPDF_Image() override; 78 79 void FinishInitialization(CPDF_Dictionary* pStreamDict); 80 RetainPtr<CPDF_Dictionary> InitJPEG(pdfium::span<uint8_t> src_span); 81 82 RetainPtr<CPDF_Dictionary> CreateXObjectImageDict(int width, int height); 83 84 int32_t m_Height = 0; 85 int32_t m_Width = 0; 86 bool m_bIsInline = false; 87 bool m_bIsMask = false; 88 bool m_bInterpolate = false; 89 UnownedPtr<CPDF_Document> const m_pDocument; 90 RetainPtr<CPDF_Stream> m_pStream; 91 RetainPtr<const CPDF_Dictionary> m_pOC; 92 }; 93 94 #endif // CORE_FPDFAPI_PAGE_CPDF_IMAGE_H_ 95