Advertisement
Guest User

MCLS_16 ver beta 0.8

a guest
Oct 15th, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unction MCLS_16(clip c, float "strength", clip "sharp", int "thsad", int "plane",\
  2.  float "ss", bool "repair", int "dmode", int "edgemode", clip "mask", bool "blur_gaussian")
  3. {
  4.  
  5.    #Motion Compensate Limited Sharpen for a 16bit stacked clip by Motenai Yoda
  6.    #beta 8
  7.    #it works (or should) with 16bit stacked clip input/output
  8.  
  9.    strength = Default(strength, 1.0)
  10.    thsad = Default(thsad, 400)
  11.    plane = Default(plane, 0)
  12.    ss = Default(ss, Defined(sharp) ? 1.0 : 1.25)
  13.    repair = Default(repair, Defined(sharp) ? false : true)
  14.    dmode = Default(dmode, 1)
  15.    edgemode = Default(edgemode, 1)
  16.    blur_gaussian = Default(blur_gaussian, false)
  17.  
  18.    
  19.    str = String(strength)
  20.    HD = (c.width > 1280) ? 2 : (c.width > 720) ? 1 : 0
  21.    Pel = Select(HD, 2, 1, 1)
  22.    Truemotion = Select(HD, True, False, False)
  23.    Blksize = Select(HD, 8, 16, 32)
  24.    Overlap = Select(HD, 4, 8, 8)
  25.      
  26.    Yp = (plane == 0 || plane == 4) ? 3 : 1
  27.    Up = (plane == 1 || plane == 3 || plane == 4) ? 3 : 1
  28.    Vp = (plane == 2 || plane == 3 || plane == 4) ? 3 : 1
  29.    
  30.    Chromap = (plane == 0) ? false : true
  31.    masked = (edgemode != 0) || Defined(mask)
  32.    
  33.    width2 = Round(c.width*ss)
  34.    height2 = Round(c.height*ss/2.0)
  35.  
  36.    wpad = 16-(width2%16)
  37.    hpad = 16-(height2%16)
  38.    
  39.    bRadius = Round(Select(HD, 3, 3, 4) / 1.25 * ss)
  40.    
  41.      
  42.    resized_source = (ss != 1.0) ? c.Dither_resize16(width2+wpad, height2+hpad, y=3, u=Up,\
  43.     v=Vp) : c
  44.    resized_sharp = Defined(sharp) ? (ss != 1.0) ? sharp.Dither_resize16(width2+wpad, height2+hpad,\
  45.     y=Yp, u=Up, v=Vp) : sharp : nop()
  46.    
  47.    pre = resized_source.Dither_removegrain16(3, (Up == 3) ? 3 : -1, (Vp == 3) ? 3 : -1)
  48.    
  49.    sharp0 = Defined(sharp) ? Dither_sub16(resized_sharp, resized_source, wrap=False,  y=Yp, u=Up,\
  50.     v=Vp, dif=true) : Dither_sub16(resized_source, blur_gaussian ? Dither_box_filter16(resized_source,\
  51.      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).\
  52.     Dither_box_filter16(radius=max(bRadius-1,1), y=Yp, u=Up, v=Vp) : Dither_box_filter16(resized_source,\
  53.       radius=bRadius, y=Yp, u=Up, v=Vp), wrap=False,  y=Yp, u=Up, v=Vp, dif=true)
  54.  
  55.    source0 = Ditherpost(pre, mode=-1, y=3, u=Up, v=Vp)
  56.    
  57.    mask = Defined(mask) ? mask :\
  58.    (edgemode == 1) ? source0.mt_edge("min/max", y=3, u=1, v=1).mt_deflate(y=3, u=1, v=1).\
  59.    mt_lut("x 2 / 128 +",y=3,u=1,v=1).removegrain(12, -1, -1) :\
  60.    (edgemode == 2) ? source0.mt_edge("min/max",6,255,y=3,u=1,v=1).mt_lut("x 255 / .5 ^ 1024 *",u=1,v=1).\
  61.    removegrain(2,-1,-1).mt_expand(u=1,v=1).mt_deflate(u=1,v=1) : nop()
  62.    mask = (masked) ? stackvertical(mask, mask) : nop()
  63.  
  64.    sup0 = source0.MSuper(pel=Pel, sharp=2, chroma=Chromap)
  65.    sharp0m = sharp0.Dither_get_msb()
  66.    sup1 = sharp0m.MSuper(pel=Pel, sharp=2, chroma=Chromap)
  67.    sharp0l = sharp0.Dither_get_lsb()
  68.    sup2 = sharp0l.MSuper(pel=Pel, sharp=2, chroma=Chromap)
  69.    
  70.    bv1 = sup0.MAnalyse(isb=true, delta=1, chroma=Chromap, blksize=Blksize, truemotion=Truemotion, overlap=Overlap)
  71.    fv1 = sup0.MAnalyse(isb=false, delta=1, chroma=Chromap, blksize=Blksize, truemotion=Truemotion, overlap=Overlap)
  72.    
  73.    nullclip = source0.mt_lut(y= (Yp==3) ? -0 : 1, u= (Up==3) ? -0 : 1, v= (Vp==3) ? -0 : 1)
  74.    
  75.    diff1 = sharp0m.MDegrain1(sup1, bv1, fv1, plane=plane, thsad=thsad, lsb=true)
  76.    diff2 = sharp0l.MDegrain1(sup2, bv1, fv1, plane=plane, thsad=thsad, lsb=false)
  77.    diff2_16 = stackvertical(nullclip, diff2)
  78.    
  79.    diff3 = Dither_add16(diff1, diff2_16, wrap=False,  y=Yp, u=Up, v=Vp, dif=false)
  80.    
  81.    sharped_back = Dither_add16(resized_source, diff3, wrap=False,  y=Yp, u=Up, v=Vp, dif=true)
  82.    
  83.    repaired = (repair) ? Dither_repair16(sharped_back, resized_source, (Yp == 3) ? 1 : -1 ,\
  84.     (Up == 3) ? 1 : -1, (Vp == 3) ? 1 : -1).Dither_merge16(sharped_back,sharped_back.mt_lut(y=-76,\
  85.      u=1,v=1),luma=true, y=Yp, u=Up, v=Vp): sharped_back
  86.    
  87.    bias = (dmode == 1) ? resized_source.Dither_lut16("x 4096. - 56064. / 0 1 clip pi * sin 0.5 ^ "+\
  88.    str+" * 65536. *", y=3, u=1, v=1) : nop()
  89.    bias = (masked) ? (dmode == 1) ? bias.mt_lutxy(mask, "x y * 8 >>u", y=3, u=1, v=1) : mask : bias
  90.    
  91.    repaired = (dmode == 1 || masked) ? Dither_merge16(resized_source, repaired, bias, y=Yp, u=Up, v=Vp, luma=true) :\
  92.    repaired
  93.    
  94.    resized_back =  (ss != 1.0) ? Dither_resize16(repaired, c.width(), c.height()/2, y=Yp, u=Up, v=Vp) : repaired
  95.    
  96.    return ytouv((Up == 3) ? resized_back.utoy() : c.utoy(), (Vp == 3) ? resized_back.vtoy() : c.vtoy(),\
  97.     (Yp == 3) ? resized_back : c)
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement