Home | History | Annotate | Download | only in page
      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/fpdfapi/parser/cpdf_stream.h"
     13 #include "core/fxcrt/fx_system.h"
     14 #include "core/fxcrt/maybe_owned.h"
     15 #include "core/fxcrt/retain_ptr.h"
     16 #include "core/fxcrt/unowned_ptr.h"
     17 
     18 class CFX_DIBSource;
     19 class CFX_DIBitmap;
     20 class CPDF_Document;
     21 class CPDF_Page;
     22 class IFX_PauseIndicator;
     23 class IFX_SeekableReadStream;
     24 
     25 class CPDF_Image : public Retainable {
     26  public:
     27   template <typename T, typename... Args>
     28   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
     29 
     30   void ConvertStreamToIndirectObject();
     31 
     32   CPDF_Dictionary* GetInlineDict() const { return m_pDict.Get(); }
     33   CPDF_Stream* GetStream() const { return m_pStream.Get(); }
     34   CPDF_Dictionary* GetDict() const;
     35   CPDF_Dictionary* GetOC() const { return m_pOC.Get(); }
     36   CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
     37 
     38   int32_t GetPixelHeight() const { return m_Height; }
     39   int32_t GetPixelWidth() const { return m_Width; }
     40 
     41   bool IsInline() const { return m_bIsInline; }
     42   bool IsMask() const { return m_bIsMask; }
     43   bool IsInterpol() const { return m_bInterpolate; }
     44 
     45   RetainPtr<CFX_DIBSource> LoadDIBSource() const;
     46 
     47   void SetImage(const RetainPtr<CFX_DIBitmap>& pDIBitmap);
     48   void SetJpegImage(const RetainPtr<IFX_SeekableReadStream>& pFile);
     49   void SetJpegImageInline(const RetainPtr<IFX_SeekableReadStream>& pFile);
     50 
     51   void ResetCache(CPDF_Page* pPage, const RetainPtr<CFX_DIBitmap>& pDIBitmap);
     52   bool StartLoadDIBSource(CPDF_Dictionary* pFormResource,
     53                           CPDF_Dictionary* pPageResource,
     54                           bool bStdCS = false,
     55                           uint32_t GroupFamily = 0,
     56                           bool bLoadMask = false);
     57   bool Continue(IFX_PauseIndicator* pPause);
     58   RetainPtr<CFX_DIBSource> DetachBitmap();
     59   RetainPtr<CFX_DIBSource> DetachMask();
     60 
     61   RetainPtr<CFX_DIBSource> m_pDIBSource;
     62   RetainPtr<CFX_DIBSource> m_pMask;
     63   uint32_t m_MatteColor = 0;
     64 
     65  private:
     66   explicit CPDF_Image(CPDF_Document* pDoc);
     67   CPDF_Image(CPDF_Document* pDoc, std::unique_ptr<CPDF_Stream> pStream);
     68   CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum);
     69   ~CPDF_Image() override;
     70 
     71   void FinishInitialization();
     72   std::unique_ptr<CPDF_Dictionary> InitJPEG(uint8_t* pData, uint32_t size);
     73 
     74   int32_t m_Height = 0;
     75   int32_t m_Width = 0;
     76   bool m_bIsInline = false;
     77   bool m_bIsMask = false;
     78   bool m_bInterpolate = false;
     79   UnownedPtr<CPDF_Document> const m_pDocument;
     80   MaybeOwned<CPDF_Stream> m_pStream;
     81   MaybeOwned<CPDF_Dictionary> m_pDict;
     82   UnownedPtr<CPDF_Dictionary> m_pOC;
     83 };
     84 
     85 #endif  // CORE_FPDFAPI_PAGE_CPDF_IMAGE_H_
     86