• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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 <stdint.h>
11 
12 #include "core/fpdfapi/page/cpdf_colorspace.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_DIB;
20 class CPDF_Dictionary;
21 class CPDF_Document;
22 class CPDF_Page;
23 class CPDF_Stream;
24 class PauseIndicatorIface;
25 class IFX_SeekableReadStream;
26 
27 class CPDF_Image final : public Retainable {
28  public:
29   CONSTRUCT_VIA_MAKE_RETAIN;
30 
31   static bool IsValidJpegComponent(int32_t comps);
32   static bool IsValidJpegBitsPerComponent(int32_t bpc);
33 
34   void ConvertStreamToIndirectObject();
35 
36   RetainPtr<const CPDF_Dictionary> GetDict() const;
37   RetainPtr<const CPDF_Stream> GetStream() const;
38   RetainPtr<const CPDF_Dictionary> GetOC() const;
GetDocument()39   CPDF_Document* GetDocument() const { return m_pDocument; }
40 
GetPixelHeight()41   int32_t GetPixelHeight() const { return m_Height; }
GetPixelWidth()42   int32_t GetPixelWidth() const { return m_Width; }
GetMatteColor()43   uint32_t GetMatteColor() const { return m_MatteColor; }
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<CPDF_DIB> CreateNewDIB() const;
49   RetainPtr<CFX_DIBBase> LoadDIBBase() const;
50 
51   void SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap);
52   void SetJpegImage(RetainPtr<IFX_SeekableReadStream> pFile);
53   void SetJpegImageInline(RetainPtr<IFX_SeekableReadStream> pFile);
54 
55   void ResetCache(CPDF_Page* pPage);
56 
57   // Returns whether to Continue() or not.
58   bool StartLoadDIBBase(const CPDF_Dictionary* pFormResource,
59                         const CPDF_Dictionary* pPageResource,
60                         bool bStdCS,
61                         CPDF_ColorSpace::Family GroupFamily,
62                         bool bLoadMask,
63                         const CFX_Size& max_size_required);
64 
65   // Returns whether to Continue() or not.
66   bool Continue(PauseIndicatorIface* pPause);
67 
68   RetainPtr<CFX_DIBBase> DetachBitmap();
69   RetainPtr<CFX_DIBBase> DetachMask();
70 
71  private:
72   explicit CPDF_Image(CPDF_Document* pDoc);
73   CPDF_Image(CPDF_Document* pDoc, RetainPtr<CPDF_Stream> pStream);
74   CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum);
75   ~CPDF_Image() override;
76 
77   void FinishInitialization();
78   RetainPtr<CPDF_Dictionary> InitJPEG(pdfium::span<uint8_t> src_span);
79   RetainPtr<CPDF_Dictionary> CreateXObjectImageDict(int width, int height);
80 
81   int32_t m_Height = 0;
82   int32_t m_Width = 0;
83   uint32_t m_MatteColor = 0;
84   bool m_bIsInline = false;
85   bool m_bIsMask = false;
86   bool m_bInterpolate = false;
87   UnownedPtr<CPDF_Document> const m_pDocument;
88   RetainPtr<CFX_DIBBase> m_pDIBBase;
89   RetainPtr<CFX_DIBBase> m_pMask;
90   RetainPtr<CPDF_Stream> m_pStream;
91   RetainPtr<const CPDF_Dictionary> m_pOC;
92 };
93 
94 #endif  // CORE_FPDFAPI_PAGE_CPDF_IMAGE_H_
95