52 VisitedSet* pVisited) {
56 if (pdfium::Contains(*pVisited, pFuncObj))
59 ScopedSetInsertion<VisitedSet::value_type> insertion(pVisited, pFuncObj);
62 if (
const CPDF_Stream* pStream = pFuncObj->AsStream())
63 iType = pStream
->GetDict()->GetIntegerFor(
"FunctionType");
64 else if (
const CPDF_Dictionary* pDict = pFuncObj->AsDictionary())
67 std::unique_ptr<CPDF_Function> pFunc;
68 Type type = IntegerToFunctionType(iType);
70 pFunc =
std::make_unique<CPDF_SampledFunc>();
72 pFunc =
std::make_unique<CPDF_ExpIntFunc>();
74 pFunc =
std::make_unique<CPDF_StitchFunc>();
76 pFunc =
std::make_unique<CPDF_PSFunc>();
78 if (!pFunc || !pFunc->Init(pFuncObj, pVisited))
91 pStream ? pStream->GetDict() : pdfium::WrapRetain(pObj->AsDictionary());
93 RetainPtr<
const CPDF_Array> pDomains = pDict->GetArrayFor(
"Domain");
101 size_t nInputs = m_nInputs * 2;
102 m_Domains = ReadArrayElementsToVector(pDomains.Get(), nInputs);
104 RetainPtr<
const CPDF_Array> pRanges = pDict->GetArrayFor(
"Range");
105 m_nOutputs = pRanges ?
fxcrt::CollectionSize<uint32_t>(*pRanges) / 2 : 0;
109 bool bRangeRequired =
115 size_t nOutputs = m_nOutputs * 2;
116 m_Ranges = ReadArrayElementsToVector(pRanges.Get(), nOutputs);
120 if (!v_Init(pObj, pVisited))
123 if (!m_Ranges.empty() && m_nOutputs > old_outputs) {
124 FX_SAFE_SIZE_T nOutputs = m_nOutputs;
126 m_Ranges.resize(nOutputs.ValueOrDie());
132 pdfium::span<
const float> inputs,
133 pdfium::span<
float> results)
const {
134 if (m_nInputs != inputs.size())
135 return absl::nullopt;
137 std::vector<
float> clamped_inputs(m_nInputs);
138 for (uint32_t i = 0; i <
m_nInputs; i++) {
139 float domain1 = m_Domains[i * 2];
140 float domain2 = m_Domains[i * 2 + 1];
141 if (domain1 > domain2)
142 return absl::nullopt;
144 clamped_inputs[i] =
std::clamp(inputs[i], domain1, domain2);
146 if (!v_Call(clamped_inputs, results))
147 return absl::nullopt;
149 if (m_Ranges.empty())
153 float range1 = m_Ranges[i * 2];
154 float range2 = m_Ranges[i * 2 + 1];
156 return absl::nullopt;
158 results[i] =
std::clamp(results[i], range1, range2);