package transformer;

import timedistortion.PixelData;
import timedistortion.Point;
import timedistortion.ITransform;

public class Max extends AbstractTransformer implements ITransform {
	int range = 30;

	@Override
	public void t(Point p) {
		int in2d_index = 3 * (p.dy * ictx.width + p.dx);
		float max = Float.MIN_VALUE;
		int vi = 0;
		for(int i=0; i<range; ++i) {
			PixelData pdi = ictx.at(p.ti + i);
			p.r = PixelData.unsigned(pdi.at(in2d_index));
			p.g = PixelData.unsigned(pdi.at(in2d_index + 1));
			p.b = PixelData.unsigned(pdi.at(in2d_index + 2));
			float v = p.r + p.g + p.b;
			if(v > max) {
				max = v;
				vi = i;
			}
		}
		PixelData pd0 = ictx.at(p.ti + vi);
		p.r = PixelData.unsigned(pd0.at(in2d_index));
		p.g = PixelData.unsigned(pd0.at(in2d_index + 1));
		p.b = PixelData.unsigned(pd0.at(in2d_index + 2));
	}

}
