Advertisement
Guest User

aWarpSharp4xx

a guest
Oct 24th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # make aWarpSharp2 work on other planar, for avs 2.6
  2. # v1.34 make it like original aWarpSharp2
  3.  
  4. function aWarpSharp4xx (clip osrc, int "thresh", int "blur", int "type", int "depth", int "chroma", int "cdepth", string "cplace", bool "bic", int "cblur", bool "lsb")
  5. {
  6.  
  7. lsb    = default(lsb, false)
  8. src = lsb ? osrc.DitherPost(mode=-1) : osrc
  9.  
  10. depth  = default(depth, 16)
  11. type   = default(type ,  0)
  12. blur   = default(blur , type==0 ? 2 : 3)
  13. chroma = default(chroma, 4)
  14. cplace = default(cplace, "MPEG2")
  15. cdepth = default(cdepth, IsYV24(src) ? depth : depth/2)
  16. cblur  = default(cblur, IsYV24(src) ? blur : (blur+1)/2)
  17. bic    = default(bic, true)
  18.  
  19. Assert(IsPlanar(src), "aWarpSharp4xx: input clip must be planar YUV")
  20. assert(0 <= chroma <= 6, "aWarpSharp4xx: argument chroma must be an integer between 0 and 6.")  
  21. assert(cplace == "MPEG2" || cplace == "MPEG1", "aWarpSharp4xx: chroma siting must be MPEG2 or MPEG1")
  22.  
  23. IsY8(src) || (IsYV12(src) && (chroma == 0 || chroma == 1 || chroma == 2)) ? \
  24. Eval("""
  25. warp   = ConvertToYV12(src).aWarpSharp2(thresh=thresh, blur=blur, type=type, depth=depth, chroma=IsY8(src) ? 1 : chroma)
  26. output = IsY8(src) ? ConvertToY8(warp) : warp
  27. """) : \
  28. Eval("""
  29. y = ConvertToY8(src).ConvertToYV12()
  30. u = UtoY8(src).ConvertToYV12()
  31. v = VtoY8(src).ConvertToYV12()
  32.  
  33. # warp each channel independently
  34. y_warp = aWarpSharp2(y, thresh=thresh, blur=blur, type=type, depth=depth, chroma=1)
  35. u_warp = aWarpSharp2(u, thresh=thresh, blur=cblur, type=type, depth=cdepth, chroma=1)
  36. v_warp = aWarpSharp2(v, thresh=thresh, blur=cblur, type=type, depth=cdepth, chroma=1)
  37.  
  38. # warp chroma by guiding it with the luma edge mask
  39. cshift = IsYV411(src) ? -1.5 : (cplace == "MPEG1" && IsYV12(src)) || IsYV24(src) ? 0 : -0.5
  40. y_mask  = bic ? aSobel(y, thresh=thresh).aBlur(blur=blur, type=type).BicubicResize(u.width(), v.height(), src_left=cshift) : \
  41. aSobel(y, thresh=thresh).aBlur(blur=blur, type=type).BilinearResize(u.width(), v.height(), src_left=cshift)
  42. u_warp2 = aWarp(u, y_mask, depth=cdepth, chroma=1)
  43. v_warp2 = aWarp(v, y_mask, depth=cdepth, chroma=1)
  44.  
  45. # "fill with zeroes"
  46. blank = BlankClip(u, pixel_type="Y8", color_yuv=$808080)
  47.  
  48. # luma/chroma processing
  49. output = chroma==0 ||                                      \
  50.         chroma==1 ? YtoUV( blank   , blank   , y_warp ) : \
  51.         chroma==2 ? YtoUV( u       , v       , y_warp ) : \
  52.         chroma==3 ? YtoUV( u_warp  , v_warp  , y_warp ) : \
  53.         chroma==4 ? YtoUV( u_warp2 , v_warp2 , y_warp ) : \
  54.         chroma==5 ? YtoUV( u_warp  , v_warp  , y      ) : \
  55.         chroma==6 ? YtoUV( u_warp2 , v_warp2 , y      ) : \
  56.         src
  57. """)
  58. output8_16 = lsb==true ? output.Dither_convert_8_to_16() : output
  59. y_ld  = chroma < 5 ? 3 : 2
  60. uv_ld = Min(chroma, 3)
  61. 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)
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement