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