• 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/fx_basic.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   FX_FLOAT r;
27   FX_FLOAT g;
28   FX_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 
43   bool Load();
44 
45   bool CanReadFlag() const;
46   bool CanReadCoords() const;
47   bool CanReadColor() const;
48 
49   uint32_t ReadFlag();
50   CFX_PointF ReadCoords();
51   std::tuple<FX_FLOAT, FX_FLOAT, FX_FLOAT> ReadColor();
52 
53   bool ReadVertex(const CFX_Matrix& pObject2Bitmap,
54                   CPDF_MeshVertex* vertex,
55                   uint32_t* flag);
56   bool ReadVertexRow(const CFX_Matrix& pObject2Bitmap,
57                      int count,
58                      CPDF_MeshVertex* vertex);
59 
BitStream()60   CFX_BitStream* BitStream() { return &m_BitStream; }
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   CPDF_Stream* const m_pShadingStream;
70   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   FX_FLOAT m_xmin;
78   FX_FLOAT m_xmax;
79   FX_FLOAT m_ymin;
80   FX_FLOAT m_ymax;
81   FX_FLOAT m_ColorMin[kMaxComponents];
82   FX_FLOAT m_ColorMax[kMaxComponents];
83   CPDF_StreamAcc m_Stream;
84   CFX_BitStream m_BitStream;
85 };
86 
87 #endif  // CORE_FPDFAPI_PAGE_CPDF_MESHSTREAM_H_
88