Advertisement
Guest User

maa2 mod

a guest
Feb 11th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. MAA2 v0.426 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.  
  59. ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
  60. sislumaonly = ssispmt ? c.isy() : c.isy8()
  61. sisfullchro = ssispmt ? c.is444() : c.isyv24()
  62.  
  63.     Assert(0 <= show <= 2, "MAA2: Parameter 'show' must be between 0 and 2")
  64.     defined(ext_aa) ? Assert((Isclip(ext_aa) || IsString(ext_aa)),        "'ext_aa' only accepts clip or string") : nop()
  65.  
  66.     # create mask
  67.     (mask != 0) ? Eval("""
  68.        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)
  69.                      """) : nop()
  70.  
  71.     # run sangnom2-based aa
  72.     extclip = defined(ext_aa) ? isclip(ext_aa) ? ext_aa : eval("c." + ext_aa) : nop()
  73.     defined(ext_aa) ? Eval("c_aa=extclip") : (!chroma || show > 0) ? Eval("""
  74.        c_aa = c.ConvertToY8().Sangnom2AA(ss, aa, threads, ss_h)
  75.    """) : \
  76.     !sislumaonly || !sisfullchro ? Eval("""
  77.        c_aa_u = ssispmt ? c.ExtractU().Sangnom2AA(ss, aac, threads, ss_h) : c.UtoY8().Sangnom2AA(ss, aac, threads, ss_h)
  78.        c_aa_v = ssispmt ? c.ExtractV().Sangnom2AA(ss, aac, threads, ss_h) : c.VtoY8().Sangnom2AA(ss, aac, threads, ss_h)
  79.        c_aa = YToUV(c_aa_u, c_aa_v, c.Sangnom2AA(ss, aa, threads, ss_h))
  80.    """) : Eval("""
  81.    c_aa = c.Sangnom2AA(ss, aa, threads, ss_h, aac)
  82.    """)
  83.  
  84.     # prepare chroma planes for mask overlay
  85.     (mask != 0) ? Eval("m = m.mt_inflate(u=uv, v=uv)") : nop()
  86.     (show == 1) ? Eval("""
  87.        c_aa = sislumaonly ? c.invert()
  88.                         \ : c.mt_lut("x 2 /", y=2, u=3, v=3)
  89.                       """) : \
  90.     (show == 2) ? Eval("""
  91.        c_aa = sislumaonly ? c_aa.invert()
  92.                         \ : YtoUV(ssispmt ? c.ExtractU() : c.UtoY8(), ssispmt ? c.ExtractV() : c.VtoY8(), c_aa).mt_lut("x 2 /", y=2, u=3, v=3)
  93.                       """) : nop()
  94.  
  95.     # merge aa'ed lines into source
  96.     (mask == 0) ? Eval("""
  97.        lastaa = maskt == 0 ? sislumaonly ? c_aa : YtoUV(ssispmt ? c.ExtractU() : c.UtoY8(), ssispmt ? c.ExtractV() : c.VtoY8(), c_aa) : c.mt_logic(c_aa, "and", y=4, u=2, v=2)
  98.        return lastaa
  99.                       """) : \
  100.     (show > 0) ? mt_merge(c, c_aa, m, luma=!sislumaonly) : Eval("""
  101.        return (chroma) ? mt_merge(c, c_aa, m, u=3, v=3)
  102.                      \ : mt_merge(c, c_aa, m, u=2, v=2)
  103.                                                                  """)
  104. }
  105.  
  106. function Sangnom2AA(clip c, float "ss", int "aa", int "threads", float "ss_h", int "aac")
  107. {
  108.     threads = Default(threads, 4)
  109.     aa = Default(aa, 48)
  110.     aac = Default(aac, aa-8)
  111.     aac = (aac < 0) ? 0 : aac
  112.     ss = Default(ss, 2.0)
  113.      w = c.width()
  114.      h = c.height()
  115.     aa_w = round(w*ss)
  116.     hasss_h = defined(ss_h)
  117.     hasss_h ? Assert(ss_h > 0, "MAA2: ss_h factor must be > 0") : nop()
  118.     ss_h = hasss_h ? ss_h : ss
  119.     aa_h = round(h*ss_h)
  120.  
  121.     Assert(ss > 0, "MAA2: Supersampling factor must be > 0")
  122.     Assert(!(aa_w==w && aa_h==h), "MAA2: why do you use this filter then?!")
  123.     c
  124.     return Eval("""
  125.    aa_h==h && aa_w!=w ? eval("try { fTurnLeft() } catch(error_msg) { TurnLeft() }") : last
  126.    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
  127.    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
  128.            SangNom2(threads=threads, aa=aa, aac=aac)
  129.    aa_h!=h && aa_w!=w ? eval("try { fTurnLeft() } catch(error_msg) { TurnLeft() }") : last
  130.    aa_w==w ? last : aa_h!=h ? SangNom2(threads=threads, aa=aa, aac=aac) : last
  131.    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
  132.    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
  133.    aa_w!=w ? eval("try { fTurnRight() } catch(error_msg) { TurnRight() }") : last
  134.    """)
  135. }
  136.  
  137. 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")""")
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement