use of org.apache.pdfbox.pdmodel.common.PDRange in project pdfbox by apache.
the class PDFunctionType0 method eval.
/**
* {@inheritDoc}
*/
@Override
public float[] eval(float[] input) throws IOException {
// This involves linear interpolation based on a set of sample points.
// Theoretically it's not that difficult ... see section 3.9.1 of the PDF Reference.
float[] sizeValues = getSize().toFloatArray();
int bitsPerSample = getBitsPerSample();
float maxSample = (float) (Math.pow(2, bitsPerSample) - 1.0);
int numberOfInputValues = input.length;
int numberOfOutputValues = getNumberOfOutputParameters();
int[] inputPrev = new int[numberOfInputValues];
int[] inputNext = new int[numberOfInputValues];
// PDFBOX-4461
input = input.clone();
for (int i = 0; i < numberOfInputValues; i++) {
PDRange domain = getDomainForInput(i);
PDRange encodeValues = getEncodeForParameter(i);
input[i] = clipToRange(input[i], domain.getMin(), domain.getMax());
input[i] = interpolate(input[i], domain.getMin(), domain.getMax(), encodeValues.getMin(), encodeValues.getMax());
input[i] = clipToRange(input[i], 0, sizeValues[i] - 1);
inputPrev[i] = (int) Math.floor(input[i]);
inputNext[i] = (int) Math.ceil(input[i]);
}
float[] outputValues = new Rinterpol(input, inputPrev, inputNext).rinterpolate();
for (int i = 0; i < numberOfOutputValues; i++) {
PDRange range = getRangeForOutput(i);
PDRange decodeValues = getDecodeForParameter(i);
if (decodeValues == null) {
throw new IOException("Range missing in function /Decode entry");
}
outputValues[i] = interpolate(outputValues[i], 0, maxSample, decodeValues.getMin(), decodeValues.getMax());
outputValues[i] = clipToRange(outputValues[i], range.getMin(), range.getMax());
}
return outputValues;
}
Aggregations