Skip to content

Instantly share code, notes, and snippets.

@line0
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save line0/7518e4c9d5014275bac0 to your computer and use it in GitHub Desktop.
Save line0/7518e4c9d5014275bac0 to your computer and use it in GitHub Desktop.
function aWarpSharp4xx16 (clip src, int "thresh", int "blur", int "type", int "depth", int "chroma", bool "lsb", string "cplace")
{
chroma = default(chroma, 4)
lsb = default(lsb, false)
cplace = default(cplace, "MPEG2")
assert(src.IsPlanar, "aWarpSharp4xx16: input clip must be planar YUV")
assert(0 <= chroma <= 6, "aWarpSharp4xx16: argument chroma must be an integer between 0 and 6.")
assert(cplace == "MPEG2" || cplace == "MPEG1", "aWarpSharp4xx16: chroma siting must be MPEG2 or MPEG1")
src8 = lsb ? src.DitherPost(mode=-1) : src
if (src.IsY8 || src.IsYV12 && (chroma == 4 or 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()
v = src8.VtoY()
# 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=depth, chroma=1)
v_warp = aWarpSharp2(v, thresh=thresh, blur=blur, type=type, depth=depth, 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=depth, chroma=1)
v_warp2 = aWarp(v, y_mask, depth=depth, 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