7#include "core/fpdfapi/page/cpdf_shadingpattern.h"
12#include "core/fpdfapi/page/cpdf_docpagedata.h"
13#include "core/fpdfapi/page/cpdf_function.h"
14#include "core/fpdfapi/parser/cpdf_array.h"
15#include "core/fpdfapi/parser/cpdf_dictionary.h"
16#include "core/fpdfapi/parser/cpdf_document.h"
17#include "core/fpdfapi/parser/cpdf_object.h"
18#include "core/fpdfapi/parser/cpdf_stream.h"
19#include "core/fxcrt/fx_safe_types.h"
20#include "third_party/base/check.h"
21#include "third_party/base/notreached.h"
38 m_bShading(bShading) {
50bool CPDF_ShadingPattern::
Load() {
55 RetainPtr<
const CPDF_Dictionary> pShadingDict =
56 pShadingObj ? pShadingObj->GetDict() :
nullptr;
62 pShadingDict->GetDirectObjectFor(
"Function");
64 if (
const CPDF_Array* pArray = pFunc->AsArray()) {
65 m_pFunctions.resize(std::min<size_t>(pArray->size(), 4));
66 for (size_t i = 0; i < m_pFunctions.size(); ++i) {
67 m_pFunctions[i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i));
70 m_pFunctions.push_back(CPDF_Function::Load(std::move(pFunc)));
74 pShadingDict->GetDirectObjectFor(
"ColorSpace");
79 m_pCS = pDocPageData->GetColorSpace(pCSObj.Get(),
nullptr);
83 if (!m_pCS || m_pCS->GetFamily() == CPDF_ColorSpace::Family::kPattern)
86 m_ShadingType = ToShadingType(pShadingDict->GetIntegerFor(
"ShadingType"));
91 return m_bShading ? pattern_obj()
92 : pattern_obj()->GetDict()->GetDirectObjectFor(
"Shading");
95bool CPDF_ShadingPattern::Validate()
const {
100 if (IsMeshShading() && !ToStream(GetShadingObject()))
104 switch (m_ShadingType) {
108 if (m_pCS->GetFamily() == CPDF_ColorSpace::Family::kIndexed)
116 if (!m_pFunctions.empty() &&
117 m_pCS->GetFamily() == CPDF_ColorSpace::Family::kIndexed) {
123 NOTREACHED_NORETURN();
127 uint32_t nNumColorSpaceComponents = m_pCS->CountComponents();
128 switch (m_ShadingType) {
131 return ValidateFunctions(1, 2, nNumColorSpaceComponents) ||
132 ValidateFunctions(nNumColorSpaceComponents, 2, 1);
137 return ValidateFunctions(1, 1, nNumColorSpaceComponents) ||
138 ValidateFunctions(nNumColorSpaceComponents, 1, 1);
145 return m_pFunctions.empty() ||
146 ValidateFunctions(1, 1, nNumColorSpaceComponents) ||
147 ValidateFunctions(nNumColorSpaceComponents, 1, 1);
150 NOTREACHED_NORETURN();
154bool CPDF_ShadingPattern::ValidateFunctions(
155 uint32_t nExpectedNumFunctions,
156 uint32_t nExpectedNumInputs,
157 uint32_t nExpectedNumOutputs)
const {
158 if (m_pFunctions.size() != nExpectedNumFunctions)
161 FX_SAFE_UINT32 nTotalOutputs = 0;
162 for (
const auto& function : m_pFunctions) {
166 if (function->CountInputs() != nExpectedNumInputs ||
167 function->CountOutputs() != nExpectedNumOutputs) {
171 nTotalOutputs += function->CountOutputs();
174 return nTotalOutputs.IsValid();
static CPDF_DocPageData * FromDocument(const CPDF_Document *pDoc)
void SetPatternToFormMatrix()
CPDF_Document * document() const
CPDF_ShadingPattern * AsShadingPattern() override
~CPDF_ShadingPattern() override
RetainPtr< const CPDF_Object > GetShadingObject() const
@ kTensorProductPatchMeshShading
@ kLatticeFormGouraudTriangleMeshShading
@ kFreeFormGouraudTriangleMeshShading