Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_expintfunc.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
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 <math.h>
10
11#include "core/fpdfapi/parser/cpdf_array.h"
12#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fpdfapi/parser/cpdf_number.h"
14#include "core/fxcrt/data_vector.h"
15#include "core/fxcrt/fx_2d_size.h"
16#include "core/fxcrt/fx_safe_types.h"
17#include "core/fxcrt/stl_util.h"
18
21
22CPDF_ExpIntFunc::~CPDF_ExpIntFunc() = default;
23
24bool CPDF_ExpIntFunc::v_Init(const CPDF_Object* pObj, VisitedSet* pVisited) {
25 RetainPtr<const CPDF_Dictionary> pDict = pObj->GetDict();
26 if (!pDict)
27 return false;
28
29 RetainPtr<const CPDF_Number> pExponent = pDict->GetNumberFor("N");
30 if (!pExponent)
31 return false;
32
33 m_Exponent = pExponent->GetNumber();
34
35 RetainPtr<const CPDF_Array> pArray0 = pDict->GetArrayFor("C0");
36 if (pArray0 && m_nOutputs == 0)
37 m_nOutputs = fxcrt::CollectionSize<uint32_t>(*pArray0);
38 if (m_nOutputs == 0)
39 m_nOutputs = 1;
40
41 RetainPtr<const CPDF_Array> pArray1 = pDict->GetArrayFor("C1");
42 m_BeginValues = DataVector<float>(Fx2DSizeOrDie(m_nOutputs, 2));
43 m_EndValues = DataVector<float>(m_BeginValues.size());
44 for (uint32_t i = 0; i < m_nOutputs; i++) {
45 m_BeginValues[i] = pArray0 ? pArray0->GetFloatAt(i) : 0.0f;
46 m_EndValues[i] = pArray1 ? pArray1->GetFloatAt(i) : 1.0f;
47 }
48
49 FX_SAFE_UINT32 nOutputs = m_nOutputs;
50 nOutputs *= m_nInputs;
51 if (!nOutputs.IsValid())
52 return false;
53
54 m_nOrigOutputs = m_nOutputs;
55 m_nOutputs = nOutputs.ValueOrDie();
56 return true;
57}
58
59bool CPDF_ExpIntFunc::v_Call(pdfium::span<const float> inputs,
60 pdfium::span<float> results) const {
61 for (uint32_t i = 0; i < m_nInputs; i++) {
62 for (uint32_t j = 0; j < m_nOrigOutputs; j++) {
63 results[i * m_nOrigOutputs + j] =
64 m_BeginValues[j] +
65 powf(inputs[i], m_Exponent) * (m_EndValues[j] - m_BeginValues[j]);
66 }
67 }
68 return true;
69}
~CPDF_ExpIntFunc() override
bool v_Init(const CPDF_Object *pObj, VisitedSet *pVisited) override
bool v_Call(pdfium::span< const float > inputs, pdfium::span< float > results) const override
uint32_t m_nOutputs
uint32_t m_nInputs
CPDF_Function(Type type)