Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
30th November 2014, 02:25 | #1 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,664
|
aWarpSharp4xx: a script similar to aWarpSharp2 but supports all planar colorspaces
I recently had to process a handful a pictures which where 4:2:2. Unfortunately aWarpSharp2 only works with YV12, so I came up with aWarpSharp4xx, a wrapper function that allows aWarpSharp2 to be used with any planar YUV colorspace.
Usage is almost identical, the only difference is that when processing YV16/YV24/YV411 chroma=1 is identical to chroma=0. When processing Y8 or YV12 aWarpSharp2() is used directly so it will be faster and more memory efficient than processing other colorspaces. Obvious requirements are AviSynth 2.6 and aWarpSharp2. Hopefully someone will find this useful One thing I'm unsure about is the scaling of the luma mask used to guide the chroma. Right now I'm just using BicubicResize() to scale the mask to the appropriate dimensions. Would interesting to know how aWarpSharp2() does this internally. Code:
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(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") src8 = lsb ? src.DitherPost(mode=-1) : src IsY8(src) || IsYV12(src) && (chroma != 4 && chroma != 6) ? \ Eval(""" warp = ConvertToYV12(src8).aWarpSharp2(thresh=thresh, blur=blur, type=type, depth=depth, chroma=IsY8(src) ? 1 : chroma) output = IsY8(src) ? ConvertToY8(warp) : warp """) : \ Eval(""" y = ConvertToY8(src8).ConvertToYV12() u = UtoY(src8).ConvertToYV12() v = VtoY(src8).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(), v.height(), src_left=cshift) u_warp2 = aWarp(u, y_mask, depth=depthC, chroma=1) v_warp2 = aWarp(v, y_mask, depth=depthC, 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 ) : \ src8 """) output8_16 = lsb==true ? output.Dither_convert_8_to_16() : output y_ld = chroma < 5 ? 3 : 2 uv_ld = Min(chroma, 3) output16 = Dither_limit_dif16(src, output8_16, thr=1.0, elast=1.5, y=y_ld, u=uv_ld, v=uv_ld) Return(lsb==true ? output16 : output8_16) } Last edited by Reel.Deel; 31st March 2015 at 18:40. Reason: add updated script |
Thread Tools | Search this Thread |
Display Modes | |
|
|