Search in sources :

Example 16 with PDRange

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;
}
Also used : PDRange(org.apache.pdfbox.pdmodel.common.PDRange) IOException(java.io.IOException)

Aggregations

PDRange (org.apache.pdfbox.pdmodel.common.PDRange)16 COSDictionary (org.apache.pdfbox.cos.COSDictionary)7 EOFException (java.io.EOFException)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 ImageInputStream (javax.imageio.stream.ImageInputStream)6 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)6 COSArray (org.apache.pdfbox.cos.COSArray)6 COSStream (org.apache.pdfbox.cos.COSStream)6 Point2D (java.awt.geom.Point2D)5 Paint (java.awt.Paint)2 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 WritableRaster (java.awt.image.WritableRaster)1 ExecutionContext (org.apache.pdfbox.pdmodel.common.function.type4.ExecutionContext)1 Test (org.junit.jupiter.api.Test)1