• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COLOR_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_COLOR_H_
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <optional>
14 #include <vector>
15 
16 #include "core/fxcrt/retain_ptr.h"
17 #include "core/fxcrt/span.h"
18 #include "core/fxge/dib/fx_dib.h"
19 #include "third_party/abseil-cpp/absl/types/variant.h"
20 
21 class CPDF_ColorSpace;
22 class CPDF_Pattern;
23 class PatternValue;
24 
25 class CPDF_Color {
26  public:
27   CPDF_Color();
28   CPDF_Color(const CPDF_Color& that);
29 
30   ~CPDF_Color();
31 
32   CPDF_Color& operator=(const CPDF_Color& that);
33 
34   bool IsNull() const;
35   bool IsPattern() const;
36   void SetColorSpace(RetainPtr<CPDF_ColorSpace> colorspace);
37   void SetValueForNonPattern(std::vector<float> values);
38   void SetValueForPattern(RetainPtr<CPDF_Pattern> pattern,
39                           pdfium::span<float> values);
40 
41   uint32_t ComponentCount() const;
42   bool IsColorSpaceRGB() const;
43   bool IsColorSpaceGray() const;
44   // Wrapper around GetRGB() that returns the RGB value as FX_COLORREF. The
45   // GetRGB() return value is clamped to fit into FX_COLORREF, where the color
46   // components are 8-bit fields within an unsigned integer.
47   std::optional<FX_COLORREF> GetColorRef() const;
48   std::optional<FX_RGB_STRUCT<float>> GetRGB() const;
49 
50   // Should only be called if IsPattern() returns true.
51   RetainPtr<CPDF_Pattern> GetPattern() const;
52 
53  protected:
54   bool IsPatternInternal() const;
55 
56   absl::variant<absl::monostate,
57                 std::vector<float>,  // Used for non-pattern colorspaces.
58                 std::unique_ptr<PatternValue>>  // Used for pattern colorspaces.
59       color_data_;
60   RetainPtr<CPDF_ColorSpace> cs_;
61 };
62 
63 #endif  // CORE_FPDFAPI_PAGE_CPDF_COLOR_H_
64