# V3 (all previous versions are buggy, please upgrade)
# Assumes MPEG-2 chroma placement for YV12, use Spline36Resize for MPEG-1 chroma placement.
 
function Spline36ResizeMod(clip c, int target_width, int target_height, float "src_left", float "src_top", float "src_width", float "src_height"){
    Assert(isYUV(c) && !isYUY2(c), "Spline36ResizeMod only supports planar YUV")
    src_left = Default(src_left,Float(0))
    src_top = Default(src_top,Float(0))
    src_width = Default(src_width,Float(0))
    src_height = Default(src_height,Float(0))
    src_width = Max(src_width, Width(c) - src_left - Sign(src_width)*src_width) # Convert to equivalent positive src_width when src_width <= 0
    height_divide = (isYV12(c) ? 2 : 1)
    width_divide = (isYV411(c) ? 4 : isYV24(c) ? 1 : 2)
    u_plane = UToY8(c).Spline36Resize(target_width/width_divide,target_height/height_divide,(-0.5*(width_divide-1)*((src_width/target_width)-1)+src_left)/width_divide,src_top/height_divide,src_width/width_divide,src_height/height_divide)
    v_plane = VToY8(c).Spline36Resize(target_width/width_divide,target_height/height_divide,(-0.5*(width_divide-1)*((src_width/target_width)-1)+src_left)/width_divide,src_top/height_divide,src_width/width_divide,src_height/height_divide)
    y_plane = ConvertToY8(c).Spline36Resize(target_width,target_height,src_left,src_top,src_width,src_height)
    YToUV(u_plane,v_plane,y_plane)
}