package transformer;

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

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

	@Override
	public void t(Point p) {
		int in2d_index = 3 * (p.dy * ictx.width + p.dx);
		float r_sum = 0.0f;
		float g_sum = 0.0f;
		float b_sum = 0.0f;
		for(int i=0; i<range; ++i) {
			PixelData pdi = ictx.at(p.ti + i);
			r_sum += PixelData.unsigned(pdi.at(in2d_index));
			g_sum += PixelData.unsigned(pdi.at(in2d_index + 1));
			b_sum += PixelData.unsigned(pdi.at(in2d_index + 2));
		}
		p.r = r_sum / range;
		p.g = g_sum / range;
		p.b = b_sum / range;
	}

}
