Log in

View Full Version : Invalid arguments to function, problem with defaults


sumawo13
8th September 2009, 22:30
I am writing my own function to crop and resize to mod16. My problem is that if I don't specifiy anything for the crop values, it spits out an error, even though I have set defaults. Below is my script.

function aspectratio(clip clip, int aspect_x, int aspect_y, int crop_l, int crop_t, int crop_r, int crop_b)
{
crop_l=default(crop_l,0)
crop_t=default(crop_t,0)
crop_r=default(crop_r,0)
crop_b=default(crop_b,0)

a=clip.width()
b=a/(aspect_x/aspect_y)

y=a%16
z=b%16

wid=y > 0 ? a-y : a
hit=z > 0 ? b-z : b

spline16resize(clip,wid,hit,crop_l,crop_t,crop_r,crop_b)
}

Gavino
9th September 2009, 00:23
You need to declare the appropriate arguments as being optional, so you need to put their names in quotes:
function aspectratio(clip clip, int aspect_x, int aspect_y, int "crop_l", int "crop_t", int "crop_r", int "crop_b")

Other points:
b=a/(aspect_x/aspect_y) is wrong as integer division (with truncation) will be used. Use
b=round(a/(float(aspect_x)/aspect_y))

wid=y > 0 ? a-y : a
could be simply replaced by wid = a-y
and similarly for hit

sumawo13
9th September 2009, 00:46
Thank you very much Gavino, I can't tell you how much I appreciate your help and tips on optimizing my script.