Advertisement
Guest User

BlindDeHalo3_mt2

a guest
Apr 1st, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 2017.03.26 1st release
  2. # BlindDeHalo3 with high bit support, need masktools 2.2.5 or up in avs26 and avs+
  3.  
  4. function BlindDeHalo3( clip input, float "rx", float "ry", int "strength",
  5.  \                     float "lodamp", float "hidamp", float "sharpness", float "tweaker",
  6.  \                     int "PPmode", float "PPlimit", bool "interlaced")
  7. {
  8. rx =         default( rx,           3.0 )
  9. ry =         default( ry,           3.0 )
  10. strength =   default( strength,     125 )
  11. lodamp =     default( lodamp,       0.0 )
  12. hidamp =     default( hidamp,       0.0 )
  13. sharpness =  default( sharpness,    0.0 )
  14. tweaker =    default( tweaker,      0.0 )
  15. PPmode =     default( PPmode,         0 )
  16. PPlimit =    default( PPlimit, (abs(PPmode)==3) ? 4 : 0 )
  17. interlaced = default( interlaced, false )
  18.  
  19. sharpness = (sharpness>1.58) ? 1.58 : sharpness
  20. tweaker   = (tweaker > 1.00) ? 1.00 : tweaker
  21. strength  = float(strength)*(1.0+sharpness*0.25)
  22. RR   = string((rx+ry)/2.0)
  23. ST   = string(float(strength)/100.0)
  24. LD   = string(lodamp)
  25. HD   = string(pow(hidamp,2))
  26. TWK0 = "x y - 12 "+ST+" / "+RR+" / /"
  27. TWK  = "x y - 12 "+ST+" / "+RR+" / / abs"
  28. TWK_HLIGHT = VersionNumber() < 2.6 ? "x y - abs 1 < 128 "+TWK+" 128 "+TWK+" - "+TWK+" 128 / * + "+TWK0+" "+TWK+" "+LD+" + / * "
  29.                                       \ + "128 "+TWK+" - 20 / 2 ^ 128 "+TWK+" - 20 / 2 ^ "+HD+" + / * 128 + ?"
  30.              \                     : "x y - abs 1 scalef < range_half "+TWK+" range_half "+TWK+" - "+TWK+" range_half / * + "+TWK0+" "+TWK+" "+LD+" + / * "
  31.                                       \ + "range_half "+TWK+" - 20 scalef / 2 ^ range_half "+TWK+" - 20 scalef / 2 ^ "+HD+" + / * range_half + ?"
  32.  
  33. ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
  34.  
  35. sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8()
  36.  
  37. clp = sislumaonly ? input : ssispmt ? input.converttoy() : input.converttoy8()
  38.  
  39. i     = (interlaced==false) ? clp : clp.separatefields()
  40. oxi   = i.width
  41. oyi   = i.height
  42. sm    = i.bicubicresize(bh_m4(oxi/rx),bh_m4(oyi/ry))
  43. mm    = VersionNumber() < 2.6 ? mt_lutxy(sm.mt_expand(),sm.mt_inpand(),"x y - 4 *") : mt_lutxy(sm.mt_expand(),sm.mt_inpand(),"clamp_f x y - 4 *")
  44. mm    = mm.mt_expand().mt_deflate().blur(1.58).mt_inflate().bicubicresize(oxi,oyi,1.0,.0).mt_inflate()
  45. sm    = sm.bicubicresize(oxi,oyi,1.0,.0)
  46. smd   = mt_lutxy(i.sharpen(tweaker),sm,TWK_HLIGHT)
  47. smd   = (sharpness==0.0) ? smd : smd.blur(sharpness)
  48. clean = VersionNumber() < 2.6 ? mt_lutxy(i,smd,yexpr="x y 128 - -") : mt_lutxy(i,smd,yexpr="x y range_half - -")
  49. clean = mt_merge(i,clean,mm,u=2,v=2)
  50.  
  51. LL    = string(PPlimit)
  52. LIM   = VersionNumber() < 2.6 ? "x "+LL+" + y < x "+LL+" + x "+LL+" - y > x "+LL+" - y ? ?" : "x "+LL+" scalef + y < x "+LL+" scalef + x "+LL+" scalef - y > x "+LL+" scalef - y ? ?"
  53.  
  54. base  = (PPmode<0) ? i : clean
  55. small = base .bicubicresize(bh_m4(oxi/sqrt(rx*1.5)),bh_m4(oyi/sqrt(ry*1.5)))
  56. ex1   = small.mt_expand().blur(.5)
  57. in1   = small.mt_inpand().blur(.5)
  58. huexp = VersionNumber() < 2.6 ? "x y - 1 1 / * 1.0 ^ 1 - 5 *" : "clamp_f x y - 1 scalef - 5 *"
  59. hull  = mt_logic( mt_lutxy( ex1.mt_expand().RemoveGrain(12,-1), ex1, huexp )
  60.  \               ,mt_lutxy( in1, in1.mt_inpand().RemoveGrain(12,-1), huexp )
  61.  \               ,"max")
  62.  \     .bicubicresize(oxi,oyi,1.0,.0)
  63.  
  64. postclean = (abs(PPmode)== 1) ?  mt_merge(base,small.bicubicresize(oxi,oyi,1.0,.0),hull,U=2,V=2)
  65.  \        : (abs(PPmode)== 2) ?  mt_merge(base,base.RemoveGrain(19,-1),hull,U=2,V=2)
  66.  \        : (abs(PPmode)== 3) ?  mt_merge(base,base.RemoveGrain(4,-1),hull,U=2,V=2)
  67.  \        :                      clean
  68.  
  69. postclean = (PPlimit==0) ?  postclean
  70.  \        :                 mt_lutxy(base,postclean,yexpr=LIM,U=2,V=2)
  71.  
  72. (PPmode==0) ? clean   : postclean
  73. interlaced  ? weave() : last
  74. sislumaonly ? last : ssispmt ? CombinePlanes(last,input,planes="YUV",sample_clip=input) : ytouv(input.utoy8(),input.vtoy8(),last)
  75.  
  76. return( last )
  77. }
  78. #---------------------------------------------------------
  79. function bh_m4(float x) {
  80. nx=VersionNumber() < 2.6 ? x<16?16:int(round(x/4.0)*4) : round(x)
  81. return(nx)
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement