Code:
# make aWarpSharp2 work on other planar, for avs 2.6
# v1.33
function aWarpSharp4xx (clip osrc, int "thresh", int "blur", int "type", int "depth", int "chroma", int "cdepth", string "cplace", bool "bic", bool "lsb")
{
lsb = default(lsb, false)
src = lsb ? osrc.DitherPost(mode=-1) : osrc
depth = default(depth, 16)
chroma = default(chroma, 4)
cplace = default(cplace, "MPEG2")
cdepth = default(cdepth, IsYV24(src) ? depth : depth/2)
bic = default(bic, true)
Assert(IsPlanar(src), "aWarpSharp4xx: input clip must be planar YUV")
assert(0 <= chroma <= 6, "aWarpSharp4xx: argument chroma must be an integer between 0 and 6.")
assert(cplace == "MPEG2" || cplace == "MPEG1", "aWarpSharp4xx: chroma siting must be MPEG2 or MPEG1")
IsY8(src) || (IsYV12(src) && (chroma == 0 || chroma == 1 || chroma == 2)) ? \
Eval("""
warp = ConvertToYV12(src).aWarpSharp2(thresh=thresh, blur=blur, type=type, depth=depth, chroma=IsY8(src) ? 1 : chroma)
output = IsY8(src) ? ConvertToY8(warp) : warp
""") : \
Eval("""
y = ConvertToY8(src).ConvertToYV12()
u = UtoY8(src).ConvertToYV12()
v = VtoY8(src).ConvertToYV12()
# warp each channel independently
y_warp = aWarpSharp2(y, thresh=thresh, blur=blur, type=type, depth=depth, chroma=1)
u_warp = aWarpSharp2(u, thresh=thresh, blur=blur, type=type, depth=cdepth, chroma=1)
v_warp = aWarpSharp2(v, thresh=thresh, blur=blur, type=type, depth=cdepth, chroma=1)
# warp chroma by guiding it with the luma edge mask
cshift = IsYV411(src) ? -1.5 : (cplace == "MPEG1" && IsYV12(src)) || IsYV24(src) ? 0 : -0.5
y_mask = bic ? aSobel(y, thresh=thresh).aBlur(blur=blur, type=type).BicubicResize(u.width(), v.height(), src_left=cshift) : \
aSobel(y, thresh=thresh).aBlur(blur=blur, type=type).BilinearResize(u.width(), v.height(), src_left=cshift)
u_warp2 = aWarp(u, y_mask, depth=cdepth, chroma=1)
v_warp2 = aWarp(v, y_mask, depth=cdepth, chroma=1)
# "fill with zeroes"
blank = BlankClip(u, pixel_type="Y8", color_yuv=$808080)
# luma/chroma processing
output = chroma==0 || \
chroma==1 ? YtoUV( blank , blank , y_warp ) : \
chroma==2 ? YtoUV( u , v , y_warp ) : \
chroma==3 ? YtoUV( u_warp , v_warp , y_warp ) : \
chroma==4 ? YtoUV( u_warp2 , v_warp2 , y_warp ) : \
chroma==5 ? YtoUV( u_warp , v_warp , y ) : \
chroma==6 ? YtoUV( u_warp2 , v_warp2 , y ) : \
src
""")
output8_16 = lsb==true ? output.Dither_convert_8_to_16() : output
y_ld = chroma < 5 ? 3 : 2
uv_ld = Min(chroma, 3)
Return(lsb==true ? Dither_limit_dif16(osrc, output8_16, thr=1.0, elast=1.5, y=y_ld, u=uv_ld, v=uv_ld) : output8_16)
}