1 // Copyright 2017 PDFium Authors. All rights reserved. 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_expintfunc.h" 8 9 #include "core/fpdfapi/parser/cpdf_array.h" 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" 11 #include "core/fpdfapi/parser/cpdf_number.h" 12 #include "core/fxcrt/fx_safe_types.h" 13 #include "third_party/base/stl_util.h" 14 CPDF_ExpIntFunc()15CPDF_ExpIntFunc::CPDF_ExpIntFunc() 16 : CPDF_Function(Type::kType2ExpotentialInterpolation) {} 17 18 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() = default; 19 v_Init(const CPDF_Object * pObj,std::set<const CPDF_Object * > * pVisited)20bool CPDF_ExpIntFunc::v_Init(const CPDF_Object* pObj, 21 std::set<const CPDF_Object*>* pVisited) { 22 const CPDF_Dictionary* pDict = pObj->GetDict(); 23 if (!pDict) 24 return false; 25 26 const CPDF_Number* pExponent = ToNumber(pDict->GetObjectFor("N")); 27 if (!pExponent) 28 return false; 29 30 m_Exponent = pExponent->GetNumber(); 31 32 const CPDF_Array* pArray0 = pDict->GetArrayFor("C0"); 33 if (pArray0 && m_nOutputs == 0) 34 m_nOutputs = pArray0->size(); 35 if (m_nOutputs == 0) 36 m_nOutputs = 1; 37 38 const CPDF_Array* pArray1 = pDict->GetArrayFor("C1"); 39 m_BeginValues = pdfium::Vector2D<float>(m_nOutputs, 2); 40 m_EndValues = pdfium::Vector2D<float>(m_nOutputs, 2); 41 for (uint32_t i = 0; i < m_nOutputs; i++) { 42 m_BeginValues[i] = pArray0 ? pArray0->GetNumberAt(i) : 0.0f; 43 m_EndValues[i] = pArray1 ? pArray1->GetNumberAt(i) : 1.0f; 44 } 45 46 FX_SAFE_UINT32 nOutputs = m_nOutputs; 47 nOutputs *= m_nInputs; 48 if (!nOutputs.IsValid()) 49 return false; 50 51 m_nOrigOutputs = m_nOutputs; 52 m_nOutputs = nOutputs.ValueOrDie(); 53 return true; 54 } 55 v_Call(const float * inputs,float * results) const56bool CPDF_ExpIntFunc::v_Call(const float* inputs, float* results) const { 57 for (uint32_t i = 0; i < m_nInputs; i++) { 58 for (uint32_t j = 0; j < m_nOrigOutputs; j++) { 59 results[i * m_nOrigOutputs + j] = 60 m_BeginValues[j] + FXSYS_pow(inputs[i], m_Exponent) * 61 (m_EndValues[j] - m_BeginValues[j]); 62 } 63 } 64 return true; 65 } 66