Advertisement
Guest User

maa2 mod

a guest
Jul 21st, 2019
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. MAA2 v0.433 mod by A.SONY
  3. =========
  4.  
  5. Updated version of the MAA antialising script from AnimeIVTC.
  6. MAA2 uses tp7's SangNom2, which provide a nice speedup for SangNom-based antialiasing,
  7. especially when only processing the luma plane.
  8. The defaults of MAA2 match up with MAA, so you'll get identical output (save for the more accurate border region processing of SangNom2)
  9. when using this script as a drop-in replacement.
  10.  
  11. MAA2 supports Y8, YV12, YV16 and YV24 input.
  12.  
  13. Requirements:
  14.  
  15.    * AviSynth 2.6
  16.    * SangNom2 0.3+ (or not with ext_aa)
  17.    * FTurn (not necessarily required but will improve speed in avs not avs+)
  18.    * Masktools 2 beta or better
  19.  
  20. Parameters:
  21.  
  22.    + [int] mask (1)
  23.        *   0: Disable masking
  24.        *   1: Enable masking
  25.        *  -i: Enable masking with custom treshold
  26.    + [bool] chroma (false)
  27.        *   false: Don't process chroma channels (copy UV from the source clip if present)
  28.        *   true: Process chroma channels
  29.    + [float] ss (2.0)
  30.        *   Supersampling factor (sensible values are between 2.0 and 4.0 for HD content)
  31.    + [int] aa (48)
  32.        *   Sangnom2 luma antialiasing strength
  33.    + [int] aac (aa-8)
  34.        *   Sangnom2 chroma antialiasing strength
  35.    + [int] threads (4)
  36.        *   Number of threads used by every Sangnom2 instance
  37.    + [int] show (0)
  38.        *   0: Don't overlay mask
  39.        *   1: Overlay mask only
  40.        *   2: Overlay mask and run antialiasing on the luma plane
  41.    + [int] maskt (1)
  42.        *   0: with mask=0 will not use any masktools function
  43.        *   1: sobel
  44.        *   2: min/max
  45.    + [val] ext_aa (undefined)
  46.        *   External aa clip or function to use it instead of Sangnom2, you can use nnedi3_resize16(Width*2, Height*2) then nnedi3_resize16(Width/2, Height/2) or ext_aa="""edi_rpow2(2,2, fwidth=width(c),fheight=Height(c), edi="eedi3", mclip=m,cshift="spline36resize")""" or something else according to your source
  47.  
  48. */
  49.  
  50. function maa2(clip c, int "mask", bool "chroma", float "ss", int "aa", int "aac", int "threads", int "show", int "maskt", val "ext_aa", float "ss_h")
  51. {
  52.     chroma = Default(chroma, false)
  53.     mask   = Default(mask, 1)
  54.     maskt  = Default(maskt, 1)
  55.     mtresh = (mask < 0) ? -mask : 7
  56.     show   = Default(show, 0)
  57.     uv     = (chroma) ? 3 : 1
  58.     aa     = Default(aa, 48)
  59.     aac    = Default(aac, aa-8)
  60.     aac    = (aac < 0) ? 0 : aac
  61.  
  62.     sisphbd = AvsPlusVersionNumber > 2294
  63.     sislumaonly = sisphbd  ? c.isy() : c.isy8()
  64.     sisfullchro = sisphbd  ? c.is444() : c.isyv24()
  65.  
  66.     Assert(0 <= show <= 2, "MAA2: Parameter 'show' must be between 0 and 2")
  67.     defined(ext_aa) ? Assert((Isclip(ext_aa) || IsString(ext_aa)), "'ext_aa' only accepts clip or string") : nop()
  68.  
  69.     # create mask
  70.     (mask != 0) ? Eval("""
  71.        m = (maskt != 1) ? c.mt_edge("min/max", 0, mtresh, 0, mtresh-6, u=uv, v=uv) : c.mt_edge("sobel", mtresh, mtresh, mtresh-6, mtresh-6, u=uv, v=uv)
  72.                      """) : nop()
  73.  
  74.     # run sangnom2-based aa
  75.     defined(ext_aa) ? isclip(ext_aa) ? eval("c_aa = ext_aa") : eval("c_aa = c." + ext_aa)
  76.     \               : show != 1 ? Eval("""
  77.        prfu  = sisfullchro && chroma
  78.        cp_Y  = !(sislumaonly || prfu) ? sisphbd  ? c.ConvertToY() : c.ConvertToY8() : c
  79.        cp_U  = !(sislumaonly || prfu || show > 0) ? sisphbd  ? c.ExtractU() : c.UtoY8() : nop()
  80.        cp_V  = !(sislumaonly || prfu || show > 0) ? sisphbd  ? c.ExtractV() : c.VtoY8() : nop()
  81.  
  82.        c_aa_Y = cp_Y.Sangnom2AA(ss, ss_h, threads, aa, aac)
  83.        c_aa_u = !(sislumaonly || prfu || show > 0) ? chroma ? cp_U.Sangnom2AA(ss, ss_h, threads, aac) : cp_U : nop()
  84.        c_aa_v = !(sislumaonly || prfu || show > 0) ? chroma ? cp_V.Sangnom2AA(ss, ss_h, threads, aac) : cp_V : nop()
  85.  
  86.        c_aa = sislumaonly || prfu || show > 0 ? c_aa_Y : sisphbd  ? CombinePlanes(c_aa_Y,c_aa_u,c_aa_v,planes="YUV",sample_clip=c) : YToUV(c_aa_u, c_aa_v, c_aa_Y)
  87.                                       """) : nop()
  88.  
  89.     # prepare chroma planes for mask overlay
  90.     (mask != 0) ? Eval("m = m.mt_inflate(u=uv, v=uv)") : nop()
  91.     (show == 1) ? Eval("""
  92.        c_aa = sislumaonly ? c.invert()
  93.                         \ : c.mt_lut("x 2 /", use_expr=2, y=2, u=3, v=3)
  94.                       """) : \
  95.     (show == 2) ? Eval("""
  96.        c_aa = sislumaonly ? c_aa.invert()
  97.                         \ : c_aa.mt_lut("x 2 /", use_expr=2, y=2, u=3, v=3)
  98.                       """) : nop()
  99.  
  100.     # merge aa'ed lines into source
  101.     (mask == 0) ? Eval("""
  102.        lastaa = maskt == 0 ? sislumaonly ? c_aa : c.mergeluma(c_aa) : c.mt_logic(c_aa, "and", y=4, u=2, v=2)
  103.        return lastaa
  104.                       """) : \
  105.     (show > 0) ? mt_merge(c, c_aa, m, luma=!sislumaonly) : Eval("""
  106.        return (chroma) ? mt_merge(c, c_aa, m, u=3, v=3)
  107.                      \ : mt_merge(c, c_aa, m, u=2, v=2)
  108.                                                                  """)
  109. }
  110.  
  111. function Sangnom2AA(clip c, float "ss", float "ss_h", int "threads", int "aa", int "aac")
  112. {
  113.     threads = Default(threads, 4)
  114.     aa = Default(aa, 48)
  115.     aac = Default(aac, aa-8)
  116.     aac = (aac < 0) ? 0 : aac
  117.     ss = Default(ss, 2.0)
  118.      w = c.width()
  119.      h = c.height()
  120.     aa_w = round(w*ss/2.0)*2
  121.     hasss_h = defined(ss_h)
  122.     hasss_h ? Assert(ss_h > 0, "MAA2: ss_h factor must be > 0") : nop()
  123.     ss_h = hasss_h ? ss_h : ss
  124.     aa_h = round(h*ss_h/2.0)*2
  125.  
  126.     Assert(ss > 0, "MAA2: Supersampling factor must be > 0")
  127.     Assert(!(aa_w==w && aa_h==h), "MAA2: why do you use this filter then?!")
  128.  
  129.     sisp   = IsAvsPlus
  130.  
  131.     c
  132.     Eval("""
  133.    aa_h==h && aa_w!=w ? eval("try { sisp ? dontdoft : fTurnLeft() } catch(error_msg) { TurnLeft() }") : last
  134.    aa_h==h ? threads!=1 ? Eval("try { Spline36Resizemt(aa_h, aa_w, threads=threads) } catch(error_msg) { Spline36Resize(aa_h, aa_w) }") : Spline36Resize(aa_h, aa_w) : last
  135.    aa_h!=h ? threads!=1 ? Eval("try { Spline36Resizemt(aa_w, aa_h, threads=threads) } catch(error_msg) { Spline36Resize(aa_w, aa_h) }") : Spline36Resize(aa_w, aa_h) : last
  136.            SangNom2(threads=threads, aa=aa, aac=aac)
  137.    aa_h!=h && aa_w!=w ? eval("try { sisp ? dontdoft : fTurnLeft() } catch(error_msg) { TurnLeft() }") : last
  138.    aa_w==w ? last : aa_h!=h ? SangNom2(threads=threads, aa=aa, aac=aac) : last
  139.    aa_h!=h && aa_w==w ? threads!=1 ? Eval("try { Spline36Resizemt(c.width, c.height, threads=threads) } catch(error_msg) { Spline36Resize(c.width, c.height) }") : Spline36Resize(c.width, c.height) : last
  140.    aa_w!=w ? threads!=1 ? Eval("try { Spline36Resizemt(c.height, c.width, threads=threads) } catch(error_msg) { Spline36Resize(c.height, c.width) }") : Spline36Resize(c.height, c.width) : last
  141.    aa_w!=w ? eval("try { sisp ? dontdoft : fTurnRight() } catch(error_msg) { TurnRight() }") : last
  142.    """)
  143. }
  144.  
  145. function maa2ee(clip c){c.maa2(mask=-7, maskt=2, chroma=true,ext_aa="""edi_rpow2(2,2, fwidth=width(c),fheight=Height(c), edi="eedi3", mclip=m,cshift="spline36resize",sclip="nnedi3",nnrep=true,bordfix=true)""")
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement