• 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_acc.h"
10 #include "third_party/base/ptr_util.h"
11 
CPDF_PSFunc()12 CPDF_PSFunc::CPDF_PSFunc() : CPDF_Function(Type::kType4PostScript) {}
13 
~CPDF_PSFunc()14 CPDF_PSFunc::~CPDF_PSFunc() {}
15 
v_Init(CPDF_Object * pObj)16 bool CPDF_PSFunc::v_Init(CPDF_Object* pObj) {
17   auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pObj->AsStream());
18   pAcc->LoadAllDataFiltered();
19   return m_PS.Parse(reinterpret_cast<const char*>(pAcc->GetData()),
20                     pAcc->GetSize());
21 }
22 
v_Call(float * inputs,float * results) const23 bool CPDF_PSFunc::v_Call(float* inputs, float* results) const {
24   CPDF_PSEngine& PS = const_cast<CPDF_PSEngine&>(m_PS);
25   PS.Reset();
26   for (uint32_t i = 0; i < m_nInputs; i++)
27     PS.Push(inputs[i]);
28   PS.Execute();
29   if (PS.GetStackSize() < m_nOutputs)
30     return false;
31   for (uint32_t i = 0; i < m_nOutputs; i++)
32     results[m_nOutputs - i - 1] = PS.Pop();
33   return true;
34 }
35