Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_color.cpp
Go to the documentation of this file.
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#include "core/fpdfapi/page/cpdf_color.h"
8
9#include <utility>
10
11#include "core/fpdfapi/page/cpdf_patterncs.h"
12#include "third_party/base/check.h"
13
14CPDF_Color::CPDF_Color() = default;
15
17 *this = that;
18}
19
20CPDF_Color::~CPDF_Color() = default;
21
22bool CPDF_Color::IsPattern() const {
23 return m_pCS && IsPatternInternal();
24}
25
27 return m_pCS->GetFamily() == CPDF_ColorSpace::Family::kPattern;
28}
29
31 m_pCS = std::move(colorspace);
33 m_Buffer.clear();
34 m_pValue = std::make_unique<PatternValue>();
35 } else {
36 m_Buffer = m_pCS->CreateBufAndSetDefaultColor();
37 m_pValue.reset();
38 }
39}
40
41void CPDF_Color::SetValueForNonPattern(std::vector<float> values) {
42 DCHECK(!IsPatternInternal());
43 DCHECK(m_pCS->CountComponents() <= values.size());
44 m_Buffer = std::move(values);
45}
46
48 pdfium::span<float> values) {
49 if (values.size() > kMaxPatternColorComps)
50 return;
51
52 if (!IsPattern()) {
55 }
56 m_pValue->SetPattern(std::move(pattern));
57 m_pValue->SetComps(values);
58}
59
61 if (this == &that)
62 return *this;
63
64 m_Buffer = that.m_Buffer;
65 m_pValue =
66 that.m_pValue ? std::make_unique<PatternValue>(*that.m_pValue) : nullptr;
67 m_pCS = that.m_pCS;
68 return *this;
69}
70
71uint32_t CPDF_Color::CountComponents() const {
72 return m_pCS->CountComponents();
73}
74
76 return m_pCS ==
77 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceRGB);
78}
79
80bool CPDF_Color::GetRGB(int* R, int* G, int* B) const {
81 float r = 0.0f;
82 float g = 0.0f;
83 float b = 0.0f;
84 bool result = false;
86 if (m_pValue) {
87 const CPDF_PatternCS* pPatternCS = m_pCS->AsPatternCS();
88 result = pPatternCS->GetPatternRGB(*m_pValue, &r, &g, &b);
89 }
90 } else {
91 if (!m_Buffer.empty())
92 result = m_pCS->GetRGB(m_Buffer, &r, &g, &b);
93 }
94 if (!result)
95 return false;
96
97 *R = static_cast<int32_t>(r * 255 + 0.5f);
98 *G = static_cast<int32_t>(g * 255 + 0.5f);
99 *B = static_cast<int32_t>(b * 255 + 0.5f);
100 return true;
101}
102
104 DCHECK(IsPattern());
105 return m_pValue ? m_pValue->GetPattern() : nullptr;
106}
static RetainPtr< CPDF_ColorSpace > GetStockCS(Family family)
void SetValueForPattern(RetainPtr< CPDF_Pattern > pattern, pdfium::span< float > values)
bool IsPatternInternal() const
CPDF_Color(const CPDF_Color &that)
CPDF_Color & operator=(const CPDF_Color &that)
void SetValueForNonPattern(std::vector< float > values)
RetainPtr< CPDF_Pattern > GetPattern() const
bool IsPattern() const
void SetColorSpace(RetainPtr< CPDF_ColorSpace > colorspace)
bool GetRGB(int *R, int *G, int *B) const
uint32_t CountComponents() const
bool IsColorSpaceRGB() const