All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.function.PDFCalculator Maven / Gradle / Ivy

/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2017 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 @LICENSE@
 *
 * ---------------
 * PDFCalculator.java
 * ---------------
 */
package org.jpedal.function;

import org.jpedal.utils.LogWriter;

/**
 * Class to handle Type 4 shading (PostScript Calculator) from a Pdf
 */
public class PDFCalculator extends PDFGenericFunction implements PDFFunction {

    private final PostScriptCompiler comp;
//    private final PostscriptFactory post;

    private final int n;

    public PDFCalculator(final byte[] stream, final float[] domain, final float[] range) {

        super(domain, range);

//        post = new PostscriptFactory(stream);
        comp = new PostScriptCompiler(stream);

        n = range.length / 2;

    }

    /**
     * Calculate the output values for this point in the shading object. (Only
     * used by Stitching)
     *
     * @return returns the shading values for this point
     */
    @Override
    public float[] computeStitch(final float[] subinput) {
        return compute(subinput);

    }

    @Override
    public float[] compute(final float[] values) {

        final float[] result = new float[n];

        try {
//            post.resetStacks(values);
//            final double[] stack = post.executePostscript();
            final double[] stack = comp.executeScript(values);

            for (int i = 0; i < n; i++) {
                result[i] = min(max((float) (stack[i]), range[i * 2]), range[i * 2 + 1]);
            }

        } catch (final Exception e) {
            LogWriter.writeLog("Exception: " + e.getMessage());
        }

        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy