Sorry, I was a bit in a hurry.
I am talking about this part of SMDegrain.avsi:
Code: Select all
# SMDegrain prefilters
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", float "h", String "knlm_params", String "cplace")
{
Interlaced = Default( Interlaced ,false)
slices = default(slices, true)
if5 = Default( if5 ,interlaced ? (GetParity(input) ? true : false) : nop())
lsb_in = Default( lsb_in ,false)
lsb = Default( lsb ,lsb_in)
pel = default( pel, (input.width () > 1099 || input.height() > (lsb_in ? 1199 : 599)) ? 1 : 2 )
sisphbd = AvsPlusVersionNumber > 2294
chroma = default( chroma, true)
planar = Default( planar , input.isyuy2())
prefilter = Default( prefilter, 3)
cplace = Default( cplace, "mpeg2")
Chr = Default(Chr, chroma ? 3 : 1)
Chr2 = Default(Chr2, chroma ? 3 : (prefilter==3 ? 2 : 1))
avs26 = !(VersionNumber() < 2.60)
Assert(!(!defined(inputP) && prefilter==-1), "prefilter must be between 0~4: "+string(prefilter))
lsb_native = sisphbd ? !(Input.BitsPerComponent() > 8 && (lsb)) : true
sisphbd ? Assert(lsb_native, "lsb hack is not Compatible with native high bit depth" ) : nop()
# Input preparation for: LSB_IN, Interlacing, Planar and MSuper optimization when pel=2
inputY = defined(inputY ) ? inputY : planar ? (lsb_in ? Dither_YUY2toPlanar16(input) : Interleaved2planar(input)) : input
inputP = defined(inputP ) ? inputP : !interlaced ? (pel == 2 ? inputY.AssumeFrameBased() : inputY) : \
(if5 ? inputY.AssumeTFF().SeparateFields() : inputY.AssumeBFF().SeparateFields())
input8h = defined(input8h) && isclip(input8h) ? input8h : lsb_in ? inputP. Ditherpost(mode=6, slice=slices) : nop()
input8y = defined(input8y) ? input8y : planar ? (lsb_in ? input8h.Dither_YUY2toInterleaved() : inputP) : inputP
input8 = defined(input8 ) ? input8 : lsb_in ? (planar ? input8y.Interleaved2planar() : input8h) : input8y
inputd = (prefilter == 3 || prefilter == 4) ? Interlaced ? if5 ? input.AssumeTFF().SeparateFields() : \
input.AssumeBFF().SeparateFields() : \
input : nop()
bug_wa = defined(bug_wa) ? bug_wa : interlaced && planar && chroma && !avs26 ? 2 : Chr # bug: crash prevention workaround
# 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
# 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.
(prefilter==-1) ? inputP : \
(prefilter==0) ? input8.MinBlur(0,Chr,planar) : \
(prefilter==1) ? input8.MinBlur(1,Chr,planar) : \
(prefilter==2) ? input8.MinBlur(2,Chr,planar) : \
(prefilter==3) ? (!planar && lsb ? Dither_merge16_8( inputd.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(), \
lsb_in?inputP.Dither_lut16("x 4096 < 65535 x 19200 > 0 65535 x 4096 - 4.338916843220339 * - ? ?",u=1,v=1).Ditherpost(mode=6, slice=slices, u=Chr, v=Chr) \
:inputd.mt_lut( "x 16 < 255 x 75 > 0 255 x 16 - 255 75 16 - / * - ? ?",u=1,v=1), luma=chroma, u=Chr2, v=Chr2) : \
avs26 && planar && lsb ? Dither_merge16_8( inputd.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).ConvertToYV16(), lsb_in?inputP:inputd.ConvertToYV16().Dither_convert_8_to_16(), \
lsb_in?inputP.Dither_lut16("x 4096 < 65535 x 19200 > 0 65535 x 4096 - 4.338916843220339 * - ? ?",u=1,v=1).Ditherpost(mode=6, slice=slices, u=Chr, v=Chr) \
:inputd.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(!chroma) : \
avs26 && planar ? mt_merge ( Dfttest(!lsb_in?inputd: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(!chroma).ConvertToYV16():input8y.ConvertToYV16(), \
input8.Planar2Interleaved(!chroma).ConvertToYV16().mt_lut( "x 16 < 255 x 75 > 0 255 x 16 - 4.322033898305085 * - ? ?",u=1,v=1), luma=planar?false:chroma, u=bug_wa,v=bug_wa).ConvertToYUY2().Interleaved2planar(!chroma) : \
avs26 ? mt_merge (Dfttest(inputd,sstring="0.0:4.0 0.2:9.0 1.0:15.0",tbsize=1,u=chroma,v=chroma,dither=1),input8, \
input8.mt_lut("x 16 scalef < range_max x 75 scalef > 0 range_max x 16 scalef - range_max 75 scalef 16 scalef - / * - ? ?",use_expr=2,u=1,v=1), luma=chroma, cplace=cplace, u=chr,v=chr) : \
mt_merge (planar ? Dfttest(!lsb_in?inputd:input8y,sstring="0.0:4.0 0.2:9.0 1.0:15.0",tbsize=1,u=chroma,v=chroma,dither=1).Interleaved2planar(!chroma) : \
Dfttest(!lsb_in?inputd:input8 ,sstring="0.0:4.0 0.2:9.0 1.0:15.0",tbsize=1,u=chroma,v=chroma,dither=1),input8, \
input8.mt_lut( "x 16 < 255 x 75 > 0 255 x 16 - 4.322033898305085 * - ? ?",u=1,v=1), luma=chroma, u=bug_wa,v=bug_wa)) : \
(prefilter==4) ? planar ? inputd.SMDegrain_KNLMeansCL(lsb=lsb, lsb_in=lsb_in, device_type=device_type, device_id=device_id, chroma=chroma, h=h, d=d, a=a, knlm_params=knlm_params).Interleaved2planar(!chroma) : \
inputd.SMDegrain_KNLMeansCL(lsb=lsb, lsb_in=lsb_in, device_type=device_type, device_id=device_id, chroma=chroma, h=h, d=d, a=a, knlm_params=knlm_params) : \
Assert(false, "prefilter must be between -1~4: "+string(prefilter))
}
Code: Select all
# SMDegrain_KNLMeansCL
function SMDegrain_KNLMeansCL (clip input, String "device_type", int "device_id", bool "chroma", bool "lsb", bool "lsb_in", float "h", int "d", int "a", String "knlm_params")
{
d = Default( d ,0)
a = Default( a ,1)
h = Default( h ,7.0)
deviceid = Default( device_id ,0)
knlm_params = default(knlm_params, "")
chroma = Default( chroma ,true)
lsb_in = Default( lsb_in ,false)
lsb = Default( lsb ,lsb_in)
sisphbd = AvsPlusVersionNumber > 2294
fullchr = sisphbd ? input.is444() : input.isyv24()
chr420 = sisphbd ? input.is420() : input.isyv12()
nochr = sisphbd ? input.isy() : input.isy8()
chrlsb = chroma && !fullchr && !nochr
NL_in = lsb && !lsb_in ? input.Dither_convert_8_to_16() : input
cnl = chrlsb ? "Y" : input.isrgb() ? "auto" : chroma ? "YUV" : "Y"
NL_in = !chrlsb && input.isyuy2() ? NL_in.converttoyv16() : NL_in
chrlsb ? eval("""
# In a more lucid state I could probably have laid out this block much better... or not...
NL_W = width(NL_in)
Uclip = sisphbd ? ExtractU(NL_in) : UToY8(NL_in)
Vclip = sisphbd ? ExtractV(NL_in) : VToY8(NL_in)
NL_lsb = (chr420 ? StackVertical( lsb ? StackVertical(Dither_get_msb(uclip),Dither_get_msb(vclip)) : uclip,\
lsb ? StackVertical(Dither_get_lsb(uclip),Dither_get_lsb(vclip)) : vclip) : \
StackHorizontal(uclip,vclip))
nlc = StackHorizontal(sisphbd ? ConvertToY(NL_in) : ConvertToY8(NL_in),NL_lsb)
nlc = Eval("nlc.KNLMeansCL(D=d, A=a, h=h,stacked=lsb_in || lsb,device_type=device_type,device_id=deviceid,channels=cnl" + knlm_params + ")")
uvh = lsb_in || lsb ? uclip.height()/2 : uclip.height()
uvw = uclip.width()
nly = nlc.crop(0,0,chr420 ? -uvw : -(uvw+uvw),0)
nlu = chr420 ? lsb_in || lsb ? StackVertical(Dither_get_msb(nlc).crop(NL_W,0,0,-uvh),Dither_get_lsb(nlc).crop(NL_W,0,0,-uvh)) : nlc.crop(NL_W,0,0,-uvh) : \
nlc.crop(NL_W ,0,-uvw,0)
nlv = chr420 ? lsb_in || lsb ? StackVertical(Dither_get_msb(nlc).crop(NL_W,uvh, 0,0),Dither_get_lsb(nlc).crop(NL_W,uvh, 0,0)) : nlc.crop(NL_W,uvh, 0,0) : \
nlc.crop(NL_W+uvw,0, 0,0)
YToUV(nlu, nlv, nly)
""") : Eval("NL_in.KNLMeansCL(D=d, A=a, h=h,stacked=lsb_in || lsb,device_type=device_type,device_id=deviceid,channels=cnl" + knlm_params + ")")
!lsb && lsb_in ? Ditherpost(mode=6,slice=false) : last
input.isyuy2() ? converttoyuy2() : last
}
![Neutral :|](./images/smilies/icon_neutral.gif)