Guest User

aWarpSharp4xx

a guest
Jan 28th, 2017
285
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. # mod to make it faster with last aWarpSharp2 and add aWarp4, v1.38
  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 "useaWarp4", clip "y_mask", 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. useaW4 = default(useaWarp4, false)
  19.  
  20. Assert(IsPlanar(src) && isyuv(src), "aWarpSharp4xx: input clip must be planar YUV")
  21. assert(0 <= chroma <= 6, "aWarpSharp4xx: argument chroma must be an integer between 0 and 6.")  
  22. assert(cplace == "MPEG2" || cplace == "MPEG1", "aWarpSharp4xx: chroma siting must be MPEG2 or MPEG1")
  23. Assert(Defined(y_mask) ? isy8(y_mask) : true, "aWarpSharp4xx: y_mask clip must be Y8")
  24.  
  25. !Defined(y_mask) || !useaW4 || (IsY8(src) || (IsYV12(src) && (chroma == 0 || chroma == 1 || chroma == 2))) ? \
  26. Eval("""
  27. output = src.aWarpSharp2(thresh=thresh, blur=blur, type=type, depth=depth, chroma=chroma, depthC=cdepth, cplace=cplace)
  28. """) : \
  29. Eval("""
  30. chrgu = chroma == 4 || chroma == 6
  31. y = chroma > 2 && !(chroma > 4 && Defined(y_mask)) ? ConvertToY8(src) : src
  32. u = chroma > 2 ? UtoY8(src) : nop()
  33. v = chroma > 2 ? VtoY8(src) : nop()
  34.  
  35. y_mask  = Defined(y_mask) ? y_mask : useaW4 || chrgu ? aSobel(y, thresh=thresh).aBlur(blur=blur,  type=type) : nop()
  36. cshift  = chrgu ? IsYV411(src) ? -1.5 : (cplace == "MPEG1" && IsYV12(src)) ? 0 : -0.5 : nop()
  37. uv_mask = chrgu ? IsYV24(src) ? y_mask : bic ? y_mask.BicubicResize(u.width(), v.height(), src_left=cshift) : y_mask.BilinearResize(u.width(), v.height(), src_left=cshift) : nop()
  38. u_mask  = chrgu ? uv_mask : chroma > 2 ? aSobel(u, thresh=thresh).aBlur(blur=cblur, type=type) : nop()
  39. v_mask  = chrgu ? uv_mask : chroma > 2 ? aSobel(v, thresh=thresh).aBlur(blur=cblur, type=type) : nop()
  40.  
  41. y = chroma < 5 ? useaW4 ? y.nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2) : y : y
  42. u = chroma > 2 ? useaW4 ? U.nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2) : u : nop()
  43. v = chroma > 2 ? useaW4 ? V.nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2) : v : nop()
  44.  
  45. # warp each channel independently
  46. y_warp = chroma < 5 ? useaW4 ? aWarp4(y, y_mask,  depth=depth, chroma=chroma, cplace=cplace) : aWarpSharp2(y, thresh=thresh, blur=blur,  type=type,  depth=depth, chroma=chroma, cplace=cplace) : y
  47. u_warp = chroma > 2 ? useaW4 ? aWarp4(u, u_mask, depth=cdepth                              ) : aWarp(u, u_mask, depth=cdepth                                                                  ) : nop()
  48. v_warp = chroma > 2 ? useaW4 ? aWarp4(v, v_mask, depth=cdepth                              ) : aWarp(v, v_mask, depth=cdepth                                                                  ) : nop()
  49.  
  50. # luma/chroma processing
  51. output = chroma > 2 ? YtoUV( u_warp  , v_warp  , y_warp ) : \
  52.         y_warp
  53. """)
  54. output8_16 = lsb==true ? output.Dither_convert_8_to_16() : output
  55. y_ld  = chroma < 5 ? 3 : 2
  56. uv_ld = Min(chroma, 3)
  57. 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)
  58. }
Add Comment
Please, Sign In to add comment