• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_psfunc.h"
8 
9 #include "core/fpdfapi/parser/cpdf_stream.h"
10 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
11 
CPDF_PSFunc()12 CPDF_PSFunc::CPDF_PSFunc() : CPDF_Function(Type::kType4PostScript) {}
13 
~CPDF_PSFunc()14 CPDF_PSFunc::~CPDF_PSFunc() {}
15 
v_Init(const CPDF_Object * pObj,std::set<const CPDF_Object * > * pVisited)16 bool CPDF_PSFunc::v_Init(const CPDF_Object* pObj,
17                          std::set<const CPDF_Object*>* pVisited) {
18   auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pObj->AsStream());
19   pAcc->LoadAllDataFiltered();
20   return m_PS.Parse(pAcc->GetSpan());
21 }
22 
v_Call(const float * inputs,float * results) const23 bool CPDF_PSFunc::v_Call(const float* inputs, float* results) const {
24   m_PS.Reset();
25   for (uint32_t i = 0; i < m_nInputs; i++)
26     m_PS.Push(inputs[i]);
27   m_PS.Execute();
28   if (m_PS.GetStackSize() < m_nOutputs)
29     return false;
30   for (uint32_t i = 0; i < m_nOutputs; i++)
31     results[m_nOutputs - i - 1] = m_PS.Pop();
32   return true;
33 }
34