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