package yi.iu.processor.resample;

public class MitchellResampler extends Resampler
{
    public MitchellResampler () {
        super(); fwidth=2.0;
    }
    
    public MitchellResampler(int w, int h) {
        super(w,h); fwidth=2.0;
    }


    final static double B=(1.0 / 3.0);
    final static double C=(1.0 / 3.0);
    
    public double filter(double value)
    {
        double tt;

        if (value < 0.0) value = -value;

        tt = value*value;

        if (value < 1.0) {
            value = (((12.0 - 9.0 * B - 6.0 * C) * (value * tt))
            + ((-18.0 + 12.0 * B + 6.0 * C) * tt)
            + (6.0 - 2 * B));

            return value / 6.0;
        }
        else if (value < 2.0) {
            value = (((-1.0 * B - 6.0 * C) * (value * tt))
            + ((6.0 * B + 30.0 * C) * tt)
            + ((-12.0 * B - 48.0 * C) * value)
            + (8.0 * B + 24 * C));
            return value / 6.0;
        }
        else
            return 0.0d;
    }

}