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/cfx_maybe_owned.h"
     14 #include "core/fxcrt/fx_system.h"
     15 
     16 class CFX_DIBSource;
     17 class CFX_DIBitmap;
     18 class CPDF_Document;
     19 class CPDF_Page;
     20 class IFX_Pause;
     21 class IFX_SeekableReadStream;
     22 
     23 class CPDF_Image {
     24  public:
     25   explicit CPDF_Image(CPDF_Document* pDoc);
     26   CPDF_Image(CPDF_Document* pDoc, std::unique_ptr<CPDF_Stream> pStream);
     27   CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum);
     28   ~CPDF_Image();
     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     return m_pStream ? m_pStream->GetDict() : nullptr;
     36   }
     37   CPDF_Dictionary* GetOC() const { return m_pOC; }
     38   CPDF_Document* GetDocument() const { return m_pDocument; }
     39 
     40   int32_t GetPixelHeight() const { return m_Height; }
     41   int32_t GetPixelWidth() const { return m_Width; }
     42 
     43   bool IsInline() const { return m_bIsInline; }
     44   bool IsMask() const { return m_bIsMask; }
     45   bool IsInterpol() const { return m_bInterpolate; }
     46 
     47   std::unique_ptr<CFX_DIBSource> LoadDIBSource() const;
     48 
     49   void SetImage(const CFX_DIBitmap* pDIBitmap);
     50   void SetJpegImage(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
     51   void SetJpegImageInline(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
     52 
     53   void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap);
     54 
     55   bool StartLoadDIBSource(CPDF_Dictionary* pFormResource,
     56                           CPDF_Dictionary* pPageResource,
     57                           bool bStdCS = false,
     58                           uint32_t GroupFamily = 0,
     59                           bool bLoadMask = false);
     60   bool Continue(IFX_Pause* pPause);
     61   CFX_DIBSource* DetachBitmap();
     62   CFX_DIBSource* DetachMask();
     63 
     64   CFX_DIBSource* m_pDIBSource = nullptr;
     65   CFX_DIBSource* m_pMask = nullptr;
     66   uint32_t m_MatteColor = 0;
     67 
     68  private:
     69   void FinishInitialization();
     70   std::unique_ptr<CPDF_Dictionary> InitJPEG(uint8_t* pData, uint32_t size);
     71 
     72   int32_t m_Height = 0;
     73   int32_t m_Width = 0;
     74   bool m_bIsInline = false;
     75   bool m_bIsMask = false;
     76   bool m_bInterpolate = false;
     77   CPDF_Document* const m_pDocument;
     78   CFX_MaybeOwned<CPDF_Stream> m_pStream;
     79   CFX_MaybeOwned<CPDF_Dictionary> m_pDict;
     80   CPDF_Dictionary* m_pOC = nullptr;
     81 };
     82 
     83 #endif  // CORE_FPDFAPI_PAGE_CPDF_IMAGE_H_
     84