1 // Copyright 2014 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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
9 #include "../../../../third_party/base/numerics/safe_conversions_impl.h"
10 #include "../../../include/fpdfapi/fpdf_module.h"
11 #include "../../../include/fpdfapi/fpdf_page.h"
12 #include "../../../include/fxcrt/fx_safe_types.h"
65 FX_BOOL Parse(CPDF_SimpleParser& parser);
66 FX_BOOL Execute(CPDF_PSEngine* pEngine);
67 CFX_PtrArray m_Operators;
69 #define PSENGINE_STACKSIZE 100
74 FX_BOOL Parse(const FX_CHAR* string, int size);
75 FX_BOOL Execute() { return m_MainProc.Execute(this); }
76 FX_BOOL DoOperator(PDF_PSOP op);
77 void Reset() { m_StackCount = 0; }
78 void Push(FX_FLOAT value);
79 void Push(int value) { Push((FX_FLOAT)value); }
81 int GetStackSize() { return m_StackCount; }
84 FX_FLOAT m_Stack[PSENGINE_STACKSIZE];
86 CPDF_PSProc m_MainProc;
88 CPDF_PSProc::~CPDF_PSProc() {
89 int size = m_Operators.GetSize();
90 for (int i = 0; i < size; i++) {
91 if (m_Operators[i] == (void*)PSOP_PROC) {
92 delete (CPDF_PSProc*)m_Operators[i + 1];
94 } else if (m_Operators[i] == (void*)PSOP_CONST) {
95 FX_Free((FX_FLOAT*)m_Operators[i + 1]);
100 FX_BOOL CPDF_PSProc::Execute(CPDF_PSEngine* pEngine) {
101 int size = m_Operators.GetSize();
102 for (int i = 0; i < size; i++) {
103 PDF_PSOP op = (PDF_PSOP)(uintptr_t)m_Operators[i];
104 if (op == PSOP_PROC) {
106 } else if (op == PSOP_CONST) {
107 pEngine->Push(*(FX_FLOAT*)m_Operators[i + 1]);
109 } else if (op == PSOP_IF) {
110 if (i < 2 || m_Operators[i - 2] != (void*)PSOP_PROC) {
113 if ((int)pEngine->Pop()) {
114 ((CPDF_PSProc*)m_Operators[i - 1])->Execute(pEngine);
116 } else if (op == PSOP_IFELSE) {
117 if (i < 4 || m_Operators[i - 2] != (void*)PSOP_PROC ||
118 m_Operators[i - 4] != (void*)PSOP_PROC) {
121 if ((int)pEngine->Pop()) {
122 ((CPDF_PSProc*)m_Operators[i - 3])->Execute(pEngine);
124 ((CPDF_PSProc*)m_Operators[i - 1])->Execute(pEngine);
127 pEngine->DoOperator(op);
132 CPDF_PSEngine::CPDF_PSEngine() {
135 CPDF_PSEngine::~CPDF_PSEngine() {}
136 void CPDF_PSEngine::Push(FX_FLOAT v) {
137 if (m_StackCount == 100) {
140 m_Stack[m_StackCount++] = v;
142 FX_FLOAT CPDF_PSEngine::Pop() {
143 if (m_StackCount == 0) {
146 return m_Stack[--m_StackCount];
148 const struct _PDF_PSOpName {
151 } _PDF_PSOpNames[] = {{"add", PSOP_ADD}, {"sub", PSOP_SUB},
152 {"mul", PSOP_MUL}, {"div", PSOP_DIV},
153 {"idiv", PSOP_IDIV}, {"mod", PSOP_MOD},
154 {"neg", PSOP_NEG}, {"abs", PSOP_ABS},
155 {"ceiling", PSOP_CEILING}, {"floor", PSOP_FLOOR},
156 {"round", PSOP_ROUND}, {"truncate", PSOP_TRUNCATE},
157 {"sqrt", PSOP_SQRT}, {"sin", PSOP_SIN},
158 {"cos", PSOP_COS}, {"atan", PSOP_ATAN},
159 {"exp", PSOP_EXP}, {"ln", PSOP_LN},
160 {"log", PSOP_LOG}, {"cvi", PSOP_CVI},
161 {"cvr", PSOP_CVR}, {"eq", PSOP_EQ},
162 {"ne", PSOP_NE}, {"gt", PSOP_GT},
163 {"ge", PSOP_GE}, {"lt", PSOP_LT},
164 {"le", PSOP_LE}, {"and", PSOP_AND},
165 {"or", PSOP_OR}, {"xor", PSOP_XOR},
166 {"not", PSOP_NOT}, {"bitshift", PSOP_BITSHIFT},
167 {"true", PSOP_TRUE}, {"false", PSOP_FALSE},
168 {"if", PSOP_IF}, {"ifelse", PSOP_IFELSE},
169 {"pop", PSOP_POP}, {"exch", PSOP_EXCH},
170 {"dup", PSOP_DUP}, {"copy", PSOP_COPY},
171 {"index", PSOP_INDEX}, {"roll", PSOP_ROLL},
173 FX_BOOL CPDF_PSEngine::Parse(const FX_CHAR* string, int size) {
174 CPDF_SimpleParser parser((uint8_t*)string, size);
175 CFX_ByteStringC word = parser.GetWord();
176 if (word != FX_BSTRC("{")) {
179 return m_MainProc.Parse(parser);
181 FX_BOOL CPDF_PSProc::Parse(CPDF_SimpleParser& parser) {
183 CFX_ByteStringC word = parser.GetWord();
184 if (word.IsEmpty()) {
187 if (word == FX_BSTRC("}")) {
190 if (word == FX_BSTRC("{")) {
191 CPDF_PSProc* pProc = new CPDF_PSProc;
192 m_Operators.Add((void*)PSOP_PROC);
193 m_Operators.Add(pProc);
194 if (!pProc->Parse(parser)) {
199 while (_PDF_PSOpNames[i].name) {
200 if (word == CFX_ByteStringC(_PDF_PSOpNames[i].name)) {
201 m_Operators.Add((void*)_PDF_PSOpNames[i].op);
206 if (_PDF_PSOpNames[i].name == NULL) {
207 FX_FLOAT* pd = FX_Alloc(FX_FLOAT, 1);
209 m_Operators.Add((void*)PSOP_CONST);
215 #define PI 3.1415926535897932384626433832795f
216 FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) {
256 Push((FX_FLOAT)FXSYS_fabs(d1));
260 Push((FX_FLOAT)FXSYS_ceil(d1));
264 Push((FX_FLOAT)FXSYS_floor(d1));
268 Push(FXSYS_round(d1));
276 Push((FX_FLOAT)FXSYS_sqrt(d1));
280 Push((FX_FLOAT)FXSYS_sin(d1 * PI / 180.0f));
284 Push((FX_FLOAT)FXSYS_cos(d1 * PI / 180.0f));
289 d1 = (FX_FLOAT)(FXSYS_atan2(d1, d2) * 180.0 / PI);
298 Push((FX_FLOAT)FXSYS_pow(d1, d2));
302 Push((FX_FLOAT)FXSYS_log(d1));
306 Push((FX_FLOAT)FXSYS_log10(d1));
317 Push((int)(d1 == d2));
322 Push((int)(d1 != d2));
327 Push((int)(d1 > d2));
332 Push((int)(d1 >= d2));
337 Push((int)(d1 < d2));
342 Push((int)(d1 <= d2));
363 case PSOP_BITSHIFT: {
364 int shift = (int)Pop();
395 if (n < 0 || n > PSENGINE_STACKSIZE ||
396 m_StackCount + n > PSENGINE_STACKSIZE || n > m_StackCount) {
399 for (int i = 0; i < n; i++) {
400 m_Stack[m_StackCount + i] = m_Stack[m_StackCount + i - n];
407 if (n < 0 || n >= m_StackCount) {
410 Push(m_Stack[m_StackCount - n - 1]);
416 if (m_StackCount == 0) {
419 if (n < 0 || n > m_StackCount) {
423 for (int i = 0; i < -j; i++) {
424 FX_FLOAT first = m_Stack[m_StackCount - n];
425 for (int ii = 0; ii < n - 1; ii++) {
426 m_Stack[m_StackCount - n + ii] = m_Stack[m_StackCount - n + ii + 1];
428 m_Stack[m_StackCount - 1] = first;
431 for (int i = 0; i < j; i++) {
432 FX_FLOAT last = m_Stack[m_StackCount - 1];
434 for (ii = 0; ii < n - 1; ii++) {
435 m_Stack[m_StackCount - ii - 1] = m_Stack[m_StackCount - ii - 2];
437 m_Stack[m_StackCount - ii - 1] = last;
446 static FX_FLOAT PDF_Interpolate(FX_FLOAT x,
451 return ((x - xmin) * (ymax - ymin) / (xmax - xmin)) + ymin;
453 static FX_DWORD _GetBits32(const uint8_t* pData, int bitpos, int nbits) {
455 for (int i = 0; i < nbits; i++)
456 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) {
457 result |= 1 << (nbits - i - 1);
462 FX_FLOAT encode_max, encode_min;
465 typedef struct { FX_FLOAT decode_max, decode_min; } SampleDecodeInfo;
467 class CPDF_SampledFunc : public CPDF_Function {
470 ~CPDF_SampledFunc() override;
473 FX_BOOL v_Init(CPDF_Object* pObj) override;
474 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
476 SampleEncodeInfo* m_pEncodeInfo;
477 SampleDecodeInfo* m_pDecodeInfo;
478 FX_DWORD m_nBitsPerSample;
479 FX_DWORD m_SampleMax;
480 CPDF_StreamAcc* m_pSampleStream;
483 CPDF_SampledFunc::CPDF_SampledFunc() {
484 m_pSampleStream = NULL;
485 m_pEncodeInfo = NULL;
486 m_pDecodeInfo = NULL;
488 CPDF_SampledFunc::~CPDF_SampledFunc() {
489 delete m_pSampleStream;
490 FX_Free(m_pEncodeInfo);
491 FX_Free(m_pDecodeInfo);
493 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) {
494 if (pObj->GetType() != PDFOBJ_STREAM) {
497 CPDF_Stream* pStream = (CPDF_Stream*)pObj;
498 CPDF_Dictionary* pDict = pStream->GetDict();
499 CPDF_Array* pSize = pDict->GetArray(FX_BSTRC("Size"));
500 CPDF_Array* pEncode = pDict->GetArray(FX_BSTRC("Encode"));
501 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode"));
502 m_nBitsPerSample = pDict->GetInteger(FX_BSTRC("BitsPerSample"));
503 if (m_nBitsPerSample > 32) {
506 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample);
507 m_pSampleStream = new CPDF_StreamAcc;
508 m_pSampleStream->LoadAllData(pStream, FALSE);
509 m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs);
510 FX_SAFE_DWORD nTotalSampleBits = 1;
511 for (int i = 0; i < m_nInputs; i++) {
512 m_pEncodeInfo[i].sizes = pSize ? pSize->GetInteger(i) : 0;
513 if (!pSize && i == 0) {
514 m_pEncodeInfo[i].sizes = pDict->GetInteger(FX_BSTRC("Size"));
516 nTotalSampleBits *= m_pEncodeInfo[i].sizes;
518 m_pEncodeInfo[i].encode_min = pEncode->GetFloat(i * 2);
519 m_pEncodeInfo[i].encode_max = pEncode->GetFloat(i * 2 + 1);
521 m_pEncodeInfo[i].encode_min = 0;
522 if (m_pEncodeInfo[i].sizes == 1) {
523 m_pEncodeInfo[i].encode_max = 1;
525 m_pEncodeInfo[i].encode_max = (FX_FLOAT)m_pEncodeInfo[i].sizes - 1;
529 nTotalSampleBits *= m_nBitsPerSample;
530 nTotalSampleBits *= m_nOutputs;
531 FX_SAFE_DWORD nTotalSampleBytes = nTotalSampleBits;
532 nTotalSampleBytes += 7;
533 nTotalSampleBytes /= 8;
534 if (!nTotalSampleBytes.IsValid() || nTotalSampleBytes.ValueOrDie() == 0 ||
535 nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) {
538 m_pDecodeInfo = FX_Alloc(SampleDecodeInfo, m_nOutputs);
539 for (int i = 0; i < m_nOutputs; i++) {
541 m_pDecodeInfo[i].decode_min = pDecode->GetFloat(2 * i);
542 m_pDecodeInfo[i].decode_max = pDecode->GetFloat(2 * i + 1);
544 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2];
545 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1];
550 FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const {
552 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs);
553 FX_FLOAT* encoded_input = encoded_input_buf;
554 CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2);
555 int* index = int_buf;
556 int* blocksize = index + m_nInputs;
557 for (int i = 0; i < m_nInputs; i++) {
561 blocksize[i] = blocksize[i - 1] * m_pEncodeInfo[i - 1].sizes;
563 encoded_input[i] = PDF_Interpolate(
564 inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1],
565 m_pEncodeInfo[i].encode_min, m_pEncodeInfo[i].encode_max);
566 index[i] = (int)encoded_input[i];
569 } else if (index[i] > m_pEncodeInfo[i].sizes - 1) {
570 index[i] = m_pEncodeInfo[i].sizes - 1;
572 pos += index[i] * blocksize[i];
574 FX_SAFE_INT32 bits_to_output = m_nOutputs;
575 bits_to_output *= m_nBitsPerSample;
576 if (!bits_to_output.IsValid()) {
579 FX_SAFE_INT32 bitpos = pos;
580 bitpos *= bits_to_output.ValueOrDie();
581 if (!bitpos.IsValid()) {
584 FX_SAFE_INT32 range_check = bitpos;
585 range_check += bits_to_output.ValueOrDie();
586 if (!range_check.IsValid()) {
589 const uint8_t* pSampleData = m_pSampleStream->GetData();
593 for (int j = 0; j < m_nOutputs; j++) {
595 _GetBits32(pSampleData, bitpos.ValueOrDie() + j * m_nBitsPerSample,
597 FX_FLOAT encoded = (FX_FLOAT)sample;
598 for (int i = 0; i < m_nInputs; i++) {
599 if (index[i] == m_pEncodeInfo[i].sizes - 1) {
601 encoded = encoded_input[i] * (FX_FLOAT)sample;
604 FX_SAFE_INT32 bitpos2 = blocksize[i];
606 bitpos2 *= m_nOutputs;
608 bitpos2 *= m_nBitsPerSample;
609 if (!bitpos2.IsValid()) {
613 _GetBits32(pSampleData, bitpos2.ValueOrDie(), m_nBitsPerSample);
614 encoded += (encoded_input[i] - index[i]) *
615 ((FX_FLOAT)sample1 - (FX_FLOAT)sample);
618 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax,
619 m_pDecodeInfo[j].decode_min,
620 m_pDecodeInfo[j].decode_max);
625 class CPDF_PSFunc : public CPDF_Function {
628 FX_BOOL v_Init(CPDF_Object* pObj) override;
629 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
634 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) {
635 CPDF_Stream* pStream = (CPDF_Stream*)pObj;
637 acc.LoadAllData(pStream, FALSE);
638 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize());
640 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const {
641 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS;
644 for (i = 0; i < m_nInputs; i++) {
648 if (PS.GetStackSize() < m_nOutputs) {
651 for (i = 0; i < m_nOutputs; i++) {
652 results[m_nOutputs - i - 1] = PS.Pop();
657 class CPDF_ExpIntFunc : public CPDF_Function {
660 ~CPDF_ExpIntFunc() override;
663 FX_BOOL v_Init(CPDF_Object* pObj) override;
664 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
667 FX_FLOAT* m_pBeginValues;
668 FX_FLOAT* m_pEndValues;
672 CPDF_ExpIntFunc::CPDF_ExpIntFunc() {
673 m_pBeginValues = NULL;
676 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() {
677 FX_Free(m_pBeginValues);
678 FX_Free(m_pEndValues);
680 FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) {
681 CPDF_Dictionary* pDict = pObj->GetDict();
685 CPDF_Array* pArray0 = pDict->GetArray(FX_BSTRC("C0"));
686 if (m_nOutputs == 0) {
689 m_nOutputs = pArray0->GetCount();
692 CPDF_Array* pArray1 = pDict->GetArray(FX_BSTRC("C1"));
693 m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
694 m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
695 for (int i = 0; i < m_nOutputs; i++) {
696 m_pBeginValues[i] = pArray0 ? pArray0->GetFloat(i) : 0.0f;
697 m_pEndValues[i] = pArray1 ? pArray1->GetFloat(i) : 1.0f;
699 m_Exponent = pDict->GetFloat(FX_BSTRC("N"));
700 m_nOrigOutputs = m_nOutputs;
701 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) {
704 m_nOutputs *= m_nInputs;
707 FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const {
708 for (int i = 0; i < m_nInputs; i++)
709 for (int j = 0; j < m_nOrigOutputs; j++) {
710 results[i * m_nOrigOutputs + j] =
712 (FX_FLOAT)FXSYS_pow(inputs[i], m_Exponent) *
713 (m_pEndValues[j] - m_pBeginValues[j]);
718 class CPDF_StitchFunc : public CPDF_Function {
721 ~CPDF_StitchFunc() override;
724 FX_BOOL v_Init(CPDF_Object* pObj) override;
725 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
728 CPDF_Function** m_pSubFunctions;
733 CPDF_StitchFunc::CPDF_StitchFunc() {
735 m_pSubFunctions = NULL;
739 CPDF_StitchFunc::~CPDF_StitchFunc() {
740 for (int i = 0; i < m_nSubs; i++)
741 delete m_pSubFunctions[i];
742 FX_Free(m_pSubFunctions);
746 FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) {
747 CPDF_Dictionary* pDict = pObj->GetDict();
751 CPDF_Array* pArray = pDict->GetArray(FX_BSTRC("Functions"));
752 if (pArray == NULL) {
755 m_nSubs = pArray->GetCount();
759 m_pSubFunctions = FX_Alloc(CPDF_Function*, m_nSubs);
762 for (i = 0; i < m_nSubs; i++) {
763 CPDF_Object* pSub = pArray->GetElementValue(i);
767 m_pSubFunctions[i] = CPDF_Function::Load(pSub);
768 if (m_pSubFunctions[i] == NULL) {
771 if (m_pSubFunctions[i]->CountOutputs() > m_nOutputs) {
772 m_nOutputs = m_pSubFunctions[i]->CountOutputs();
775 m_pBounds = FX_Alloc(FX_FLOAT, m_nSubs + 1);
776 m_pBounds[0] = m_pDomains[0];
777 pArray = pDict->GetArray(FX_BSTRC("Bounds"));
778 if (pArray == NULL) {
781 for (i = 0; i < m_nSubs - 1; i++) {
782 m_pBounds[i + 1] = pArray->GetFloat(i);
784 m_pBounds[m_nSubs] = m_pDomains[1];
785 m_pEncode = FX_Alloc2D(FX_FLOAT, m_nSubs, 2);
786 pArray = pDict->GetArray(FX_BSTRC("Encode"));
787 if (pArray == NULL) {
790 for (i = 0; i < m_nSubs * 2; i++) {
791 m_pEncode[i] = pArray->GetFloat(i);
795 FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const {
796 FX_FLOAT input = inputs[0];
798 for (i = 0; i < m_nSubs - 1; i++)
799 if (input < m_pBounds[i + 1]) {
802 if (m_pSubFunctions[i] == NULL) {
805 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1],
806 m_pEncode[i * 2], m_pEncode[i * 2 + 1]);
808 m_pSubFunctions[i]->Call(&input, m_nInputs, outputs, nresults);
811 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) {
812 if (pFuncObj == NULL) {
815 CPDF_Function* pFunc = NULL;
817 if (pFuncObj->GetType() == PDFOBJ_STREAM) {
818 type = ((CPDF_Stream*)pFuncObj)
820 ->GetInteger(FX_BSTRC("FunctionType"));
821 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) {
822 type = pDict->GetInteger(FX_BSTRC("FunctionType"));
827 pFunc = new CPDF_SampledFunc;
828 } else if (type == 2) {
829 pFunc = new CPDF_ExpIntFunc;
830 } else if (type == 3) {
831 pFunc = new CPDF_StitchFunc;
832 } else if (type == 4) {
833 pFunc = new CPDF_PSFunc;
837 if (!pFunc->Init(pFuncObj)) {
843 CPDF_Function::CPDF_Function() {
847 CPDF_Function::~CPDF_Function() {
851 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) {
852 CPDF_Dictionary* pDict;
853 if (pObj->GetType() == PDFOBJ_STREAM) {
854 pDict = ((CPDF_Stream*)pObj)->GetDict();
856 pDict = pObj->AsDictionary();
858 CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain"));
859 if (pDomains == NULL) {
862 m_nInputs = pDomains->GetCount() / 2;
863 if (m_nInputs == 0) {
866 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2);
867 for (int i = 0; i < m_nInputs * 2; i++) {
868 m_pDomains[i] = pDomains->GetFloat(i);
870 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range"));
873 m_nOutputs = pRanges->GetCount() / 2;
874 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
875 for (int i = 0; i < m_nOutputs * 2; i++) {
876 m_pRanges[i] = pRanges->GetFloat(i);
879 FX_DWORD old_outputs = m_nOutputs;
883 if (m_pRanges && m_nOutputs > (int)old_outputs) {
884 m_pRanges = FX_Realloc(FX_FLOAT, m_pRanges, m_nOutputs * 2);
886 FXSYS_memset(m_pRanges + (old_outputs * 2), 0,
887 sizeof(FX_FLOAT) * (m_nOutputs - old_outputs) * 2);
892 FX_BOOL CPDF_Function::Call(FX_FLOAT* inputs,
895 int& nresults) const {
896 if (m_nInputs != ninputs) {
899 nresults = m_nOutputs;
900 for (int i = 0; i < m_nInputs; i++) {
901 if (inputs[i] < m_pDomains[i * 2]) {
902 inputs[i] = m_pDomains[i * 2];
903 } else if (inputs[i] > m_pDomains[i * 2 + 1]) {
904 inputs[i] = m_pDomains[i * 2] + 1;
907 v_Call(inputs, results);
909 for (int i = 0; i < m_nOutputs; i++) {
910 if (results[i] < m_pRanges[i * 2]) {
911 results[i] = m_pRanges[i * 2];
912 } else if (results[i] > m_pRanges[i * 2 + 1]) {
913 results[i] = m_pRanges[i * 2 + 1];