• 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_MESHSTREAM_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_MESHSTREAM_H_
9 
10 #include <stdint.h>
11 
12 #include <array>
13 #include <memory>
14 #include <vector>
15 
16 #include "core/fpdfapi/page/cpdf_shadingpattern.h"
17 #include "core/fxcrt/retain_ptr.h"
18 #include "core/fxge/dib/fx_dib.h"
19 
20 class CPDF_StreamAcc;
21 
22 class CPDF_MeshVertex {
23  public:
24   CPDF_MeshVertex();
25   CPDF_MeshVertex(const CPDF_MeshVertex&);
26   ~CPDF_MeshVertex();
27 
28   CFX_PointF position;
29   FX_RGB_STRUCT<float> rgb = {};
30 };
31 
32 class CFX_BitStream;
33 class CFX_Matrix;
34 class CPDF_ColorSpace;
35 class CPDF_Function;
36 class CPDF_Stream;
37 
38 class CPDF_MeshStream {
39  public:
40   CPDF_MeshStream(ShadingType type,
41                   const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
42                   RetainPtr<const CPDF_Stream> pShadingStream,
43                   RetainPtr<CPDF_ColorSpace> pCS);
44   ~CPDF_MeshStream();
45 
46   bool Load();
47   void SkipBits(uint32_t nbits);
48   void ByteAlign();
49 
50   bool IsEOF() const;
51   bool CanReadFlag() const;
52   bool CanReadCoords() const;
53   bool CanReadColor() const;
54 
55   uint32_t ReadFlag() const;
56   CFX_PointF ReadCoords() const;
57   FX_RGB_STRUCT<float> ReadColor() const;
58 
59   bool ReadVertex(const CFX_Matrix& pObject2Bitmap,
60                   CPDF_MeshVertex* vertex,
61                   uint32_t* flag);
62   std::vector<CPDF_MeshVertex> ReadVertexRow(const CFX_Matrix& pObject2Bitmap,
63                                              int count);
64 
ComponentBits()65   uint32_t ComponentBits() const { return m_nComponentBits; }
Components()66   uint32_t Components() const { return m_nComponents; }
67 
68  private:
69   static constexpr uint32_t kMaxComponents = 8;
70 
71   const ShadingType m_type;
72   const std::vector<std::unique_ptr<CPDF_Function>>& m_funcs;
73   RetainPtr<const CPDF_Stream> const m_pShadingStream;
74   RetainPtr<CPDF_ColorSpace> const m_pCS;
75   uint32_t m_nCoordBits = 0;
76   uint32_t m_nComponentBits = 0;
77   uint32_t m_nFlagBits = 0;
78   uint32_t m_nComponents = 0;
79   uint32_t m_CoordMax = 0;
80   uint32_t m_ComponentMax = 0;
81   float m_xmin = 0.0f;
82   float m_xmax = 0.0f;
83   float m_ymin = 0.0f;
84   float m_ymax = 0.0f;
85   RetainPtr<CPDF_StreamAcc> m_pStream;
86   std::unique_ptr<CFX_BitStream> m_BitStream;
87   std::array<float, kMaxComponents> m_ColorMin = {};
88   std::array<float, kMaxComponents> m_ColorMax = {};
89 };
90 
91 #endif  // CORE_FPDFAPI_PAGE_CPDF_MESHSTREAM_H_
92