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_COLOR_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_COLOR_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxcrt/fx_system.h" 14 #include "core/fxcrt/retain_ptr.h" 15 16 class CPDF_ColorSpace; 17 class CPDF_Pattern; 18 class PatternValue; 19 20 class CPDF_Color { 21 public: 22 CPDF_Color(); 23 CPDF_Color(const CPDF_Color& that); 24 25 ~CPDF_Color(); 26 27 CPDF_Color& operator=(const CPDF_Color& that); 28 IsNull()29 bool IsNull() const { return m_Buffer.empty() && !m_pValue; } 30 bool IsPattern() const; 31 void SetColorSpace(const RetainPtr<CPDF_ColorSpace>& pCS); 32 void SetValueForNonPattern(const std::vector<float>& values); 33 void SetValueForPattern(const RetainPtr<CPDF_Pattern>& pPattern, 34 const std::vector<float>& values); 35 uint32_t CountComponents() const; 36 bool IsColorSpaceRGB() const; 37 bool GetRGB(int* R, int* G, int* B) const; 38 39 // Should only be called if IsPattern() returns true. 40 CPDF_Pattern* GetPattern() const; 41 42 protected: 43 bool IsPatternInternal() const; 44 45 std::vector<float> m_Buffer; // Used for non-pattern colorspaces. 46 std::unique_ptr<PatternValue> m_pValue; // Used for pattern colorspaces. 47 RetainPtr<CPDF_ColorSpace> m_pCS; 48 }; 49 50 #endif // CORE_FPDFAPI_PAGE_CPDF_COLOR_H_ 51