Guest User

SMDegrain

a guest
Oct 6th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ################################################################################################
  2. ###                                                                                          ###
  3. ###                           Simple MDegrain Mod - SMDegrain()                              ###
  4. ###                                                                                          ###
  5. ###                       Mod by Dogway - Original idea by Caroliano                         ###
  6. ###                                                                                          ###
  7. ###          Special Thanks: Sagekilla, Didée, cretindesalpes, Gavino and MVtools people     ###
  8. ###                                                                                          ###
  9. ###                       v3.1.2d (Dogway's mod) - 21 July 2015                              ###
  10. ###          mod in 2016-10-05 to fix subpixel=3 and add Prefilter auto 16 (lsb) support     ###
  11. ###                           and yuy2 support in avs 2.6 with masktools 2.6                 ###
  12. ### and medianblur2 now will be used in Minblur instead of Quantile RemoveGrainHD in avs 2.6 ###
  13. ###                                    and add TV_range bool                                 ###
  14. ###               less lsb if not use lsb things and get ready for yv16 and yv24             ###
  15. ###              add dct, device_id and move all prefilters to external function             ###
  16. ###                                                                                          ###
  17. ################################################################################################
  18. ###
  19. ### General purpose simple degrain function. Pure temporal denoiser. Basically a wrapper(function)/frontend of mvtools2+mdegrain
  20. ### with some added common related options. Goal is accessibility and quality but not targeted to any specific kind of source.
  21. ### The reason behind is to keep it simple so aside masktools2 you will only need MVTools2.
  22. ###
  23. ### Check documentation for deep explanation on settings and defaults.
  24. ### VideoHelp thread: (http://forum.videohelp.com/threads/369142)
  25. ###
  26. ################################################################################################
  27.  
  28. function SMDegrain (clip input   , int "tr"      , int "thSAD"    , int  "thSADC" , bool "RefineMotion",  val  "contrasharp", clip "CClip"      , bool "interlaced" ,  int   "plane" ,  int   "Globals",                                  \
  29.                      int "pel"   , int "subpixel", val "prefilter", clip "mfilter", int  "blksize"     , int  "overlap"     ,  int  "search"    , bool "truemotion" , int  "limit"   ,  int   "limitc" ,  int   "thSCD1" , int "thSCD2",  \
  30.                     bool "chroma", int "hpad"    , int "vpad"     , bool "lsb"    , bool "lsb_in"      ,  bool "lsb_out"    , int  "mode"       , bool  "slices"    , val  "Show"    ,  float "Str"    ,  float "Amp" , bool "TV_range", int "dct", int "device_id"){
  31.  
  32.  
  33.  
  34. # Defaults & Conditionals
  35.  
  36.  
  37. tr           = default( tr,       2 )
  38. thSAD        = default( thSAD,  300 )
  39. thSAD2=int(thSAD/2)
  40. thSADC       = default( thSADC, thSAD2)
  41. RefineMotion = default( RefineMotion,false)
  42.  
  43. lsb_in       = default( lsb_in,  false)
  44. lsb_out      = default( lsb_out, false)
  45. lsb          = default( lsb    , lsb_in || lsb_out)
  46. mode         = default( mode, 0 )
  47. mode         = mode != 9 ? mode : -1
  48. ampn         = mode != 9 ? 0.0  : 1.0
  49. slices       = default(slices, true)
  50.  
  51. Globals      = default( Globals,  0 )
  52. GlobalR = Globals == 1        ? true : false
  53. GlobalO = Globals == 3        ? true : false
  54. if1     = Defined(CClip)      ? true : false
  55.  
  56. Contrasharp  = default( Contrasharp, !GlobalO && if1 ? true : false)
  57. Interlaced   = default( Interlaced,  false)
  58.  
  59. w       = input.width ()
  60. h       = input.height()
  61. sShow   = IsString(show)      ? true : false
  62. preclip = IsClip(prefilter)   ? true : false
  63. planar  = IsYUY2(input)       ? true : false
  64. ifC     = IsBool(Contrasharp) ? true : false
  65. if0     = ifC ? (Contrasharp  ? true : false) : (Contrasharp > 0.0 ? true : false)
  66. if2     = if0 && lsb && !GlobalO                                    ? true : false
  67. if3     = tr > 3                                                    ? true : false
  68. if4     = (w > 1099 ||  h > (lsb_in ? 1199 : 599))                  ? true : false
  69. if5     = interlaced ? (GetParity(input)                            ? true : false) : nop()
  70. avs26   = VersionNumber() < 2.60 ? false : true
  71. yuy25   = !avs26 && planar
  72.  
  73.  
  74. pel          = default( pel, if4 ? 1 : 2 )
  75. subpixel     = default( subpixel,  2 )
  76. prefilter    = default( prefilter, -1 )
  77. MFilterB     = defined(mfilter) ? true : false
  78. pelclip      = pel>1 && subpixel == 3 ? true : false
  79. Str          = default( Str, 1.0 )
  80. Amp          = default( Amp, 0.0625 )
  81. TV_range     = default( TV_range, true)
  82.  
  83. blksize      = default( blksize,  if4 ? 16 : 8 )
  84. blk2=blksize/2
  85. overlap      = default( overlap,  blk2 )
  86. ovl2=overlap/2
  87. search       = default( search,   4 )
  88. truemotion   = default( truemotion, !if4)
  89. dct          = default( dct,   0 )
  90. thSCD1       = default( thSCD1,  int(pow((blksize*2.5),2)))
  91. thSCD2       = default( thSCD2,  130 )
  92.  
  93.  
  94. plane        = default( plane,    4 )
  95. chroma       = default( chroma,    true)
  96. Chr          = chroma ? 3 : 1
  97. Chr2         = chroma ? 3 : (prefilter==3 ? 2 : 1)
  98. plane0       = plane!=0        ? true : false
  99. U            = plane0 && plane!=2 ? 3 : 2
  100. V            = plane0 && plane!=1 ? 3 : 2
  101. Uin          = lsb_in ? 3 : u
  102. Vin          = lsb_in ? 3 : v
  103.  
  104.  
  105. hpad         = blksize
  106. vpad         = blksize
  107. limit        = default( limit,  255 )
  108. limitc       = default( limitc,limit)
  109.  
  110. Show         = default( Show,  false)
  111.  
  112.  
  113.  
  114.  
  115. # Error Report
  116.  
  117.                   Assert(blksize==4 || blksize==8 || blksize==16 || blksize==32,"MAnalyse: Block's size must be 4x4, 8x4, 8x8, 16x2, 16x8, 16x16, 32x16, 32x32")
  118.                   Assert(overlap <= blk2,              "Overlap must be at least half blksize or less")
  119.                   Assert(overlap == overlap-overlap%2, "MAnalyse: overlap must be an even figure")
  120.                   Assert(IsBool(Show) || sShow,        "'Show' only accepts bool inputs (true,false), or string modes ('Speed','Memory',Quality')")
  121.                   Assert(preclip || IsInt(prefilter),  "'prefilter' only accepts integers and clip inputs")
  122.                   Assert(ifC     || IsInt(Contrasharp),"'Contrasharp' only accepts integers and bool inputs")
  123. !chroma         ? Assert(plane==0,                     "Denoising chroma with luma only vectors is bugged in mvtools and thus unsupported") : nop()
  124. MFilterB        ? Assert(IsClip(mfilter),              "'mfilter' only accepts clip inputs")                        : nop()
  125. interlaced      ? Assert(h%4==0,                       "Interlaced sources require mod 4 height sizes")             : nop()
  126. lsb_in          ? Assert(!interlaced,                  "Interlaced 16 bit stacked clip is not a recognized format") : nop()
  127. planar && if0   ? Assert(ifC,                          "LSFmod doesn't support YUY2 sources")                       : nop()
  128. RefineMotion    ? Assert(blksize > 7,                  "For RefineMotion you need a blksize of at least 8")         : nop()
  129. lsb_in          ? Assert(lsb,                          "lsb_in  requires: lsb=true")                                : nop()
  130. lsb_out         ? Assert(lsb,                          "lsb_out requires: lsb=true")                                : nop()
  131.  
  132.  
  133.  
  134. # RefineMotion Variables
  135.  
  136. halfblksize  = RefineMotion ?  blk2                                     : nop() # MRecalculate works with half block size
  137. halfoverlap  = RefineMotion ? (overlap == 2 ? overlap : ovl2+ovl2%2)    : nop() # Halve the overlap to suit the halved block size
  138. halfthSAD    = RefineMotion || if3 ?     thSAD2                         : nop() # MRecalculate uses a more strict thSAD, which defaults to 150 (half of function's default of 300)
  139. halfthSADC   =                 if3 ? int(thSADC/2)                      : nop() # For MDegrainN()
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. # Input preparation for: LSB_IN, Interlacing, Planar and MSuper optimization when pel=2
  147.  
  148. inputY  = planar      ? (lsb_in   ? Dither_YUY2toPlanar16(input)          : Interleaved2planar(input))                          : input
  149.  
  150. inputP  = !interlaced ? (pel == 2 ? inputY.AssumeFrameBased()             : inputY)                                             : \
  151.                         (if5      ? inputY.AssumeTFF().SeparateFields()   : inputY.AssumeBFF().SeparateFields())
  152.  
  153. input8h = lsb_in      ?             inputP. Ditherpost(mode=6, slice=slices)                                                    : nop()
  154. input8y = planar      ? (lsb_in   ? input8h.Dither_YUY2toInterleaved()    : inputP)                                             : inputP
  155. input8  = lsb_in      ? (planar   ? input8y.Interleaved2planar()                                                                : \
  156.                                     input8h)                                                                                    : input8y
  157.  
  158.  
  159. # Prefilter & Motion Filter
  160.  
  161. Mfilter = MFilterB ? Mfilter : input8
  162.  
  163. bug_wa = interlaced && planar && chroma && !avs26 ? 2 : Chr # bug: crash prevention workaround (http://forum.doom9.org/showthread.php?p=1546684#post1546684)
  164.  
  165. pref   = !GlobalR ? ( preclip        ?  prefilter                                                                                                                                   : \
  166.                     ((prefilter==-1) ?  inputP                                                                                                                                      : \
  167.                      (prefilter>-1)  ?  input.SMDegrain_prefilters(inputP=inputP,input8=input8,input8y=input8y\
  168.                                                                                 ,inputY=inputY,input8h=input8h,prefilter=prefilter,chroma=chroma\
  169.                                                                                 ,Chr=Chr,Chr2=Chr2,bug_wa=bug_wa,lsb=lsb,lsb_in=lsb_in,Interlaced=Interlaced\
  170.                                                                                 ,if5=if5,pel=pel,device_id=device_id,slices=slices,planar=planar)                                                       : \
  171.                       Assert(false,    "Mode must be between -1~4: "+string(prefilter))))                                                                                           : \
  172.                       input8
  173.  
  174.  
  175.  
  176.  
  177.  
  178. # Default Auto-Prefilter - Luma expansion TV->PC (up to 16% more values for motion estimation)
  179.  
  180. pref   = avs26 && planar && ((lsb_in && prefilter==-1)) ? pref.Dither_YUY2toInterleaved16().Interleaved2planar() : pref
  181. pref16 = (Height(pref)) == (Height(input8)*2) ? true : false
  182. pref   = !GlobalR ? (!yuy25 && lsb ? ((!preclip ? ((lsb_in && prefilter==-1) || prefilter==3 || prefilter==4 ) : false)          ? \
  183.                      !TV_range ? pref.Ditherpost(mode=6,ampn=0.0,slice=slices,staticnoise=false,u=Chr2,v=Chr2)                                      : \
  184.                      pref.Dither_Luma_Rebuild(S0=Str,c=Amp,slice=slices,lsb_in=true,uv=Chr2)                                      : \
  185.                      !TV_range ? pref16 ? pref.Ditherpost(mode=6,ampn=0.0,slice=slices,staticnoise=false,u=Chr2,v=Chr2) : pref                                      : \
  186.                      pref.Dither_Luma_Rebuild(S0=Str,c=Amp,slice=slices,lsb   =lsb,lsb_in=pref16,uv=Chr2))                       : \
  187.                                       ((!preclip ?  (lsb_in && prefilter==-1)                                   : false)                                 ? \
  188.                      !TV_range ? pref.Ditherpost(mode=6,slice=slices,u=Chr,v=Chr).Dither_YUY2toInterleaved().Interleaved2planar(!chroma)   : \
  189.                      pref.Ditherpost(mode=6,slice=slices,u=Chr,v=Chr).Dither_YUY2toInterleaved().Interleaved2planar(!chroma).Dither_Luma_Rebuild(S0=Str,c=Amp,uv=Chr   )   : \
  190.                      !TV_range ? pref16 ? pref.Dither_YUY2toPlanar16().Ditherpost(mode=6,slice=slices,u=bug_wa,v=bug_wa).Dither_YUY2toInterleaved().Interleaved2planar(!chroma) : pref                                  : \
  191.                      pref.                                                    Dither_Luma_Rebuild(S0=Str,lsb_in=pref16,slice=slices,c=Amp,uv=bug_wa)))                                  : \
  192.                      pref
  193.  
  194.  
  195.  
  196.  
  197.  
  198. (sShow ? false : !Show) ? eval("""
  199.  
  200.  
  201. # Subpixel 3
  202.  
  203. pclip  = pelclip              ?    pel==4 ? pref.nnedi3_rpow2(rfactor=2,nns=4).nnedi3_rpow2(rfactor=2,nns=4) :   pref.nnedi3_rpow2(rfactor=2,nns=4)  : nop()
  204. pclip2 = pelclip && !GlobalR  ?  pel==4 ? input8.nnedi3_rpow2(rfactor=2,nns=4).nnedi3_rpow2(rfactor=2,nns=4) : input8.nnedi3_rpow2(rfactor=2,nns=4)  : nop()
  205.  
  206.  
  207.  
  208.  
  209. # Motion vectors search
  210.  
  211.  
  212. super_search =                             pelclip ? MSuper(pref,     pel=pel,               chroma=chroma, hpad=hpad, vpad=vpad,          pelclip=pclip,  rfilter=4, planar=planar) : \
  213.                                                     MSuper(pref,     pel=pel,sharp=subpixel,chroma=chroma, hpad=hpad, vpad=vpad                        ,  rfilter=4, planar=planar)
  214. super_render = !GlobalR ?                 (pelclip ? MSuper(input8,   pel=pel,               chroma=plane0, hpad=hpad, vpad=vpad,levels=1, pelclip=pclip2           , planar=planar) : \
  215.                                                     MSuper(input8,   pel=pel,sharp=subpixel,chroma=plane0, hpad=hpad, vpad=vpad,levels=1                           , planar=planar)): super_search
  216. Recalculate  = !GlobalR && RefineMotion ? (pelclip ? MSuper(pref,     pel=pel,               chroma=chroma, hpad=hpad, vpad=vpad,levels=1, pelclip=pclip            , planar=planar) : \
  217.                                                     MSuper(pref,     pel=pel,sharp=subpixel,chroma=chroma, hpad=hpad, vpad=vpad,levels=1                           , planar=planar)): nop()
  218. !if3  ? eval("
  219. bv6  =   interlaced && (tr > 2)                  ? (!GlobalR  ? super_search.MAnalyse(isb = true, delta = 6,  overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         bv6) :  nop()
  220. bv6  =   interlaced && (tr > 2) && RefineMotion &&  !GlobalR  ?   MRecalculate           (Recalculate, bv6,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion) :  bv6
  221. bv4  =   interlaced && (tr > 1)                  ? (!GlobalR  ? super_search.MAnalyse(isb = true, delta = 4,  overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         bv4) :  nop()
  222. bv4  =   interlaced && (tr > 1) && RefineMotion &&  !GlobalR  ?   MRecalculate           (Recalculate, bv4,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  bv4
  223. bv3  =  !interlaced ? ((tr > 2)                  ? (!GlobalR  ? super_search.MAnalyse(isb = true, delta = 3,  overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         bv3) :  nop()) : nop()
  224. bv3  =  !interlaced ? ((tr > 2  && RefineMotion &&  !GlobalR) ?   MRecalculate           (Recalculate, bv3,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  bv3               )   : nop()
  225. bv2  =  (interlaced ||  tr > 1)                  ? (!GlobalR  ? super_search.MAnalyse(isb = true, delta = 2,  overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         bv2) :  nop()
  226. bv2  = ((interlaced ||  tr > 1) && RefineMotion &&  !GlobalR) ?   MRecalculate           (Recalculate, bv2,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  bv2
  227. bv1  =  !interlaced ?                              (!GlobalR  ? super_search.MAnalyse(isb = true, delta = 1,  overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         bv1        ) : nop()
  228. bv1  =  !interlaced ?            ( RefineMotion &&  !GlobalR  ?   MRecalculate           (Recalculate, bv1,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  bv1               ) : nop()
  229.  
  230. fv1  =  !interlaced ?                              (!GlobalR  ? super_search.MAnalyse(isb = false, delta = 1, overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         fv1        ) : nop()
  231. fv1  =  !interlaced ?            ( RefineMotion &&  !GlobalR  ?   MRecalculate           (Recalculate, fv1,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  fv1               ) : nop()
  232. fv2  =  (interlaced ||  tr > 1)                  ? (!GlobalR  ? super_search.MAnalyse(isb = false, delta = 2, overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         fv2) :  nop()
  233. fv2  = ((interlaced ||  tr > 1) && RefineMotion &&  !GlobalR) ?   MRecalculate           (Recalculate, fv2,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  fv2
  234. fv3  =  !interlaced ? ((tr > 2)                  ? (!GlobalR  ? super_search.MAnalyse(isb = false, delta = 3, overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         fv3) :  nop()) : nop()
  235. fv3  =  !interlaced ? ((tr > 2  && RefineMotion &&  !GlobalR) ?   MRecalculate           (Recalculate, fv3,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  fv3               )   : nop()
  236. fv4  =   interlaced && (tr > 1)                  ? (!GlobalR  ? super_search.MAnalyse(isb = false, delta = 4, overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         fv4) :  nop()
  237. fv4  =   interlaced && (tr > 1) && RefineMotion &&  !GlobalR  ?   MRecalculate           (Recalculate, fv4,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  fv4
  238. fv6  =   interlaced && (tr > 2)                  ? (!GlobalR  ? super_search.MAnalyse(isb = false, delta = 6, overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma, truemotion=truemotion, dct=dct) :         fv6) :  nop()
  239. fv6  =   interlaced && (tr > 2) && RefineMotion &&  !GlobalR  ?   MRecalculate           (Recalculate, fv6,   overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma, truemotion=truemotion, dct=dct) :  fv6 " )     : \
  240. \
  241. eval("
  242. tr2    = tr*2
  243. vmulti =                   !GlobalR ? super_search.MAnalyse( multi=true,overlap=    overlap,blksize=    blksize,   search=search,chroma=chroma,truemotion=truemotion, delta = interlaced ? tr2 : tr, dct=dct) : vmulti
  244. vmulti = RefineMotion   ? (!GlobalR ? MRecalculate (Recalculate, vmulti,overlap=halfoverlap,blksize=halfblksize, thSAD=halfthSAD,chroma=chroma,truemotion=truemotion,    tr = interlaced ? tr2 : tr, dct=dct) : vmulti) : vmulti
  245. vmulti =                   !GlobalR ? (interlaced ? vmulti.SelectEvery (4, 2, 3) : vmulti) : vmulti.SelectRangeEvery (Rtr*2, tr2, 0, false)")
  246.  
  247.  
  248.  
  249. # Finally, MDegrain
  250.  
  251.  
  252. output  = !GlobalO ? (interlaced ?
  253. \        ((lsb ?     ( if3  ? mfilter.MDegrainN(super_render, vmulti, tr, thSAD2=halfthSAD, thSADC2=halfthSADC, thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=true) :
  254. \                 (tr == 3) ? mfilter.MDegrain3(super_render, bv2, fv2, bv4, fv4, bv6, fv6,                     thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=true) :
  255. \                 (tr == 2) ? mfilter.MDegrain2(super_render, bv2, fv2, bv4, fv4,                               thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=true) :
  256. \                             mfilter.MDegrain1(super_render, bv2, fv2,                                         thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=true)):
  257. \                    ( if3  ? mfilter.MDegrainN(super_render, vmulti, tr, thSAD2=halfthSAD, thSADC2=halfthSADC, thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=false):
  258. \                 (tr == 3) ? mfilter.MDegrain3(super_render, bv2, fv2, bv4, fv4, bv6, fv6,                     thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar)          :
  259. \                 (tr == 2) ? mfilter.MDegrain2(super_render, bv2, fv2, bv4, fv4,                               thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar)          :
  260. \                             mfilter.MDegrain1(super_render, bv2, fv2,                                         thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar))))       :
  261. \         (lsb ?     ( if3  ? mfilter.MDegrainN(super_render, vmulti, tr, thSAD2=halfthSAD, thSADC2=halfthSADC, thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=true) :
  262. \                 (tr == 3) ? mfilter.MDegrain3(super_render, bv1, fv1, bv2, fv2, bv3, fv3,                     thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=true) :
  263. \                 (tr == 2) ? mfilter.MDegrain2(super_render, bv1, fv1, bv2, fv2,                               thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=true) :
  264. \                             mfilter.MDegrain1(super_render, bv1, fv1,                                         thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=true)):
  265. \                    ( if3  ? mfilter.MDegrainN(super_render, vmulti, tr, thSAD2=halfthSAD, thSADC2=halfthSADC, thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar,lsb=false):
  266. \                 (tr == 3) ? mfilter.MDegrain3(super_render, bv1, fv1, bv2, fv2, bv3, fv3,                     thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar)          :
  267. \                 (tr == 2) ? mfilter.MDegrain2(super_render, bv1, fv1, bv2, fv2,                               thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar)          :
  268. \                             mfilter.MDegrain1(super_render, bv1, fv1,                                         thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit, limitc=limitc, plane=plane, planar=planar))))       : nop()
  269.  
  270.  
  271. # LSB_IN merging
  272.  
  273. outputI= !GlobalO && planar && (lsb || ifC) ? output.Planar2Interleaved()                                                                                             : nop()
  274. !GlobalO && lsb   ? eval("
  275. blnkclp= lsb_in  || (if2 && !planar) ? BlankClip (lsb_in?input8h:input8, pixel_type="+Chr(34)+"YV12"+Chr(34)+", color_yuv=0)                                          : nop()
  276. output = lsb && planar               ? Dither_YUY2toPlanar16(outputI)                                                                                                 : output
  277. output = lsb_in                      ? inputY.Dither_add16 (Dither_sub16(output, planar?inputY:input8.Dither_convert_8_to_16 (), dif=true,u=u,v=v), dif=true,u=u,v=v) : output") : nop()
  278.  
  279.  
  280.  
  281.  
  282. # Contrasharp (only sharpens luma)
  283.  
  284. ifC && if0 && if4 ? eval("
  285. global Super           = super_render
  286. global cb1             = !if3 ? (interlaced ? bv2 : bv1) : vmulti.SelectEvery (tr2, 0)
  287. global cf1             = !if3 ? (interlaced ? fv2 : fv1) : vmulti.SelectEvery (tr2, 1)") : nop()
  288.  
  289. !GlobalO && if0   ? eval("
  290.  
  291. CCh   =       if1 ? CClip.height() : nop()
  292. ref8  =       if1 ? (h == CCh*2)   : nop()
  293. ref16 =       if1 ? (h == CCh/2)   : nop()
  294.  
  295. interlaced && if1 ? Assert(!ref16, "+Chr(34)+"Interlaced 16 bit stacked CClip is not a recognized format"+Chr(34)+")         : nop()
  296.  
  297. CClip = planar ?  (if1 ?  (lsb_in ? (ref8 ? CClip.Interleaved2planar(true) : CClip.Dither_YUY2toPlanar16().DitherPost(mode=-1,u=1,v=1).Dither_YUY2toInterleaved().Interleaved2planar(true))                         : \
  298.                                      (interlaced ? (if5 ? CClip.AssumeTFF().SeparateFields().Interleaved2planar(true) : CClip.AssumeBFF().SeparateFields().Interleaved2planar(true))                                : \
  299.                                      (ref16 ? CClip.Dither_YUY2toPlanar16().DitherPost(mode=-1,u=1,v=1).Dither_YUY2toInterleaved().Interleaved2planar(true) : CClip.Interleaved2planar(true))))                     : \
  300.                           (lsb_in ?  inputY.DitherPost(mode=-1,u=1,v=1).Dither_YUY2toInterleaved().Interleaved2planar(true)                                                                                         : \
  301.                                      inputP))                                                                                                                                                                       : \
  302.                   (if1 ?  (lsb_in ? (ref8 ? CClip : CClip.DitherPost(mode=-1,u=1,v=1))                                                                                                                              : \
  303.                                      (interlaced ? (if5 ? CClip.AssumeTFF().SeparateFields()                          : CClip.AssumeBFF().SeparateFields()) : (ref16 ? CClip.DitherPost(mode=-1,u=1,v=1) : CClip))) : \
  304.                           (lsb_in ?  input.DitherPost(mode=-1,u=1,v=1)                                                                                                                                              : \
  305.                                      inputP))")                                                                                                                                                                     : nop()
  306.  
  307.  
  308. !GlobalO && if2   ? eval("
  309. OutTO8  = output.DitherPost(mode=-1,u=1,v=1)
  310. OutTO8P = planar  ? OutTO8.Dither_YUY2toInterleaved()                                                                                               : nop()
  311. ctr16   = ifC     ? ContrasharpeningHD (planar ? OutTO8P.Interleaved2planar(true):OutTO8, CClip, planar=planar, HD=if4)                             : \
  312.                     LSFmod(OutTO8,source=CClip,defaults="+Chr(34)+"slow"+Chr(34)+",strength=Contrasharp,soothe=false,Lmode=0,soft=-2,keep=0)
  313.  
  314.  
  315. ctr16P  = planar  ? ctr16.Planar2Interleaved(true)  : ctr16
  316. ctr16   = StackVertical (ctr16P, planar ? BlankClip  (ctr16P, pixel_type="+Chr(34)+"YUY2"+Chr(34)+", color_yuv=0,length=1) : blnkclp )
  317. ctr16   = Dither_add16 (output,mt_makediff(!planar?ctr16P:ctr16P.Dither_YUY2toPlanar(), OutTO8,u=2,v=2).Dither_convert_8_to_16(), dif=true,u=2,v=2)
  318. ctr16   = MergeChroma(ctr16, output)                                                                                                     ")         : nop()
  319.  
  320.  
  321.  
  322. # Globals Output
  323.  
  324. GlobalO || Globals == 2  ? (!if3 ? eval("
  325. global Super           = super_render
  326. global bv6             = bv6
  327. global bv4             = bv4
  328. global bv3             = bv3
  329. global bv2             = bv2
  330. global bv1             = bv1
  331.  
  332. global fv1             = fv1
  333. global fv2             = fv2
  334. global fv3             = fv3
  335. global fv4             = fv4
  336. global fv6             = fv6
  337. ") : eval("
  338. global bv1             =                                            vmulti.SelectEvery (tr2, 0)
  339. global bv2             = interlaced ? bv1                         : vmulti.SelectEvery (tr2, 2)
  340. global bv3             =                                            vmulti.SelectEvery (tr2, 4)
  341. global bv4             = interlaced ? vmulti.SelectEvery (tr2, 2) : nop()
  342. global bv6             = interlaced ? bv3                         : nop()
  343.  
  344. global fv1             =                                            vmulti.SelectEvery (tr2, 1)
  345. global fv2             = interlaced ? fv1                         : vmulti.SelectEvery (tr2, 3)
  346. global fv3             =                                            vmulti.SelectEvery (tr2, 5)
  347. global fv4             = interlaced ? vmulti.SelectEvery (tr2, 3) : nop()
  348. global fv6             = interlaced ? fv3                         : nop()
  349. global Super           = super_render
  350. global vmulti          = vmulti
  351. global Rtr             = tr")) : nop()
  352.  
  353.  
  354.  
  355. # Output
  356.  
  357. !GlobalO ? (lsb_out ? (if0 ? ctr16 : output)  : \
  358.                      (if0 ? (lsb ?  (interlaced ?  ctr16.weave().DitherPost(u=u,v=v,mode=6,slice=slices,interlaced=true)               :  ctr16.DitherPost(mode=mode,slice=slices,ampn=ampn,u=Uin,v=Vin))                                              : \
  359.                                     (interlaced ? (ifC ? ContraSharpeningHD(output, CClip, planar=planar, HD=if4).weave()              : LSFmod(output,source=CClip,defaults="slow",strength=Contrasharp,soothe=false,Lmode=0,soft=-2,keep=0).weave()) : \
  360.                                                   (ifC ? ContraSharpeningHD(output, CClip, planar=planar, HD=if4)                      : LSFmod(output,source=CClip,defaults="slow",strength=Contrasharp,soothe=false,Lmode=0,soft=-2,keep=0))))       : \
  361.                             (lsb ?  (interlaced ? output.weave().DitherPost(u=u,v=v,mode=6,slice=slices,interlaced=true)               : output.DitherPost(mode=mode,slice=slices,ampn=ampn,u=Uin,v=Vin)) : (interlaced ? output.weave() : output))))    \
  362.         :  input
  363.  
  364. !GlobalO ? (planar ? (lsb ? Dither_YUY2toInterleaved() : (if0 ? MergeChroma(Planar2Interleaved(true), interlaced ? outputI.weave() : outputI) : Planar2Interleaved())) : last) : last """) : \
  365.  \
  366.  \
  367.  \
  368.  \
  369.  \
  370. eval("""
  371.  
  372. ##############
  373. # SHOW PANEL #
  374. ##############
  375.  
  376.  
  377.  # Common Variables
  378.  
  379. h     = lsb_in ? h/2 : h
  380. w2    = w*1.0
  381. h2    = h*1.0
  382. hi    = interlaced ? round(h/2.0) : h
  383. AR    = w2/h2
  384. lsp   = interlaced?15:30
  385. lsp   = AR < 1.9 ? lsp : floor(AR < 1.9 ? lsp : ((AR>2.4) ? 0 : lsp-((AR-1.9)*(lsp/(2.4-1.9)))))
  386. ys    = round(lsb_in ? h2/6 : (interlaced?h2/15:h2/6))
  387. s     = floor(((interlaced?w2/1.6:w2)/720.0)*16.0)
  388. type  = avs26 ? input.PixelType() : planar?"YUY2":"YV12"
  389.  
  390. Wadd  = w2/40
  391. Wadd2 = Wadd/2
  392. w1    = round(w2+Wadd+Wadd2)
  393. w3    = (w2/3)+Wadd/2.1
  394. w2    = round(w1+w3)
  395. w3    = round(w1+(w3+Wadd2)*1.96)
  396. w3sq  = string(round(w3*1.01))
  397. w3s   = string(w3)
  398.  
  399.  # Panel Separator
  400.  
  401. blkclp = BlankClip(interlaced?assumeframebased(pref):pref,length=1,pixel_type=type,color=$161616)
  402.         \.crop(0,interlaced?h/2%8:h%8,0,0).separatefields().assumeframebased().separatefields()
  403.  
  404. Interleave(selecteven(blkclp).addborders(2,0,0,0,color=$7f7f7f).crop(0,0,-2,0),selectodd(blkclp))
  405.  
  406. WOut=weave().assumefieldbased().weave()
  407. sep=round((hi-height(WOut))/2.0)
  408.  
  409. StackHorizontal(planar? pref.Planar2Interleaved() : pref,WOut.addborders(0,sep-sep%2,0,hi-(height(WOut)+(sep-sep%2)),color=$161616))
  410.  
  411.  
  412.  
  413.  # Color Guide Squares
  414.  
  415. a=interlaced?h*0.37:h*0.74
  416. b=interlaced?h*0.40:h*0.80
  417. c=interlaced?h*0.43:h*0.86
  418.  
  419. !planar ? mt_merge(mt_lut(yexpr="127",uexpr="183",vexpr="47" ,u=3,v=3) ,mt_lutspa(mode="absolute", yexpr="x "+w3s+" >= x "+w3sq+" <= & y "+string(a)+" >= y "+string(interlaced?h*0.3835:h*0.767)+" <= & & 255 0 ?").trim(0,-1).FreezeFrame(0, FrameCount(pref)-1, 0),luma=true) : nop()
  420. !planar ? mt_merge(mt_lut(yexpr="81" ,uexpr="91" ,vexpr="240",u=3,v=3) ,mt_lutspa(mode="absolute", yexpr="x "+w3s+" >= x "+w3sq+" <= & y "+string(b)+" >= y "+string(interlaced?h*0.4135:h*0.827)+" <= & & 255 0 ?").trim(0,-1).FreezeFrame(0, FrameCount(pref)-1, 0),luma=true) : nop()
  421. !planar ? mt_merge(mt_lut(yexpr="210",uexpr="16" ,vexpr="146",u=3,v=3) ,mt_lutspa(mode="absolute", yexpr="x "+w3s+" >= x "+w3sq+" <= & y "+string(c)+" >= y "+string(interlaced?h*0.4435:h*0.887)+" <= & & 255 0 ?").trim(0,-1).FreezeFrame(0, FrameCount(pref)-1, 0),luma=true) : nop()
  422.  
  423.  
  424.  # Parameters List
  425.  
  426. blue  = sShow ? (show=="Speed"   ? true : false) : false
  427. red   = sShow ? (show=="Memory"  ? true : false) : false
  428. yellow= sShow ? (show=="Quality" ? true : false) : false
  429.  
  430. Color = sShow ? (blue   ? $00aef0 : \
  431.                 red    ? $ff0000 : \
  432.                 yellow ? $ffff00 : \
  433.                 Assert(false,    "Revise typo for possible color guide modes: 'Speed','Memory','Quality'")) : nop()
  434.  
  435.  
  436.  
  437. varn = "\n\n\n\n\n"
  438. sp   = !GlobalR && str==1.0 ? "  " : ""
  439.  
  440. Subtitle("SMDegrain Mod v3.1.2",text_color=red||blue||yellow?Color:$7f7f7f,halo_color=$000000,font="VERDANA",size=s*2,x=w1,y=lsb_in?h/40:(interlaced?h/50:h/20))
  441.  
  442. Subtitle("BASIC"   ,lsp=lsp,text_color=$ffffff,font="COURIER NEW",size=s,x=w1,y=ys)
  443. Subtitle(            "\n\ntr           = " + string(tr)                                                                              + \
  444.         varn+varn+      "chroma       = " + string(chroma)                                                                          ,lsp=lsp,text_color=red||blue               ?Color:$ffffff,font="COURIER NEW",size=s,x=w1,y=ys)
  445. Subtitle(          "\n\n\nthSAD(C)     = " + string( GlobalO?"bypass":string(thSAD)     + "(" + string(plane0?thSADC:"bypass") + ")")+ \
  446.         varn+           "CClip        = " + string( GlobalO?"bypass":(defined(CClip)?"defined":"undefined"))                        + \
  447.                     "\n\nInterlaced   = " + string(interlaced)                                                                      ,lsp=lsp,text_color=                               $ffffff,font="COURIER NEW",size=s,x=w1,y=ys)
  448. Subtitle(varn+           "RefineMotion = " + string( GlobalO?"bypass":RefineMotion)                                                  ,lsp=lsp,text_color=yellow                  ?Color:$ffffff,font="COURIER NEW",size=s,x=w1,y=ys)
  449. Subtitle(varn+       "\n\nContrasharp  = " + string( GlobalO?"bypass":contrasharp)                                                   ,lsp=lsp,text_color=yellow&&!GlobalO        ?Color:$ffffff,font="COURIER NEW",size=s,x=w1,y=ys)
  450. Subtitle(varn+varn+    "\nplane        = " + string( GlobalO?"bypass":(plane==0?"0 (Luma)":plane==1?"1 (U plane)":plane==2?"2 (V plane)":plane==3?"3 (Chroma)":"4(Luma+Chroma)")),lsp=lsp,text_color=(red||blue)&&!GlobalO?Color:$ffffff,font="COURIER NEW",size=s,x=w1,y=ys)
  451. Subtitle("<-- "+string(IsClip(prefilter)||prefilter!=-1?"Prefiltered clip converted\n    to PC levels":"Clip converted to PC levels\n   ")+" for the motion search",lsp=lsp,text_color=$ffffff,font="COURIER NEW",size=s,x=w1-10,y=(interlaced?h/2:h)-int(ys/1.5))
  452.  
  453. Subtitle("ADVANCED",lsp=lsp,text_color=$7f7f7f,font="COURIER NEW",size=s,x=w2,y=ys)
  454. Subtitle(              "\n\npel        = " + string(pel)                                                                             ,lsp=lsp,text_color=red                     ?Color:$7f7f7f,font="COURIER NEW",size=s,x=w2,y=ys)
  455. Subtitle(            "\n\n\nsubpixel   = " + string( pel==1 ?"bypass":subpixel)                                                      ,lsp=lsp,text_color=(yellow||blue)&&pel!=1  ?Color:$7f7f7f,font="COURIER NEW",size=s,x=w2,y=ys)
  456. Subtitle(varn+varn+  "\n\n\ntruemotion = " + string( GlobalR?"bypass":truemotion)                                                    ,lsp=lsp,text_color=(yellow||blue)&&!GlobalR?Color:$7f7f7f,font="COURIER NEW",size=s,x=w2,y=ys)
  457. Subtitle(varn+             "mfilter    = " + string( GlobalR?"bypass":MFilterB?"Clip"+sp+" Variable":"OFF")                          ,lsp=lsp,text_color=                               $7f7f7f,font="COURIER NEW",size=s,x=w2,y=ys)
  458. Subtitle(varn+         "\n\nStr        = " + (GlobalR?string("bypass"):string(Str,"%1.2f"))+sp+" Brightness"                         + \
  459.         varn+             "search     = " + string( GlobalR?"bypass":search)                                                        ,lsp=lsp,text_color=yellow&&!GlobalR        ?Color:$7f7f7f,font="COURIER NEW",size=s,x=w2,y=ys)
  460. Subtitle(varn+varn+        "blksize    = " + string( GlobalR?"bypass":blksize)                                                       + \
  461.                         "\noverlap    = " + string( GlobalR?"bypass":overlap)                                                       ,lsp=lsp,text_color=(red||blue)&&!GlobalR   ?Color:$7f7f7f,font="COURIER NEW",size=s,x=w2,y=ys)
  462. Subtitle(varn+           "\nprefilter  = " + (GlobalR?string("bypass"):(preclip?"Clip"+sp+" Variable":(prefilter==0?"0"+sp+"    MinBlur(0)":prefilter==1?"1"+sp+"    MinBlur(1)":prefilter==2?"2"+sp+"    MinBlur(2)":prefilter==3?"3"+sp+"    Dfttest":prefilter==4?"4"+sp+"    KNLmeans":"OFF"+sp+"    (-1)"))) + \
  463.                       "\n\nAmp        = " + (GlobalR||str==1.0?string("bypass"):string(Amp,"%1.2f"))+" Amplitude"                   + \
  464.         varn+           "\nlimit(C)   = " + (GlobalO?string("bypass"):string(limit)     + "(" + string(limitc) + ")")               ,lsp=lsp,text_color=                               $7f7f7f,font="COURIER NEW",size=s,x=w2,y=ys)
  465.  
  466. Subtitle("OTHERS"  ,lsp=lsp,text_color=$494949,font="COURIER NEW",size=s,x=w3,y=ys)
  467. Subtitle(             "\n\n\nthSCD1(2) = " + (GlobalO?string("bypass"):string(thSCD1) + "(" + string(thSCD2) + ")")                  + \
  468.                   varn+"\n\nGlobals   = " + string(Globals==0 ? "0 (OFF)" : Globals==1 ? "1 (Import)" : Globals==2 ? "2 (Export)" : "3 (E.Only)"),lsp=lsp,text_color=                  $494949,font="COURIER NEW",size=s,x=w3,y=ys)
  469. Subtitle(          varn+"\n\nslices    = " + string(slices)                                                                          ,lsp=lsp,text_color=blue                    ?Color:$494949,font="COURIER NEW",size=s,x=w3,y=ys)
  470. Subtitle(               "\n\nhpad(v)   = " + string(hpad)   + "(" + string(vpad)   + ")"                                             ,lsp=lsp,text_color=red||blue               ?Color:$494949,font="COURIER NEW",size=s,x=w3,y=ys)
  471. Subtitle(varn+              "lsb       = " + string(lsb)                                                                             ,lsp=lsp,text_color=yellow                  ?Color:$494949,font="COURIER NEW",size=s,x=w3,y=ys)
  472. Subtitle(varn+            "\nlsb_in/out= " + string(lsb_in) +"/"+ string(lsb_out)                                                    ,lsp=lsp,text_color=red&&lsb_in             ?Color:$494949,font="COURIER NEW",size=s,x=w3,y=ys)
  473. Subtitle(varn+        "\n\n\nmode      = " + (GlobalO||(lsb_out||!lsb)?string("bypass"):interlaced?"6 (locked)":string(mode))        ,lsp=lsp,text_color=yellow&&!GlobalO&&lsb   ?Color:$494949,font="COURIER NEW",size=s,x=w3,y=ys)
  474.  
  475. Subtitle("   Speed"   ,lsp=interlaced?15:30,text_color=planar?$00aef0:$7f7f7f,font="COURIER NEW",size=s,x=w3,y=int(a-1))
  476. Subtitle("   Memory"  ,lsp=interlaced?17:34,text_color=planar?$ff0000:$7f7f7f,font="COURIER NEW",size=s,x=w3,y=int(b-1))
  477. Subtitle("   Quality" ,lsp=interlaced?19:38,text_color=planar?$ffff00:$7f7f7f,font="COURIER NEW",size=s,x=w3,y=int(c-1))
  478.  
  479. lsb_out ? StackVertical (last, BlankClip (last, pixel_type=type, color_yuv=0,length=1)) : last""")}
  480.  
  481.  
  482.  
  483.  
  484.  
  485. ########################################################
  486. #                                                      #
  487. # HELPER FUNCTIONS: For Contrasharp and YUY2 handling  #
  488. #                                                      #
  489. ########################################################
  490.  
  491. ########################################
  492. ## Didée's functions:
  493.  
  494.  # contra-sharpening: sharpen the denoised clip, but don't add more to any pixel than what was removed previously.
  495.  # script function from Didée, at the VERY GRAINY thread (http://forum.doom9.org/showthread.php?p=1076491#post1076491)
  496.  
  497.  # In final version 2.0d ContraHD() was merged, to allow proper HD sharpening.
  498.  # In this case global variables of (before denoising) source MSuper and forward and backward
  499.  # compensated motion vectors are necessary as: Super, cb1 and cf1, if used as a stand alone function.
  500.  # Don't know who made (mod) it, so I can't give proper credits, sorry.
  501.  
  502. FUNCTION ContraSharpeningHD(clip denoised, clip original, bool "HD", bool "planar", int "overshoot"){
  503. HD        = default(HD    ,false)
  504. planar    = default(planar,false)
  505. overshoot = default(overshoot,0)
  506. avs26 = VersionNumber() < 2.60 ? false : true
  507. yuy26 = avs26 && Isyuy2(denoised) && planar
  508.  
  509. HD ? eval("""
  510. cb1=original.MCompensate(Super, cb1, planar=planar)
  511. cf1=original.MCompensate(Super, cf1, planar=planar)
  512. pmax = yuy26 ? original.Planar2Interleaved().ConvertToYV16().mt_logic(cb1.Planar2Interleaved().ConvertToYV16(), "max").mt_logic(cf1.Planar2Interleaved().ConvertToYV16(), "max") : original.mt_logic(cb1, "max").mt_logic(cf1, "max")
  513. pmin = yuy26 ? original.Planar2Interleaved().ConvertToYV16().mt_logic(cb1.Planar2Interleaved().ConvertToYV16(), "min").mt_logic(cf1.Planar2Interleaved().ConvertToYV16(), "min") : original.mt_logic(cb1, "min").mt_logic(cf1, "min")""") : nop()
  514.  
  515. s    = denoised.MinBlur(HD?2:1,1,planar=planar)                                   # Damp down remaining spots of the denoised clip.
  516. s    = yuy26 ? s.Planar2Interleaved().ConvertToYV16() : s
  517. original = yuy26 ? original.Planar2Interleaved().ConvertToYV16() : original
  518. denoised = yuy26 ? denoised.Planar2Interleaved().ConvertToYV16() : denoised
  519. allD = mt_makediff(original,denoised)                                             # The difference achieved by the denoising.
  520. ssD  = mt_makediff(s,HD?s.removegrain(20,-1,planar=planar).\
  521.                           removegrain(20,-1,planar=planar):\
  522.                         s.removegrain(11,-1,planar=planar))                       # The difference of a simple kernel blur.
  523. allD = yuy26 ? allD.ConvertToYUY2().Interleaved2planar() : allD
  524. ssD  = yuy26 ? ssD.ConvertToYUY2().Interleaved2planar() : ssD
  525. ssDD = ssD.repair(HD?ssD.repair(allD,1,planar=planar):allD,HD?12:1,planar=planar) # Limit the difference to the max of what the denoising removed locally.
  526. ssDD = yuy26 ? ssDD.Planar2Interleaved().ConvertToYV16() : ssDD
  527. ssD  = yuy26 ? ssD.Planar2Interleaved().ConvertToYV16() : ssD
  528. ssDD = SSDD.mt_lutxy(ssD,"x 128 - abs y 128 - abs < x y ?")                       # abs(diff) after limiting may not be bigger than before.
  529.  
  530. denoised.mt_adddiff(ssDD,U=2,V=2)                                                 # Apply the limited difference. (Sharpening is just inverse blurring)
  531. HD ? mt_clamp(last,pmax,pmin,overshoot,overshoot,chroma="copy first") : last
  532. yuy26 ? last.ConvertToYUY2().Interleaved2planar() : last
  533. }
  534.  
  535.  # MinBlur   by Didée (http://avisynth.org/mediawiki/MinBlur)
  536.  # Nifty Gauss/Median combination (Modified for Planar input)
  537.  
  538. function MinBlur(clip clp, int "r", int "uv", bool "planar"){
  539.  
  540. r      = default(r,1)
  541. uv     = default(uv,3)
  542. planar = default(planar,false)
  543. avs26 = VersionNumber() < 2.60 ? false : true
  544. yuy26 = avs26 && Isyuy2(clp) && planar
  545.  
  546. uv2    = (uv==2) ? 1  : uv
  547. rg4    = (uv==3) ? 4  : -1
  548. rg11   = (uv==3) ? 11 : -1
  549. rg20   = (uv==3) ? 20 : -1
  550. uvm2   = r==2 ? (uv==3?2:uv==2?0:-1) : nop()
  551. uvm3   = r==3 ? (uv==3?3:uv==2?0:-1) : nop()
  552. medf   = (uv==3) ? 1 : -200
  553.  
  554. RG11D = (r==0) ? yuy26 ? mt_makediff(clp.Planar2Interleaved().ConvertToYV16(),clp.sbr(planar=planar).Planar2Interleaved().ConvertToYV16(),U=uv2,V=uv2).ConvertToYUY2().Interleaved2planar() : mt_makediff(clp,clp.sbr(planar=planar),U=uv2,V=uv2)
  555.  \    : (r==1) ? yuy26 ? mt_makediff(clp.Planar2Interleaved().ConvertToYV16(),clp.removegrain(11,rg11,planar=planar).Planar2Interleaved().ConvertToYV16(),U=uv2,V=uv2).ConvertToYUY2().Interleaved2planar() : mt_makediff(clp,clp.removegrain(11,rg11,planar=planar),U=uv2,V=uv2)
  556.  \    : (r==2) ? yuy26 ? mt_makediff(clp.Planar2Interleaved().ConvertToYV16(),clp.removegrain(11,rg11,planar=planar).removegrain(20,rg20,planar=planar).Planar2Interleaved().ConvertToYV16(),U=uv2,V=uv2).ConvertToYUY2().Interleaved2planar() : mt_makediff(clp,clp.removegrain(11,rg11,planar=planar).removegrain(20,rg20,planar=planar),U=uv2,V=uv2)
  557.  \    :          yuy26 ? mt_makediff(clp.Planar2Interleaved().ConvertToYV16(),clp.removegrain(11,rg11,planar=planar).removegrain(20,rg20,planar=planar).removegrain(20,rg20,planar=planar).Planar2Interleaved().ConvertToYV16(),U=uv2,V=uv2).ConvertToYUY2().Interleaved2planar() : mt_makediff(clp,clp.removegrain(11,rg11,planar=planar).removegrain(20,rg20,planar=planar).removegrain(20,rg20,planar=planar),U=uv2,V=uv2)
  558. RG4D  = (r<=1) ? yuy26 ? mt_makediff(clp.Planar2Interleaved().ConvertToYV16(),clp.removegrain(4,rg4,planar=planar).Planar2Interleaved().ConvertToYV16(),U=uv2,V=uv2).ConvertToYUY2().Interleaved2planar() : mt_makediff(clp,clp.removegrain(4,rg4,planar=planar),U=uv2,V=uv2)
  559.  \    : (r==2) ? avs26 ? yuy26 ? mt_makediff(clp.Planar2Interleaved().ConvertToYV16(),clp.Planar2Interleaved().ConvertToYV16().medianblur(2,2*medf,2*medf),U=uv2,V=uv2).ConvertToYUY2().Interleaved2planar() : mt_makediff(clp,clp.medianblur(2,2*medf,2*medf),U=uv2,V=uv2) : mt_makediff(clp,clp.Quantile(radius_y=2, radius_u=uvm2, radius_v=uvm2, planar=planar), U=uv2,V=uv2)
  560.  \    :          avs26 ? yuy26 ? mt_makediff(clp.Planar2Interleaved().ConvertToYV16(),clp.Planar2Interleaved().ConvertToYV16().medianblur(3,3*medf,3*medf),U=uv2,V=uv2).ConvertToYUY2().Interleaved2planar() : mt_makediff(clp,clp.medianblur(3,3*medf,3*medf),U=uv2,V=uv2) : mt_makediff(clp,clp.Quantile(radius_y=3, radius_u=uvm3, radius_v=uvm3, planar=planar), U=uv2,V=uv2)
  561. DD    = yuy26 ? mt_lutxy(RG11D.Planar2Interleaved().ConvertToYV16(),RG4D.Planar2Interleaved().ConvertToYV16(),"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2).ConvertToYUY2().Interleaved2planar() : mt_lutxy(RG11D,RG4D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
  562. return (yuy26 ? clp.Planar2Interleaved().ConvertToYV16().mt_makediff(DD.Planar2Interleaved().ConvertToYV16(),U=uv,V=uv).ConvertToYUY2().Interleaved2planar() : clp.mt_makediff(DD,U=uv,V=uv)) }
  563.  
  564.  
  565.  # helper function: make a highpass on a blur's difference (well, kind of that)
  566.  # Highpass of spatial r=1 Gaussian (like blur(1.0)) (Modified for Planar input)
  567.  
  568. function sbr(clip c, bool "planar") {
  569.  
  570. planar = default(planar,false)
  571. avs26 = VersionNumber() < 2.60 ? false : true
  572. yuy26 = avs26 && Isyuy2(c) && planar
  573.  
  574. rg11   = c.removegrain(11,-1,planar=planar)
  575. rg11D  = yuy26 ? mt_makediff(c.Planar2Interleaved().ConvertToYV16(),rg11.Planar2Interleaved().ConvertToYV16()).ConvertToYUY2().Interleaved2planar() : mt_makediff(c,rg11)
  576. rg11DD = yuy26 ? mt_makediff(rg11D.Planar2Interleaved().ConvertToYV16(),rg11D.removegrain(11,-1,planar=planar).Planar2Interleaved().ConvertToYV16()).mt_lutxy(rg11D.Planar2Interleaved().ConvertToYV16(),"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?").ConvertToYUY2().Interleaved2planar() : mt_makediff(rg11D,rg11D.removegrain(11,-1,planar=planar)).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  577. yuy26 ? c.Planar2Interleaved().ConvertToYV16().mt_makediff(rg11DD.Planar2Interleaved().ConvertToYV16(),U=2,V=2).ConvertToYUY2().Interleaved2planar() : c.mt_makediff(rg11DD,U=2,V=2) }
  578.  
  579. ########################################
  580. ## cretindesalpes' functions: (http://forum.doom9.org/showthread.php?p=1505297#post1505297)
  581.  
  582. # Converts 16 bit interleaved YUY2 to 16bit planar YUY2 suitable for Ditherpost. (Use right before Ditherpost; this format is not suitable for filtering)
  583.  
  584. function Dither_YUY2toPlanar16(c){c
  585. yuy26   = !(VersionNumber() < 2.60) && isyuy2(c)
  586. my = !yuy26 ? Dither_get_msb().ConvertToYV12() : nop()
  587. ly = !yuy26 ? Dither_get_lsb().ConvertToYV12() : nop()
  588. u = !yuy26 ? UToY ().ConvertToYV12 () : nop()
  589. v = !yuy26 ? VToY ().ConvertToYV12 () : nop()
  590. yuy26 ? ConvertToYV16() : YToUV (u, v, StackVertical (StackVertical (my, my), StackVertical (ly, ly)))}
  591.  
  592.  
  593. # Converts 8 bit interleaved YUY2 to 8 bit planar YUY2 ready for either 8 or 16 bit processing also suitable for Ditherpost
  594.  
  595. function Dither_YUY2toPlanar(c){c
  596. yuy26   = !(VersionNumber() < 2.60) && isyuy2(c)
  597. y = !yuy26 ? ConvertToYV12 () : nop()
  598. u = !yuy26 ? UToY ().ConvertToYV12 () : nop()
  599. v = !yuy26 ? VToY ().ConvertToYV12 () : nop()
  600. yuy26 ? ConvertToYV16() : YToUV (u, v, StackVertical (y, y))}
  601.  
  602.  
  603. # Converts back the above special planar formats to normal interleaved 16 bit YUY2
  604.  
  605. function Dither_YUY2toInterleaved16(c){c
  606. yuy26   = !(VersionNumber() < 2.60)
  607. y = !yuy26 ? StackVertical (Crop (0, 0, 0, (Height () /(4))), Crop (0, (Height () /(2))+(Height () /(4)), 0, 0)).ConvertToYUY2 () : nop()
  608. u = !yuy26 ? UToY ().ConvertToYUY2 () : nop()
  609. v = !yuy26 ? VToY ().ConvertToYUY2 () : nop()
  610. yuy26 ? ConvertToYUY2() : YToUV (u, v, y)}
  611.  
  612. # Converts back the above special planar formats to normal interleaved YUY2
  613.  
  614. function Dither_YUY2toInterleaved(c){c
  615. yuy26   = !(VersionNumber() < 2.60)
  616. y = !yuy26 ? Crop (0, 0, 0, Height () /(2)).ConvertToYUY2 () : nop()
  617. u = !yuy26 ? UToY ().ConvertToYUY2 () : nop()
  618. v = !yuy26 ? VToY ().ConvertToYUY2 () : nop()
  619. yuy26 ? ConvertToYUY2() : YToUV (u, v, y)}
  620.  
  621.  
  622.  
  623. # Converts luma (and chroma) to PC levels, and optionally allows tweaking for pumping up the darks. (for the clip to be fed to motion search only)
  624. # By courtesy of cretindesalpes. (http://forum.doom9.org/showthread.php?p=1548318#post1548318)
  625.  
  626. function Dither_Luma_Rebuild (clip src, float "s0", float "c",int "uv", bool "lsb", bool "lsb_in", bool "lsb_out", int "mode", float "ampn", bool "slice"){
  627. lsb_in  = Default( lsb_in  ,false)
  628. lsb_out = Default( lsb_out ,false)
  629. lsb     = Default( lsb     ,lsb_in || lsb_out)
  630. mode    = Default( mode ,6)
  631. uv      = Default(uv,    3)
  632. s0      = Default(s0,  2.0)
  633. c       = Default(c,  1.0/16)
  634. ampn    = Default(ampn, 0.0)
  635. slice   = Default(slice, true)
  636. yuy26   = !(VersionNumber() < 2.60) && isyuy2(src)
  637. src     = yuy26 ? src.Planar2Interleaved().ConvertToYV16() : src
  638.  
  639.     k = (s0 - 1) * c
  640.     t = lsb_in ? "x 4096 - 56064 / 0 1 clip" : "x 16 - 219 / 0 1 clip"
  641.     e = String(k)+" "+String(1+c)+" "+String((1+c)*c)+" "+t+" "+String(c)
  642. \       +" + / - * "+t+" 1 "+String(k)+" - * + "+String(lsb?65536:255)+" *"
  643. src
  644. lsb ? (lsb_in ? Dither_lut16 (yexpr=e,expr="x 32768 - 32768 * 28672 / 32768 +",y=3, u=uv, v=uv)   : \
  645.                 Dither_lut8  (yexpr=e,expr="x 128 - 32768 * 112 / 32768 +"    ,y=3, u=uv, v=uv))  : \
  646.                 mt_lut       (yexpr=e,expr="x 128 - 128 * 112 / 128 +"        ,y=3, u=uv, v=uv)
  647. lsb_out ? last : (lsb ? Ditherpost(mode=mode,ampn=ampn,slice=slice,staticnoise=ampn!=0.0?true:false,u=uv,v=uv) : last)
  648. return yuy26 ? last.ConvertToYUY2().Interleaved2planar() : last
  649. }
  650.  
  651.  
  652.  
  653. # SMDegrain prefilters
  654.  
  655. function SMDegrain_prefilters (clip input, int "prefilter", bool "chroma", int "Chr", int "Chr2", int "bug_wa", bool "lsb", bool "lsb_in", bool "Interlaced", val "if5", int "pel", String "device_type", int "device_id", int "d", int "a", bool "slices", bool "planar", clip "inputP", clip "input8", clip "input8y", clip "inputY", val "input8h"){
  656. Interlaced = Default( Interlaced  ,false)
  657. slices       = default(slices, true)
  658. if5            = Default( if5  ,interlaced ? (GetParity(input)                            ? true : false) : nop())
  659. lsb_in       = Default( lsb_in  ,false)
  660. lsb            = Default( lsb     ,lsb_in)
  661. pel          = default( pel, (input.width () > 1099 ||  input.height() > (lsb_in ? 1199 : 599)) ? 1 : 2 )
  662. chroma     = Default( chroma  ,true)
  663. planar       = Default( planar  ,false)
  664. prefilter    = Default( prefilter ,3)
  665. d            = Default( d ,1)
  666. a            = Default( a ,1)
  667. deviceid    = Default( device_id ,0)
  668. devicetype    = Default( device_type ,"GPU")
  669. Chr           = Default(Chr,     chroma ? 3 : 1)
  670. Chr2         = Default(Chr2,    chroma ? 3 : (prefilter==3 ? 2 : 1))
  671. avs26       = !(VersionNumber() < 2.60)
  672.  
  673. # Input preparation for: LSB_IN, Interlacing, Planar and MSuper optimization when pel=2
  674.  
  675. inputY  = defined(inputY )                    ? inputY  : planar      ? (lsb_in   ? Dither_YUY2toPlanar16(input)          : Interleaved2planar(input))                          : input
  676.  
  677. inputP  = defined(inputP )                    ? inputP  : !interlaced ? (pel == 2 ? inputY.AssumeFrameBased()             : inputY)                                             : \
  678.                                                                      (if5      ? inputY.AssumeTFF().SeparateFields()   : inputY.AssumeBFF().SeparateFields())
  679.  
  680. input8h = defined(input8h) && isclip(input8h) ? input8h :    lsb_in      ?             inputP. Ditherpost(mode=6, slice=slices)                                                    : nop()
  681. input8y = defined(input8y)                    ? input8y : planar      ? (lsb_in   ? input8h.Dither_YUY2toInterleaved()    : inputP)                                             : inputP
  682. input8  = defined(input8 )                    ? input8  : lsb_in      ? (planar   ? input8y.Interleaved2planar()                                                                : \
  683.                                                                                        input8h)                                                                                    : input8y
  684.  
  685. bug_wa    = defined(bug_wa) ? bug_wa : interlaced && planar && chroma && !avs26 ? 2 : Chr # bug: crash prevention workaround (http://forum.doom9.org/showthread.php?p=1546684#post1546684)
  686.  
  687. # The mt_merge() line for prefilter=3 should be swapped with a high bitdepth variant (Dither_merge16_8() ?) due to a 1 point limited range
  688. # in both range ends, but then it won't work with planar sources. This isn't as critical since we are only trying to find motion vectors.
  689.                      (prefilter==0)  ?  input8.MinBlur(0,Chr,planar)                                               : \
  690.                      (prefilter==1)  ?  input8.MinBlur(1,Chr,planar)                                               : \
  691.                      (prefilter==2)  ?  input8.MinBlur(2,Chr,planar)                                               : \
  692.                      (prefilter==3)  ?  (!planar && lsb ? Dither_merge16_8(inputP.Dfttest(sstring="0.0:4.0 0.2:9.0 1.0:15.0",tbsize=1,u=chroma,v=chroma,lsb=true,lsb_in=lsb_in,quiet=true), lsb_in?inputP:inputP.Dither_convert_8_to_16(),                                \
  693.                                                                    lsb_in?inputP.Dither_lut16("x 4096 < 65535 x 19200 > 0 65535 x 4096 - 65535 19200 4096 - / * - ? ?",u=1,v=1).Ditherpost(mode=6, slice=slices, u=Chr,   v=Chr)                                           \
  694.                                                                          :inputP.mt_lut(      "x 16 < 255 x 75 > 0 255 x 16 - 255 75 16 - / * - ? ?",u=1,v=1), luma=chroma,                       u=Chr2,  v=Chr2)                                                       : \
  695.                                  avs26 && planar && lsb ? Dither_merge16_8(inputP.Dfttest(sstring="0.0:4.0 0.2:9.0 1.0:15.0",tbsize=1,u=chroma,v=chroma,lsb=true,lsb_in=lsb_in,quiet=true), lsb_in?inputP:inputP.Dither_convert_8_to_16(),                                \
  696.                                                                    lsb_in?inputP.Dither_lut16("x 4096 < 65535 x 19200 > 0 65535 x 4096 - 65535 19200 4096 - / * - ? ?",u=1,v=1).Ditherpost(mode=6, slice=slices, u=Chr,   v=Chr)                                           \
  697.                                                                          :inputP.Planar2Interleaved().ConvertToYV16().mt_lut(      "x 16 < 255 x 75 > 0 255 x 16 - 255 75 16 - / * - ? ?",u=1,v=1), luma=chroma,                       u=Chr2,  v=Chr2).ConvertToYUY2().Interleaved2planar()                                                       : \
  698.                                            planar && avs26 ? mt_merge(           Dfttest(!lsb_in?inputP.Planar2Interleaved(!chroma):input8y,sstring="0.0:4.0 0.2:9.0 1.0:15.0",tbsize=1,u=chroma,v=chroma,dither=1).ConvertToYV16(),!lsb_in?input8y.Planar2Interleaved().ConvertToYV16():input8y.ConvertToYV16(),                                                   \
  699.                                                                           input8y.Planar2Interleaved().ConvertToYV16().mt_lut(      "x 16 < 255 x 75 > 0 255 x 16 - 255 75 16 - / * - ? ?",u=1,v=1), luma=planar?false:chroma,          u=bug_wa,v=bug_wa).ConvertToYUY2().Interleaved2planar()                                                    : \
  700.                                                              mt_merge( planar ?  Dfttest(!lsb_in?inputP.Planar2Interleaved(!chroma):input8y,sstring="0.0:4.0 0.2:9.0 1.0:15.0",tbsize=1,u=chroma,v=chroma,dither=1).Interleaved2planar(!chroma)                          : \
  701.                                                                                  Dfttest(        inputP,                                    sstring="0.0:4.0 0.2:9.0 1.0:15.0",tbsize=1,u=chroma,v=chroma,dither=1),!lsb_in?input8y:input8y.Interleaved2planar(!chroma),   \
  702.                                                                           input8y.mt_lut(      "x 16 < 255 x 75 > 0 255 x 16 - 255 75 16 - / * - ? ?",u=1,v=1), luma=planar?false:chroma,          u=bug_wa,v=bug_wa))                                                   : \
  703.                      (prefilter==4)  ?  eval("""
  704.                                              # In a more lucid state I could probably have laid out this block much better... or not...
  705.                                              fullchr = inputP.isyv24()
  706.                                              chr422 = inputP.isyv16() || planar
  707.                                              NL_in   = !chr422 ? (lsb_in || !lsb ? inputP : input8.Dither_convert_8_to_16()) : Interlaced ? (if5 ? lsb ? input.AssumeTFF().SeparateFields().Dither_convert_8_to_16() : input.AssumeTFF().SeparateFields() : lsb ? input.AssumeBFF().SeparateFields().Dither_convert_8_to_16() : input.AssumeBFF().SeparateFields()) : (lsb_in || !lsb ? input : input.Dither_convert_8_to_16())
  708.                                              NL_W    = !fullchr ? width(NL_in) : nop()
  709.                                              U8      = (chroma || chr422) && !fullchr ? UToY8(NL_in) : nop()
  710.                                              V8      = (chroma || chr422) && !fullchr ? VToY8(NL_in) : nop()
  711.                                              NL_lsb  = chroma && !fullchr ? (!chr422 ?           StackVertical(lsb ? StackVertical(Dither_get_msb(u8),Dither_get_msb(v8)) : u8,\
  712.                                                                                      lsb ? StackVertical(Dither_get_lsb(u8),Dither_get_lsb(v8)) : v8)              :\
  713.                                                                                      StackHorizontal(u8,v8)) : nop()
  714.  
  715.                                              nlc      = chroma && !fullchr ? (!chr422 ? StackHorizontal(ConvertToY8(NL_in),NL_lsb) : \
  716.                                                                            StackHorizontal(lsb ? StackVertical(Dither_get_msb(ConvertToY8(NL_in)),Dither_get_lsb(ConvertToY8(NL_in))) : ConvertToY8(NL_in),NL_lsb)) : \
  717.                                                                 (!chr422 ? NL_in : NL_in.converttoYV16())
  718.  
  719.                                              nlc      = nlc.KNLMeansCL(D=d, A=a, h=7.0,lsb_inout=lsb_in || lsb,device_type=devicetype,device_id=deviceid,cmode=chroma && fullchr)
  720.  
  721.                                              my      = chr422 ? lsb_in || lsb ? nlc.Dither_get_msb().crop(0,0,chroma && !fullchr ? -NL_W:0,0) : nlc.crop(0,0,chroma && !fullchr ? -NL_W:0,0) : nop()
  722.                                              ly      = chr422 && (lsb_in || lsb) ? nlc.Dither_get_lsb().crop(0,0,chroma && !fullchr ? -NL_W:0,0) : nop()
  723.  
  724.                                              chroma && !fullchr ? eval ("
  725.                                               u_h = lsb_in || lsb ? u8.height()/2 : u8.height()
  726.                                               v_h = lsb_in || lsb ? v8.height()/2 : v8.height()
  727.  
  728.                                               u16 = !chr422 ? lsb_in || lsb ? StackVertical(Dither_get_msb(nlc).crop(NL_W,0,0,-v_h),Dither_get_lsb(nlc).crop(NL_W,0,0,-v_h)) : nlc.crop(NL_W,0,0,-v_h)                : \
  729.                                                               lsb_in || lsb ? StackVertical(Dither_get_msb(nlc).crop(NL_W,0,-NL_W/2 ,0),Dither_get_lsb(nlc).crop(NL_W,0,-NL_W/2 ,0)) : nlc.crop(NL_W,0,-NL_W/2 ,0)
  730.                                               v16 = !chr422 ? lsb_in || lsb ? StackVertical(Dither_get_msb(nlc).crop(NL_W,u_h, 0,0),Dither_get_lsb(nlc).crop(NL_W,u_h, 0,0)) : nlc.crop(NL_W,u_h, 0,0)                : \
  731.                                                               lsb_in || lsb ? StackVertical(Dither_get_msb(nlc).crop(NL_W+NL_W/2,0,0,0),Dither_get_lsb(nlc).crop(NL_W+NL_W/2,0,0,0)) : nlc.crop(NL_W+NL_W/2,0,0,0)
  732.  
  733.                                               !chr422 ? YToUV(u16,v16,nlc.crop(0,0,-u8.width(),0)) : planar ? YToUV(u16, v16, lsb_in || lsb ? StackVertical(my, ly) : my).converttoyuy2() : YToUV(u16, v16, lsb_in || lsb ? StackVertical(my, ly) : my) ") : \
  734.                                            planar ? nlc.converttoyuy2() : nlc  """)                                   : \
  735.                       Assert(false,    "prefilter must be between 0~4: "+string(prefilter))
  736. }
Advertisement
Add Comment
Please, Sign In to add comment