AddStaticGrainM source

From Avisynth wiki
Revision as of 00:01, 14 December 2015 by Raffriff42 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

source: http://pastebin.com/raw.php?i=wLSpAKHZ

function AddStaticGrainM(clip orig, int "cont", int "bright", int "grain", int "mode", float "mThresh", bool "showmask") {
#######################################
#
# Requires:
#   - AddGrain()
#   - RemoveGrain()
#   - MaskTools2
#   - gradfunkmirror()
#   - GradFun2dbMod()
#
#######################################
#
# cont - cont value of Tweak(). Lower value means weaker mask        
#   Default 4
#
# bright - bright value of Tweak(). Lower value means stronger mask. 
#   Default -128
#
# mode - values from 0 to 2
#       0 - no preprocessing
#       1 - preprocessing using gradfunkmirror()
#       2 - preprocessing using gradfun2dbmod()
#   Default 1
#
# mThresh - preprocessing strength
#   Default 1.2 for mode 1 and 2
#
# Showmask - enables preview of the mask. Brighter areas will have more grain applied to them. Useful for choosing settings. 
#   Default false
#
#######################################

    cont = Default(cont, 4)
    bright = Default(bright, -128)
    grain = Default(grain, 1)
    mode = Default(mode, 1)
    mThresh = Default(mThresh, 1.2)
    showmask = Default(showmask, false)
    
    clp = orig.IsYV12() ? orig : orig.ConvertToYV12()
    
    clp = (mode==1) ? clp.gradfunkmirror(mThresh) : clp
    clp = (mode==2) ? clp.gradfun2dbmod(mThresh) : clp
    
    grain = clp.AddGrain(1,constant=true)
    grainmask = clp.Tweak(cont,bright).GreyScale().Invert()
    clp.RemoveGrain(1)
    final = mt_merge(last,grain,grainmask,true)
    
    result = showmask ? grainmask : final
    
    return result
}
Personal tools