Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MCLS_16_plus(clip c, float "strength", clip "sharp", int "thsad", int "plane",\
- float "ss", bool "repair", bool "secure", int "dmode", int "edgemode", clip "mask", bool "blur_gaussian")
- {
- #Motion Compensate Limited Sharpen for a 16bit stacked clip by Motenai Yoda
- #first relase - beta 12
- #it works (or should) with 16bit avs+ only input (but mask is still 8bit only, I have to read how pinterf's autoscale works)
- #dependencies avs+, modded masktools2, rgtools, mvtools, dither_package, resamplemt
- strength = Default(strength, 1.0)
- thsad = Default(thsad, 400)
- plane = Default(plane, 0)
- ss = Default(ss, Defined(sharp) ? 1.0 : 1.25)
- repair = Default(repair, (Defined(sharp)) ? false : true)
- dmode = Default(dmode, 1)
- edgemode = Default(edgemode, 1)
- blur_gaussian = Default(blur_gaussian, false)
- secure = Default(secure, false)
- stacked = Default(stacked, true)
- str_lo = (strength < 1) ? " "+String(strength)+" *" : ""
- str_hi = (strength > 1) ? " "+String(strength)+" *" : ""
- HD = (c.width > 1280) ? 2 : (c.width > 720) ? 1 : 0
- Pel = Select(HD, 2, 1, 1)
- Truemotion = Select(HD, True, False, False)
- Blksize = Select(HD, 8, 16, 32)
- Overlap = Select(HD, 4, 8, 8)
- Yp = (plane == 0 || plane == 4) ? 3 : 1
- Up = (plane == 1 || plane == 3 || plane == 4) ? 3 : 1
- Vp = (plane == 2 || plane == 3 || plane == 4) ? 3 : 1
- Chromap = (plane == 0) ? false : true
- masked = (edgemode != 0) || Defined(mask)
- width2 = Round(c.width*ss)
- height2 = Round(c.height*ss)
- wpad = 16-(width2%16)
- hpad = 16-(height2%16)
- bRadius = Round(Select(HD, 3, 3, 4) / 1.25 * ss)
- resized_source = (ss != 1.0) ? c.Spline36resizemt(width2+wpad, height2+hpad) : c
- resized_sharp = Defined(sharp) ? (ss != 1.0) ? sharp.Spline36resizemt(width2+wpad, height2+hpad) : sharp : nop()
- pre = resized_source.removegrain(3, (Up == 3) ? 3 : -1, (Vp == 3) ? 3 : -1)
- blur = blur_gaussian ? Dither_box_filter16(resized_source.converttostacked(),\
- radius=max(bRadius-2, 1), y=Yp, u=Up, v=Vp).Dither_box_filter16(radius=max(bRadius-1,1), y=Yp, u=Up, v=Vp).\
- Dither_box_filter16(radius=max(bRadius-1,1), y=Yp, u=Up, v=Vp) : Dither_box_filter16(resized_source.converttostacked(),\
- radius=bRadius, y=Yp, u=Up, v=Vp)
- sharp0 = Defined(sharp) ? mt_makediff(resized_sharp, resized_source, y=Yp, u=Up,\
- v=Vp) : mt_makediff(resized_source, blur.convertfromstacked(bits=16), y=Yp, u=Up, v=Vp)
- source0 = pre.ConvertBits(8)
- mask = Defined(mask) ? mask :\
- (abs(edgemode) == 1) ? source0.mt_edge("min/max", y=3, u=1, v=1).mt_deflate(y=3, u=1, v=1).\
- removegrain(12, -1, -1) :\
- (abs(edgemode) == 2) ? source0.mt_edge("min/max",6,255,y=3,u=1,v=1).mt_lut("x 255 / 1 1.5 / ^ 1024 *",u=1,v=1).\
- removegrain(2,-1,-1).mt_expand(u=1,v=1).mt_deflate(u=1,v=1) : nop()
- mask = (edgemode < 0) ? mask.mt_invert(y=3,u=1,v=1) : mask
- mask = (masked) ? mask.convertbits(16) : nop()
- sup0 = pre.MSuper(pel=Pel, sharp=2, chroma=Chromap)
- sup1 = sharp0.MSuper(pel=Pel, sharp=2, chroma=Chromap)
- bv1 = sup0.MAnalyse(isb=true, delta=1, chroma=Chromap, blksize=Blksize, truemotion=Truemotion, overlap=Overlap)
- fv1 = sup0.MAnalyse(isb=false, delta=1, chroma=Chromap, blksize=Blksize, truemotion=Truemotion, overlap=Overlap)
- diff = sharp0.MDegrain1(sup1, bv1, fv1, plane=plane, thsad=thsad)
- secured = secure ? diff.mt_lut("x 32768 - abs 512 < x x 32768 < 32256 33280 ? ?", y=Yp, u=Up, v=Vp):\
- diff
- sharped_back = mt_adddiff(resized_source, secured, y=Yp, u=Up, v=Vp)
- repaired = (repair) ? repair(sharped_back, resized_source, (Yp == 3) ? 1 : -1 ,\
- (Up == 3) ? 1 : -1, (Vp == 3) ? 1 : -1).merge(sharped_back,0.33) : sharped_back
- bias = (dmode == 1) ? resized_source.mt_lut("x 4096. - 56064. / 0 1 clip pi * sin 0.5 ^ 65536. *"+\
- str_lo, y=3, u=1, v=1) : nop()
- bias = (masked) ? (dmode == 1) ? bias.mt_lutxy(mask, "x y * 8 >>u", y=3, u=1, v=1) : mask : bias
- repaired = (dmode == 1 || masked) ?\
- mt_merge(resized_source, repaired, bias, y=Yp, u=Up, v=Vp, luma=true) : repaired
- stronged = (strength > 1) ? repaired.mt_makediff(resized_source, y=Yp, u=Up, v=Vp).\
- mt_lut("x 32768 -"+str_hi+" 32768 +", y=Yp, u=Up, v=Vp).\
- mt_adddiff(resized_source, y=Yp, u=Up, v=Vp) : repaired
- resized_back = (ss != 1.0) ? spline36resizemt(stronged, c.width(), c.height()) : stronged
- return ytouv((Up == 3) ? resized_back.utoy() : c.utoy(), (Vp == 3) ? resized_back.vtoy() : c.vtoy(),\
- (Yp == 3) ? resized_back : c)
- }
Add Comment
Please, Sign In to add comment