Guest User

aWarpSharp4xx

a guest
Oct 15th, 2017
228
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.44
  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", int "depthV", int "blurV", int "cdepthV", int "cblurV")
  5. {
  6.  
  7. avspmt  = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
  8.  
  9. lsb    = default(lsb, false)
  10. avspmt ? Assert(!(osrc.BitsPerComponent() > 8 && lsb), "lsb hack is not Compatible with native high bit depth" ) : nop()
  11.  
  12. src = lsb ? osrc.DitherPost(mode=-1) : osrc
  13.  
  14. fullchr = avspmt ? src.is444() : src.isyv24()
  15. chr420  = avspmt ? src.is420() : src.isyv12()
  16. nochr   = avspmt ?   src.isy() : src.isy8()
  17.  
  18. depth  = default(depth, 16)
  19. type   = default(type ,  0)
  20. mablur  = defined(blur)
  21. blur   = default(blur , type==0 ? 2 : 3)
  22. chroma = default(chroma, 4)
  23. cplace = default(cplace, "MPEG2")
  24. cdepth = default(cdepth, fullchr ? depth : depth/2)
  25. blurC_para = defined(cblur) ? ",blurC=" + string(cblur) : ""
  26. cblur  = default(cblur, fullchr ? blur : (blur+1)/2)
  27. bic    = default(bic, true)
  28. useaW4 = default(useaWarp4, false)
  29.  
  30. Assert(IsPlanar(src) && isyuv(src), "aWarpSharp4xx: input clip must be planar YUV")
  31. assert(0 <= chroma <= 6, "aWarpSharp4xx: argument chroma must be an integer between 0 and 6.")  
  32. assert(cplace == "MPEG2" || cplace == "MPEG1", "aWarpSharp4xx: chroma siting must be MPEG2 or MPEG1")
  33. Assert(Defined(y_mask) ? avspmt ? isy(y_mask) : isy8(y_mask) : true, "aWarpSharp4xx: y_mask clip mustn't has chroma")
  34.  
  35. blur = defined(blurV) && !mablur ? depth==0 ? 0 : blur : blur
  36.  
  37. defined(depthV) ? depthV != 0 && depth==0 ? eval("blurV=defined(blurV) ? blurV : blur Chr(3) blur=mablur ? blur : 0") : depthV==0 && depth != 0 ? eval("blurV=defined(blurV) ? blurV : 0") : nop() : nop()
  38.  
  39. defined(depthV) && !defined(cdepthV) ? depthV != 0 ? fullchr ? eval("cdepthV=depthV") : eval("cdepthV=depthV/2") : eval("cdepthV=0") : nop()
  40.  
  41. defined(cdepthV) ? cdepthV != 0 && cdepth==0 ? eval("""cblurV=defined(cblurV) ? cblurV : cblur Chr(3) cblur=blurC_para!="" ? cblur : 0""") : cdepthV==0 && cdepth != 0 ? eval("cblurV=defined(cblurV) ? cblurV : 0") : nop() : nop()
  42.  
  43. depthV_para = defined(depthV) ? ",depthV=" + string(depthV) : ""
  44. blurV_para = defined(blurV) ? ",blurV=" + string(blurV) : defined(depthV) ? depthV==0 ? ",blurV=0" : "" : ""
  45. cdepthV_para = defined(cdepthV) ? ",depthVC=" + string(cdepthV) : ""
  46. cblurV_para = defined(cblurV) ? ",blurVC=" + string(cblurV) : defined(cdepthV) ? cdepthV==0 ? ",blurVC=0" : "" : ""
  47. cuvdepthV_para = defined(cdepthV) ? ",depthV=" + string(cdepthV) : ""
  48. cuvblurV_para = defined(cblurV) ? ",blurV=" + string(cblurV) : ""
  49.  
  50. chroma = nochr ? 1 : defined(cdepthV) ? cdepthV==0 && cdepth==0 && chroma > 2 ? 2 : chroma : chroma
  51.  
  52. (blurC_para=="" && !Defined(y_mask) && !useaW4 && !IsYV411(src) && !((!fullchr || !nochr) && (chroma == 4 || chroma == 6))) ? \
  53. Eval("""
  54. output = eval("src.aWarpSharp2(thresh=thresh, blur=blur, type=type, depth=depth, chroma=chroma, depthC=cdepth, cplace=cplace" + depthV_para + blurV_para + cdepthV_para + cblurV_para + ")")
  55. """) : \
  56. Eval("""
  57. chrgu = chroma == 4 || chroma == 6
  58. y = chroma > 2 && !(chroma > 4 && Defined(y_mask)) ? avspmt ? ConvertToY(src) : ConvertToY8(src) : src
  59. u = chroma > 2 ? avspmt ? ExtractU(src) : UtoY8(src) : nop()
  60. v = chroma > 2 ? avspmt ? ExtractV(src) : VtoY8(src) : nop()
  61.  
  62. eymask = Defined(y_mask)
  63.  
  64. y_mask = eymask ? y_mask : useaW4 || chrgu ? aSobel(y, thresh=thresh) : nop()
  65. yblurb  = !mablur && eymask ? defined(blurV) ? blurV!=0 : false : defined(blurV) ? !(blurV==0 && blur==0) : blur!=0
  66. y_mask  = yblurb && (useaW4 || chrgu) ? eval("y_mask.aBlur(blur=blur,  type=type" + blurV_para + ")") : y_mask
  67. cshift  = chrgu ? IsYV411(src) ? -1.5 : (cplace == "MPEG1" && chr420) ? 0 : -0.5 : nop()
  68. uv_mask = chrgu ? fullchr ? y_mask : bic ? y_mask.BicubicResize(u.width(), v.height(), src_left=cshift) : y_mask.BilinearResize(u.width(), v.height(), src_left=cshift) : nop()
  69. u_mask  = chrgu ? uv_mask : chroma > 2 ? aSobel(u, thresh=thresh) : nop()
  70. uvblurb     = defined(cblurV) ? !(cblurV==0 && cblur==0) : cblur!=0
  71. u_mask  = chrgu ? u_mask : chroma > 2 ? uvblurb ? eval("u_mask.aBlur(blur=cblur, type=type" + cuvblurV_para + ")") : u_mask : nop()
  72. v_mask  = chrgu ? uv_mask : chroma > 2 ? aSobel(v, thresh=thresh) : nop()
  73. v_mask  = chrgu ? v_mask : chroma > 2 ? uvblurb ? eval("v_mask.aBlur(blur=cblur, type=type" + cuvblurV_para + ")") : v_mask : nop()
  74.  
  75. y = chroma < 5 ? useaW4 ? y.nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2) : y : y
  76. u = chroma > 2 ? useaW4 ? U.nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2) : u : nop()
  77. v = chroma > 2 ? useaW4 ? V.nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2) : v : nop()
  78.  
  79. # warp each channel independently
  80. y_warp = chroma < 5 ? useaW4 ? eval("aWarp4(y, y_mask,  depth=depth, chroma=chroma, cplace=cplace" + depthV_para + cdepthV_para + ")") : eval("aWarpSharp2(y, thresh=thresh, blur=blur,  type=type,  depth=depth, chroma=chroma, cplace=cplace" + depthV_para + blurV_para + cdepthV_para + blurC_para + cblurV_para + ")") : y
  81. u_warp = chroma > 2 ? useaW4 ? eval("aWarp4(u, u_mask, depth=cdepth                             " + cuvdepthV_para + ")") : eval("aWarp(u, u_mask, depth=cdepth                                                                  " + cuvdepthV_para + ")") : nop()
  82. v_warp = chroma > 2 ? useaW4 ? eval("aWarp4(v, v_mask, depth=cdepth                              " + cuvdepthV_para + ")") : eval("aWarp(v, v_mask, depth=cdepth                                                                  " + cuvdepthV_para + ")") : nop()
  83.  
  84. # luma/chroma processing
  85. output = chroma > 2 ? avspmt ? CombinePlanes(y_warp,u_warp,v_warp,planes="YUV", source_planes="YYY",sample_clip=src) : YtoUV( u_warp  , v_warp  , y_warp ) : \
  86.         y_warp
  87. """)
  88. output8_16 = lsb==true ? output.Dither_convert_8_to_16() : output
  89. y_ld  = chroma < 5 ? 3 : 2
  90. uv_ld = Min(chroma, 3)
  91. 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)
  92. }
Add Comment
Please, Sign In to add comment