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