1 // Copyright 2014 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_patterncs.h"
8
9 #include "core/fpdfapi/page/cpdf_docpagedata.h"
10 #include "core/fpdfapi/parser/cpdf_array.h"
11 #include "core/fpdfapi/parser/cpdf_document.h"
12 #include "third_party/base/notreached.h"
13
CPDF_PatternCS()14 CPDF_PatternCS::CPDF_PatternCS() : CPDF_BasedCS(Family::kPattern) {}
15
16 CPDF_PatternCS::~CPDF_PatternCS() = default;
17
InitializeStockPattern()18 void CPDF_PatternCS::InitializeStockPattern() {
19 SetComponentsForStockCS(1);
20 }
21
v_Load(CPDF_Document * pDoc,const CPDF_Array * pArray,std::set<const CPDF_Object * > * pVisited)22 uint32_t CPDF_PatternCS::v_Load(CPDF_Document* pDoc,
23 const CPDF_Array* pArray,
24 std::set<const CPDF_Object*>* pVisited) {
25 RetainPtr<const CPDF_Object> pBaseCS = pArray->GetDirectObjectAt(1);
26 if (HasSameArray(pBaseCS.Get()))
27 return 0;
28
29 auto* pDocPageData = CPDF_DocPageData::FromDocument(pDoc);
30 m_pBaseCS =
31 pDocPageData->GetColorSpaceGuarded(pBaseCS.Get(), nullptr, pVisited);
32 if (!m_pBaseCS)
33 return 1;
34
35 if (m_pBaseCS->GetFamily() == Family::kPattern)
36 return 0;
37
38 if (m_pBaseCS->CountComponents() > kMaxPatternColorComps)
39 return 0;
40
41 return m_pBaseCS->CountComponents() + 1;
42 }
43
GetRGB(pdfium::span<const float> pBuf,float * R,float * G,float * B) const44 bool CPDF_PatternCS::GetRGB(pdfium::span<const float> pBuf,
45 float* R,
46 float* G,
47 float* B) const {
48 NOTREACHED_NORETURN();
49 }
50
AsPatternCS() const51 const CPDF_PatternCS* CPDF_PatternCS::AsPatternCS() const {
52 return this;
53 }
54
GetPatternRGB(const PatternValue & value,float * R,float * G,float * B) const55 bool CPDF_PatternCS::GetPatternRGB(const PatternValue& value,
56 float* R,
57 float* G,
58 float* B) const {
59 if (m_pBaseCS && m_pBaseCS->GetRGB(value.GetComps(), R, G, B))
60 return true;
61
62 *R = 0.75f;
63 *G = 0.75f;
64 *B = 0.75f;
65 return false;
66 }
67