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

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

There is a newer version: 20151002
Show newest version
/*
 * ===========================================
 * 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
 *
     This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


 *
 * ---------------
 * PDFStitching.java
 * ---------------
 */

package org.jpedal.function;

/**
 * Class to handle Type 3 shading (Stitching) in PDF
 */
public class PDFStitching extends PDFGenericFunction implements PDFFunction {

	/**
	 * composed of other Functions
	 */
	private PDFFunction[] functions;
	private float[] bounds;
	
	public PDFStitching(final PDFFunction[] functions, final float[] encode, final float[] bounds, final float[] domain, final float[] range) {

		//setup global values needed
		super(domain, range);

		if (bounds!= null) {
            this.bounds = bounds;
        }
		
		if (encode!= null) {
            this.encode = encode;
        }

        if(functions!=null) {
            this.functions = functions;
        }

        //n = encode.length/2;
	}
	
	/**
	 * Calculate shading for current location
	 * 
	 * @param values input values for shading calculation
	 * @return float[] containing the color values for shading at this point
	 */
	@Override
    public float[] compute(final float[] values){
        
//        if(functions.length == 1){
//            float x = min(max(values[0],domain[0]),domain[1]);
//            x = encode[0]+(x-domain[0])*(encode[1]-encode[0])/(domain[1]-domain[0]);
//            float[] vv = functions[0].compute(new float[]{x}); 
//            vv[0] = 1-vv[0];
//            return vv;
//        }

        //take raw input number
        final float x=min(max(values[0],domain[0*2]),domain[0*2+1]);

        //hack for error in a PDF
        if(bounds==null) {
            bounds = new float[0];
        }
       
        //see if value lies outside a boundary
        int subi=bounds.length-1;
        for(; subi>=0; subi--) {
            if (x >= bounds[subi]) {
                break;
            }
        }
        subi++;


        //if it does, truncate it
        final float[] subinput = new float[1];
        float xmin=domain[0],xmax=domain[1];
        if(subi>0) {
            xmin = (bounds[subi - 1]);
        }
        if(subi=0; subi--){
            if (x >= bounds[subi]) {
                break;
            }
        }
        subi++;

        //if it does, truncate it
        final float[] subinput = new float[1];
        float xmin=domain[0],xmax=domain[1];
        if(subi>0) {
            xmin = (bounds[subi - 1]);
        }
        if(subi




© 2015 - 2024 Weber Informatics LLC | Privacy Policy