use of org.apache.pdfbox.pdmodel.common.function.type4.ExecutionContext in project pdfbox by apache.
the class PDFunctionType4 method eval.
/**
* {@inheritDoc}
*/
@Override
public float[] eval(float[] input) throws IOException {
// Setup the input values
ExecutionContext context = new ExecutionContext(OPERATORS);
for (int i = 0; i < input.length; i++) {
PDRange domain = getDomainForInput(i);
float value = clipToRange(input[i], domain.getMin(), domain.getMax());
context.getStack().push(value);
}
// Execute the type 4 function.
instructions.execute(context);
// Extract the output values
int numberOfOutputValues = getNumberOfOutputParameters();
int numberOfActualOutputValues = context.getStack().size();
if (numberOfActualOutputValues < numberOfOutputValues) {
throw new IllegalStateException("The type 4 function returned " + numberOfActualOutputValues + " values but the Range entry indicates that " + numberOfOutputValues + " values be returned.");
}
float[] outputValues = new float[numberOfOutputValues];
for (int i = numberOfOutputValues - 1; i >= 0; i--) {
PDRange range = getRangeForOutput(i);
outputValues[i] = context.popReal();
outputValues[i] = clipToRange(outputValues[i], range.getMin(), range.getMax());
}
// Return the resulting array
return outputValues;
}
Aggregations