###################################################################################
#
# This AviSynth function stretches the red, green and/or blue channel according to
# a given factor symmetrically around the center of the frame and crops it afterwards.
#
# Parameters: clip, red{1,...}, green{1,...}, blue{1,000}
# red, green and blue are stretching (resizing) factors against the original clip size.
# The function returns the clip in RGB24 colorspace.
#
# Factors of e.g. red=1.015, green=1.01 allow to compensate the colored edge near the
# corners of the image which appear from lenses with 'chromatic aberration'.
#
# Note that chromatic aberration also smears the image a bit, which is not compensated
# by this function.
#
# Martin Wagener at gmx.de, 03/24/2007
#
###################################################################################

function FixChromaticAberration(clip "clip", val "red", val "green", val "blue")
{
	r= default(red,1)
	g= default(green,1)
	b= default(blue,1)
	r= (r<1)?1:r
	g= (g<1)?1:g
	b= (b<1)?1:b
	c= ConvertToRGB24(clip)
	w= c.Width()
	h= c.Height()
	MergeRGB((r>1) ? LanczosResize(c, Round(r*w),Round(r*h)).Crop(Round((r-1)*w*0.5),Round((r-1)*h*0.5),w,h) : c, \
		 	 (g>1) ? LanczosResize(c, Round(g*w),Round(g*h)).Crop(Round((g-1)*w*0.5),Round((g-1)*h*0.5),w,h) : c, \
		 	 (b>1) ? LanczosResize(c, Round(b*w),Round(b*h)).Crop(Round((b-1)*w*0.5),Round((b-1)*h*0.5),w,h) : c)
	return(last)
}