Advertisement
Guest User

dfttestMC and MC things

a guest
Apr 19th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Motion-compensated dfttest by twc
  2. # Aka: Really Really Really Slow
  3. #
  4. # v2 by BakaProxy
  5. # Aka: Even more Really Really Really slow
  6. # Added: Recalculate, (proper) 16 bit input handling, dither_luma_rebuild and some masking to prevent 16 bit data loss from 8 bit Mdegrain and Mcompensate
  7. #
  8. #
  9. # v3.91 by A.SONY
  10. # make it work in normal avs again and some fix, and not that slow if you use it without lsb/lsb_in
  11. # add slice bool to use it to avoid artifacts with avstp
  12. # clean up
  13. # New Features
  14. #
  15. # Requirements:
  16. # dfttest
  17. # MVTools2
  18. #
  19. # Suggested:
  20. # Dither (for stack16 processing)
  21. #
  22. # Description of function parameters:
  23. #
  24. # pp = Clip to calculate vectors from (default input)
  25. # mc = Number of frames in each direction to compensate (default 2, max 5)
  26. # mdg = Run MDeGrain before dfttest (default false)
  27. # mdgSAD = thSAD for MDeGrain (default 400)
  28. # lsb = stack16 output and processing (default false)
  29. #
  30. # dfttest Y, U, V, sigma, sbsize, sosize, tbsize, and dither are supported.
  31. # Extra dfttest parameters may be passed via dfttest_params.
  32. # MVTools2 pel, thSCD, thSAD, blksize, overlap, dct, search, and
  33. # searchparam are also supported.
  34. #
  35. # sigma is the main control of dfttest strength.
  36. # tbsize should not be set higher than mc * 2 + 1.
  37.  
  38. function dfttestMC(clip input, clip "pp", int "mc", bool "mdg", bool "Y", bool "U", bool "V", float "sigma", int "sbsize", int "sosize", int "tbsize", int "dither", bool "lsb",bool "lsb_in",bool "pp_lsb_in",int "super_filter",
  39.     \ string "dfttest_params",float "rStr",float "Amp", int "mdgSAD", int "thSAD", int "thSCD1", int "thSCD2", bool "recalculate", bool "truemotion", int "pel", int "blksize", int "search", int "searchparam", int "overlap",
  40.         \ int "dct", bool "slices", bool "luma_rebuild", string "nstring", string "sstring", string "ssx", string "ssy", string "sst", bool "mdg_domask", string "mdg_mask", clip "ppsuper", clip "super", clip "exmcclip", bool "hd", clip "input8")
  41. {
  42.     # Set default options. Most external parameters are passed valueless.
  43.    
  44.     exmc = defined(exmcclip)
  45.     mc = default(mc, 2).min(5)
  46.     Y = default(Y, true)
  47.     U = default(U, true)
  48.     V = default(V, true)
  49.     mdg = default(mdg, false)
  50.     lsb = default(lsb, false)
  51.     lsb_in = default(lsb_in, false)
  52.     input8 = defined(input8) ? input8 : lsb_in ? input.ditherpost(mode=7,slice=slices,y=y ? 3 : 1,u=u ? 3 : 1,v=v ? 3 : 1) : input
  53.     super_filter = default(super_filter,4)
  54.     pp_enabled = defined(pp)
  55.     pp_lsb_in = default(pp_lsb_in,(pp_enabled ? lsb_in ? (height(input) == height(pp)) ? true : false : false : false ))
  56.     lsb_enable = false
  57.     truemotion = default(truemotion,true)
  58.     tbsize = default(tbsize, mc * 2 + 1)
  59.     dfttest_params = default(dfttest_params, "")
  60.     ox = defined(HD) ? nop() : input8.width()
  61.     oy = defined(HD) ? nop() : input8.height()
  62.     HD = defined(HD) ? HD : (ox > 1099 || oy > 599)
  63.     pel = default( pel, HD ? 1 : 2 )
  64.     blksize = default(blksize,HD ? 16:8)
  65.     blksize2 = int(blksize/2) + (int(blksize/2)%2)
  66.     search = default(search, HD ? 4 : 5)
  67.     overlap = default(overlap,blksize2)
  68.     overlap2 = int(overlap/2) + (int(overlap/2)%2)
  69.     recalculate = default(recalculate,mdg)
  70.     mdgSAD = default(mdgSAD,   400)
  71.     mdgSAD2= mdgSAD/2
  72.     thSAD  = default(thSAD ,   mdgSAD)
  73.     rStr         = default( rStr, 1.0 )
  74.     Amp          = default( Amp, 0.0625 )
  75.     slices       = default(slices, true)
  76.     luma_rebuild = default(luma_rebuild, true)
  77.     mdg_domask   = default(mdg_domask, mdg)
  78.  
  79.     avs26  = VersionNumber() < 2.60 ? false : true
  80.  
  81.     # Set chroma parameters.
  82.     chroma = U || V
  83.     plane  = U && !Y && !V ? 1 : V && !Y && !U ? 2 : chroma && !Y ? 3 : Y && chroma ? 4 : 0
  84.  
  85.     # Prepare supersampled clips.
  86.     !exmc || mdg ? eval("""
  87.     pp = (pp_enabled) && !defined(ppsuper) ? luma_rebuild ? pp.dither_luma_rebuild(S0=rStr,c=Amp,slice=slices,lsb_in=pp_lsb_in,lsb_out=false,uv=((U&&v)?3:1)) : pp : nop()
  88.     pp_super = defined(ppsuper) ? ppsuper : exmc ? nop() : pp_enabled ? MSuper(pp, pel=pel, chroma=chroma,rfilter=super_filter) : MSuper(input8, pel=pel, chroma=chroma)
  89.     super = defined(super) ? super : pp_enabled ? input8.MSuper(pel=pel, levels=1, chroma=chroma) : pp_super
  90.     recalc_sup = recalculate && pp_enabled ? MSuper(pp,pel=pel, levels=1, chroma=chroma) : pp_super
  91.    
  92.     # Motion vector search.
  93.     b5vec = mc == 5 ? MAnalyse(pp_super, delta=5, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  94.     b4vec = mc >  3 ? MAnalyse(pp_super, delta=4, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  95.     b3vec = mc >  2 ? MAnalyse(pp_super, delta=3, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  96.     b2vec = mc >  1 ? MAnalyse(pp_super, delta=2, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  97.     b1vec = MAnalyse(pp_super, delta=1, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion)
  98.     f1vec = MAnalyse(pp_super, delta=1, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion)
  99.     f2vec = mc >  1 ? MAnalyse(pp_super, delta=2, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  100.     f3vec = mc >  2 ? MAnalyse(pp_super, delta=3, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  101.     f4vec = mc >  3 ? MAnalyse(pp_super, delta=4, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  102.     f5vec = mc == 5 ? MAnalyse(pp_super, delta=5, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  103.     """) : nop()
  104.  
  105.    
  106.     recalculate ? Eval("""
  107.     b5vec = mc == 5 ? MRecalculate(recalc_sup,b5vec , chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion) : nop()
  108.     b4vec = mc >  3 ? MRecalculate(recalc_sup,b4vec , chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion) : nop()
  109.     b3vec = mc >  2 ? MRecalculate(recalc_sup,b3vec , chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion) : nop()
  110.     b2vec = mc >  1 ? MRecalculate(recalc_sup,b2vec , chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion) : nop()
  111.     b1vec = MRecalculate(recalc_sup,b1vec , chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion)
  112.     f1vec = MRecalculate(recalc_sup,f1vec, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion)
  113.     f2vec = mc >  1 ? MRecalculate(recalc_sup,f2vec, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion) : nop()
  114.     f3vec = mc >  2 ? MRecalculate(recalc_sup,f3vec, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion) : nop()
  115.     f4vec = mc >  3 ? MRecalculate(recalc_sup,f4vec, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion) : nop()
  116.     f5vec = mc == 5 ? MRecalculate(recalc_sup,f5vec, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap2, blksize=blksize2, dct=dct,thSAD=mdgSAD2,truemotion=truemotion) : nop()
  117.     """) : nop()
  118.  
  119.     # Optional MDegrain.
  120.     Eval("""
  121.     try {
  122.         degrained = lsb || lsb_in ? mc == 5 && mdg ? MDeGrain5(input8, super, b1vec, f1vec, b2vec, f2vec, b3vec, f3vec, b4vec, f4vec, b5vec, f5vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2, lsb=true) :
  123.             \ mc == 4 && mdg ? MDeGrain4(input8, super, b1vec, f1vec, b2vec, f2vec, b3vec, f3vec, b4vec, f4vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2, lsb=true) :
  124.             \ mc == 3 && mdg ? MDeGrain3(input8, super, b1vec, f1vec, b2vec, f2vec, b3vec, f3vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2, lsb=true) :
  125.             \ mc == 2 && mdg ? MDeGrain2(input8, super, b1vec, f1vec, b2vec, f2vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2, lsb=true) :
  126.             \ mdg ? MDeGrain1(input8, super, b1vec, f1vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2, lsb=true) : lsb_in ? input : errmsggonext :
  127.             \ errmsggonext
  128.             degrained  = mdg_domask && mdg ? defined(mdg_mask) ? eval(mdg_mask) : DarkPreserve_function(degrained,input,lsb_in=lsb_in) : degrained
  129.             degrained8 = lsb ? degrained.dither_get_msb() : degrained.ditherpost(mode=7,slice=slices,y=y ? 3 : 1,u=u ? 3 : 1,v=v ? 3 : 1)
  130.             lsb_enable = true
  131.         } catch(err_msg)
  132.         {
  133.         degrained8 = avs26 && mc == 5 && mdg ? MDeGrain5(input8, super, b1vec, f1vec, b2vec, f2vec, b3vec, f3vec, b4vec, f4vec, b5vec, f5vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2) :
  134.             \ avs26 && mc == 4 && mdg ? MDeGrain4(input8, super, b1vec, f1vec, b2vec, f2vec, b3vec, f3vec, b4vec, f4vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2) :
  135.             \ mc >= 3 && mdg ? MDeGrain3(input8, super, b1vec, f1vec, b2vec, f2vec, b3vec, f3vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2) :
  136.             \ mc == 2 && mdg ? MDeGrain2(input8, super, b1vec, f1vec, b2vec, f2vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2) :
  137.             \ mdg ? MDeGrain1(input8, super, b1vec, f1vec, thSAD=mdgSAD, plane=plane, thSCD1=thSCD1, thSCD2=thSCD2) : input8
  138.             degrained8 = mdg_domask && mdg ? defined(mdg_mask) ? eval(mdg_mask) : DarkPreserve_function(degrained8,input,lsb_in=lsb_in) : degrained8
  139.         lsb_enable = false
  140.         }
  141.     """)
  142.     !exmc ? eval("""
  143.     degrained_super = mdg ? MSuper(degrained8, pel=pel, levels=1, chroma=chroma) : super
  144.     b5clip = mc == 5 ? MCompensate(degrained8, degrained_super, b5vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  145.     b4clip = mc >  3 ? MCompensate(degrained8, degrained_super, b4vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  146.     b3clip = mc >  2 ? MCompensate(degrained8, degrained_super, b3vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  147.     b2clip = mc >  1 ? MCompensate(degrained8, degrained_super, b2vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  148.     b1clip = MCompensate(degrained8, degrained_super, b1vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2)
  149.     f1clip = MCompensate(degrained8, degrained_super, f1vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2)
  150.     f2clip = mc >  1 ? MCompensate(degrained8, degrained_super, f2vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  151.     f3clip = mc >  2 ? MCompensate(degrained8, degrained_super, f3vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  152.     f4clip = mc >  3 ? MCompensate(degrained8, degrained_super, f4vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  153.     f5clip = mc == 5 ? MCompensate(degrained8, degrained_super, f5vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  154.     """) : nop()
  155.  
  156.     # Create compensated clip.
  157.     interleaved = !exmc && mc == 5 ? Interleave(f5clip, f4clip, f3clip, f2clip, f1clip, degrained8, b1clip, b2clip, b3clip, b4clip, b5clip) :
  158.         \ !exmc &&  mc == 4 ? Interleave(f4clip, f3clip, f2clip, f1clip, degrained8, b1clip, b2clip, b3clip, b4clip) :
  159.         \ !exmc &&  mc == 3 ? Interleave(f3clip, f2clip, f1clip, degrained8, b1clip, b2clip, b3clip) :
  160.         \ !exmc &&  mc == 2 ? Interleave(f2clip, f1clip, degrained8, b1clip, b2clip) :
  161.         \ !exmc ?  Interleave(f1clip, degrained8, b1clip) : exmcclip
  162.  
  163.       degrained = lsb_enable ? lsb_in && mdg ? input.Dither_limit_dif16(degrained, thr=1.0, elast=2.0) : degrained : nop()
  164.       degrained = lsb_enable ? degrained : lsb_in ? input.Dither_limit_dif16(degrained8.dither_convert_8_to_16(), thr=1.0, elast=2.0) : nop()
  165.  
  166.         degrained16mc = lsb_enable || lsb_in ? degrained.changefps(interleaved,linear=true) : nop()
  167.  
  168.         mask = lsb_enable || lsb_in ? mt_logic(interleaved,degrained16mc.dither_get_msb(), "xor",y=y ? 3 : 1,u=u ? 3 : 1,v=v ? 3 : 1).mt_binarize(0,y=y ? 3 : 1,u=u ? 3 : 1,v=v ? 3 : 1) : nop()
  169.  
  170.         interleaved16 = lsb_enable || lsb_in ? Dither_merge16_8(degrained16mc,interleaved.dither_convert_8_to_16(),mask,u=u ? 3 : 1,v=v ? 3 : 1) : interleaved
  171.        
  172.     # Perform dfttest. Exception handling required for official dfttest.
  173.     Eval("""
  174.     try {
  175.         filtered = Eval("dfttest(interleaved16, Y=Y, U=U, V=V, sigma=sigma, sbsize=sbsize, sosize=sosize, tbsize=tbsize, dither=dither, lsb=lsb,lsb_in=lsb_enable || lsb_in, nstring=nstring, sstring=sstring, ssx=ssx, ssy=ssy, sst=sst" + dfttest_params + ")")
  176.         } catch(err_msg)
  177.         {
  178.         filtered = Eval("dfttest(interleaved, Y=Y, U=U, V=V, sigma=sigma, sbsize=sbsize, sosize=sosize, tbsize=tbsize, dither=dither, nstring=nstring, sstring=sstring, ssx=ssx, ssy=ssy, sst=sst" + dfttest_params + ")")
  179.         }
  180.     """)
  181.        
  182.     return selectEvery(filtered, mc * 2 + 1, mc)
  183. }
  184.  
  185.  
  186. #### helper functions for admfilter, and some others MC warper/template
  187.  
  188. function sMCclips(clip input, clip pp_super, clip super, int "mc",
  189.     \ int "thSAD", int "thSCD1", int "thSCD2", bool "truemotion", bool "chroma", int "blksize", int "search", int "searchparam", int "overlap",
  190.         \ int "dct", bool "HD")
  191. {
  192.     mc = default(mc, 2).min(5)
  193.     HD = default(HD, false)
  194.     truemotion = default(truemotion,true)
  195.     blksize = default(blksize,HD ? 16:8)
  196.     blksize2 = int(blksize/2) + (int(blksize/2)%2)
  197.     search = default(search, HD ? 4 : 5)
  198.     overlap = default(overlap,blksize2)
  199.     thSAD  = default(thSAD ,   400)
  200.     chroma   = default(chroma, true)
  201.    
  202.     # Motion vector search.
  203.     b5vec = mc == 5 ? MAnalyse(pp_super, delta=5, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  204.     b4vec = mc >  3 ? MAnalyse(pp_super, delta=4, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  205.     b3vec = mc >  2 ? MAnalyse(pp_super, delta=3, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  206.     b2vec = mc >  1 ? MAnalyse(pp_super, delta=2, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  207.     b1vec = MAnalyse(pp_super, delta=1, isb=true, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion)
  208.     f1vec = MAnalyse(pp_super, delta=1, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion)
  209.     f2vec = mc >  1 ? MAnalyse(pp_super, delta=2, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  210.     f3vec = mc >  2 ? MAnalyse(pp_super, delta=3, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  211.     f4vec = mc >  3 ? MAnalyse(pp_super, delta=4, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  212.     f5vec = mc == 5 ? MAnalyse(pp_super, delta=5, chroma=chroma, search=search, searchparam=searchparam, overlap=overlap, blksize=blksize, dct=dct,truemotion=truemotion) : nop()
  213.  
  214.     eval("""
  215.     b5clip = mc == 5 ? MCompensate(input, super, b5vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  216.     b4clip = mc >  3 ? MCompensate(input, super, b4vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  217.     b3clip = mc >  2 ? MCompensate(input, super, b3vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  218.     b2clip = mc >  1 ? MCompensate(input, super, b2vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  219.     b1clip = MCompensate(input, super, b1vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2)
  220.     f1clip = MCompensate(input, super, f1vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2)
  221.     f2clip = mc >  1 ? MCompensate(input, super, f2vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  222.     f3clip = mc >  2 ? MCompensate(input, super, f3vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  223.     f4clip = mc >  3 ? MCompensate(input, super, f4vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  224.     f5clip = mc == 5 ? MCompensate(input, super, f5vec, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2) : nop()
  225.     """)
  226.  
  227.     # Create compensated clip.
  228.     interleaved = mc == 5 ? Interleave(f5clip, f4clip, f3clip, f2clip, f1clip, input, b1clip, b2clip, b3clip, b4clip, b5clip) :
  229.         \  mc == 4 ? Interleave(f4clip, f3clip, f2clip, f1clip, input, b1clip, b2clip, b3clip, b4clip) :
  230.         \ mc == 3 ? Interleave(f3clip, f2clip, f1clip, input, b1clip, b2clip, b3clip) :
  231.         \ mc == 2 ? Interleave(f2clip, f1clip, input, b1clip, b2clip) :
  232.         \ Interleave(f1clip, input, b1clip)
  233.        
  234.     return interleaved
  235. }
  236.  
  237. function spp_super(clip input, clip "pp", int "dither", bool "lsb",bool "lsb_in",bool "pp_lsb_in",int "super_filter",
  238.     \ float "rStr",float "Amp", int "pel", bool "Y", bool "U", bool "V",
  239.         \ bool "slices", bool "luma_rebuild", bool "HD")
  240. {
  241.     Y = default(Y, true)
  242.     U = default(U, true)
  243.     V = default(V, true)
  244.     HD = default(HD, false)
  245.     lsb_in = default(lsb_in, false)
  246.     input8 = lsb_in ? input.ditherpost(mode=7,slice=slices,y=y ? 3 : 1,u=u ? 3 : 1,v=v ? 3 : 1) : input
  247.     super_filter = default(super_filter,4)
  248.     pp_enabled = defined(pp)
  249.     pp_lsb_in = default(pp_lsb_in,(pp_enabled ? lsb_in ? (height(input) == height(pp)) ? true : false : false : false ))
  250.     pel = default( pel, HD ? 1 : 2 )
  251.     rStr         = default( rStr, 1.0 )
  252.     Amp          = default( Amp, 0.0625 )
  253.     slices       = default(slices, true)
  254.     luma_rebuild = default(luma_rebuild, true)
  255.    
  256.     # Set chroma parameters.
  257.     chroma = U || V
  258.  
  259.     # Prepare supersampled clips.
  260.     pp = (pp_enabled) ? luma_rebuild ? pp.dither_luma_rebuild(S0=rStr,c=Amp,slice=slices,lsb_in=pp_lsb_in,lsb_out=false,uv=((U&&v)?3:1)) : pp : nop()
  261.     pp_super = pp_enabled ? MSuper(pp, pel=pel, chroma=chroma,rfilter=super_filter) : MSuper(input8, pel=pel, chroma=chroma)
  262.        
  263.     return pp_super
  264. }
  265.  
  266. # sMCwarper v1.2
  267. function sMCwarper(clip input, string "filter", int "mc", val "prefilter", bool "TV_range", clip "exmcclip", clip "super", clip "pp_super", bool "Y", bool "U", bool "V",
  268.     \ int "thSAD", int "thSCD1", int "thSCD2", bool "truemotion", bool "chroma", int "blksize", int "search", int "searchparam", int "overlap", int "dct",
  269.         \ bool  "HD",bool "slices",float "rStr",float "Amp", int "pel",int "super_filter")
  270. {
  271.         exmc = defined(exmcclip)
  272.         !exmc ? eval("
  273.         mc = default(mc, 2).min(5)
  274.         chroma = default(chroma, true)
  275.         Y = default(Y, true)
  276.         U = default(U, chroma)
  277.         V = default(V, U)
  278.         TV_range  = default( TV_range, !(Isrgb(input)))
  279.         HDbool = defined(HD)
  280.         ox = HDbool ? nop() : input.width()
  281.         oy = HDbool ? nop() : input.height()
  282.         HD = HDbool ? HD : (ox > 1099 || oy > 599)
  283.         pel = default( pel, HD ? 1 : 2 )
  284.         prefilterdef = defined(prefilter)
  285.         prefilterisint = prefilterdef ? isint(prefilter) : false
  286.         prefilterbool = prefilterdef ? isbool(prefilter) ? prefilter : prefilterisint ? prefilter!=0 : true : true
  287.         prefilter = prefilterisint && prefilterbool ? input.blur(1.53) : prefilter
  288.         prefilterisclip = prefilterdef ? isclip(prefilter) : false
  289.         sppbool = prefilterisclip ? true : TV_range ? true : false
  290.         pp_super =  defined(pp_super) ? pp_super : sppbool ? spp_super(input ,prefilterisclip ? prefilter :  input ,HD=HD,slices=slices,rStr=rStr,Amp=Amp,pel=pel,super_filter=super_filter,luma_rebuild=TV_range,y=y,u=u,v=v) : MSuper(pel=pel,rfilter=super_filter)
  291.         super = defined(super) ? super : sppbool ? input.MSuper(levels=1,pel=pel,rfilter=0) : pp_super
  292.                     ") : nop()
  293.         exmc ? exmcclip : input.sMCclips(pp_super, super,mc,thSAD,thSCD1,thSCD2,truemotion,chroma,blksize,search,searchparam,overlap,dct,HD)
  294.         eval(filter)
  295.         selectEvery(last, mc * 2 + 1, mc)
  296. }
  297.  
  298. # mcKNLMeansCL v1.2
  299. function mcKNLMeansCL(clip input, String "device_type", int "device_id", bool "chroma", bool "lsb", bool "lsb_in", float "h", int "d", int "a", String "knlm_params", bool "Y", bool "U", bool "V",
  300.     \ val "prefilter", bool "TV_range", clip "exmcclip", clip "super", clip "pp_super", int "thSAD", int "thSCD1", int "thSCD2", bool "truemotion", bool "chroma", int "blksize", int "search", int "searchparam", int "overlap", int "dct",
  301.         \ bool  "HD",bool "slices",float "rStr",float "Amp", int "pel",int "super_filter")
  302. {
  303.         d            = Default( d ,1).min(5)
  304.         a            = Default( a ,2)
  305.         h            = Default( h ,1.2)
  306. d==0 ? SMDegrain_KNLMeansCL(input, device_type, device_id, chroma, lsb, lsb_in, h, d, a, knlm_params) : \
  307.         eval("""
  308.     exmc = defined(exmcclip)
  309.         !exmc ? eval("
  310.         mc = d
  311.         chroma = default(chroma, true)
  312.         Y = default(Y, true)
  313.         U = default(U, chroma)
  314.         V = default(V, U)
  315.         TV_range  = default( TV_range, !(Isrgb(input)))
  316.         HDbool = defined(HD)
  317.         ox = HDbool ? nop() : input.width()
  318.         oy = HDbool ? nop() : input.height()
  319.         HD = HDbool ? HD : (ox > 1099 || oy > 599)
  320.         pel = default( pel, HD ? 1 : 2 )
  321.         prefilterdef = defined(prefilter)
  322.         prefilterisint = prefilterdef ? isint(prefilter) : false
  323.         prefilterbool = prefilterdef ? isbool(prefilter) ? prefilter : prefilterisint ? prefilter!=0 : true : true
  324.         prefilter = prefilterisint && prefilterbool ? input.blur(1.53) : prefilter
  325.         prefilterisclip = prefilterdef ? isclip(prefilter) : false
  326.         sppbool = prefilterisclip ? true : TV_range ? true : false
  327.         pp_super =  defined(pp_super) ? pp_super : sppbool ? spp_super(input ,prefilterisclip ? prefilter :  input ,HD=HD,slices=slices,rStr=rStr,Amp=Amp,pel=pel,super_filter=super_filter,luma_rebuild=TV_range,y=y,u=u,v=v) : MSuper(pel=pel,rfilter=super_filter)
  328.         super = defined(super) ? super : sppbool ? input.MSuper(levels=1,pel=pel,rfilter=0) : pp_super
  329.                     ") : nop()
  330.         exmc ? exmcclip : input.sMCclips(pp_super, super,mc,thSAD,thSCD1,thSCD2,truemotion,chroma,blksize,search,searchparam,overlap,dct,HD)
  331.         SMDegrain_KNLMeansCL(last, device_type, device_id, chroma, lsb, lsb_in, h, d, a, knlm_params)
  332.         selectEvery(last, mc * 2 + 1, mc)
  333.         """)
  334. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement