Last active
August 29, 2015 14:17
-
-
Save Reel-Deal/986abfec2e3a375fdcd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function aWarpSharp4xx (clip src, int "thresh", int "blur", int "type", int "depth", int "depthC", int "chroma", bool "lsb", string "cplace") | |
{ | |
depth = default(depth, 16) | |
depthC = default(depthC, src.IsYV24 ? depth : depth/2) #depth/3 is claimed to work better | |
chroma = default(chroma, 4) | |
lsb = default(lsb, false) | |
cplace = default(cplace, "MPEG2") | |
assert(src.IsPlanar, "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") | |
src8 = lsb ? src.DitherPost(mode=-1) : src | |
if (src.IsY8 || src.IsYV12 && (chroma != 4 && chroma != 6)) { | |
src8.ConvertToYV12().aWarpSharp2(thresh=thresh, blur=blur, type=type, depth=depth, chroma=src.IsY8 ? 1 : chroma) | |
src.IsY8 ? ConvertToY8() : last | |
} | |
else { | |
y = src8.ConvertToY8().ConvertToYV12() | |
u = src8.UtoY().ConvertToYV12() | |
v = src8.VtoY().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=depthC, chroma=1) | |
v_warp = aWarpSharp2(v, thresh=thresh, blur=blur, type=type, depth=depthC, chroma=1) | |
# warp chroma by guiding it with the luma edge mask | |
cshift = cplace == "MPEG2" && !src.IsYV24 ? -0.5 : 0 | |
y_mask = aSobel(y, thresh=thresh).aBlur(blur=blur, type=type).BilinearResize(u.width, u.height, cshift) | |
u_warp2 = aWarp(u, y_mask, depth=depthC, chroma=1) | |
v_warp2 = aWarp(v, y_mask, depth=depthC, chroma=1) | |
# neutral chroma plane | |
blank = u.ConvertToY8().mt_lut(y=-128) | |
# luma/chroma processing | |
if (chroma == 1 && src.IsYV12) { | |
y_warp | |
} | |
else { | |
u = Select(chroma, blank, blank, u, u_warp, u_warp2, u_warp, u_warp2) | |
v = Select(chroma, blank, blank, v, v_warp, v_warp2, v_warp, v_warp2) | |
y = chroma < 5 ? y_warp : y | |
YToUV(u,v,y) | |
} | |
} | |
if (lsb) { | |
y_ld = chroma < 5 ? 3 : 2 | |
uv_ld = Min(chroma, 3) | |
Dither_convert_8_to_16() | |
return src.Dither_limit_dif16(last, thr=1.0, elast=1.5, y=y_ld, u=uv_ld, v=uv_ld) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment