Advertisement
Guest User

maa2+ mod

a guest
Mar 11th, 2015
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. MAA2+ v0.42 mod
  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+
  16.    * SangNom2 0.3+
  17.    * Masktools 2.0b1
  18.  
  19. Parameters:
  20.  
  21.    + [int] mask (1)
  22.        *   0: Disable masking
  23.        *   1: Enable masking
  24.        *  -i: Enable masking with custom treshold
  25.    + [bool] chroma (false)
  26.        *   false: Don't process chroma channels (copy UV from the source clip if present)
  27.        *   true: Process chroma channels
  28.    + [float] ss (2.0)
  29.        *   Supersampling factor (sensible values are between 2.0 and 4.0 for HD content)
  30.    + [int] aa (48)
  31.        *   Sangnom2 luma antialiasing strength
  32.    + [int] aac (aa-8)
  33.        *   Sangnom2 chroma antialiasing strength
  34.    + [int] threads (4)
  35.        *   Number of threads used by every Sangnom2 instance
  36.    + [int] show (0)
  37.        *   0: Don't overlay mask
  38.        *   1: Overlay mask only
  39.        *   2: Overlay mask and run antialiasing on the luma plane
  40.    + [int] maskt (1)
  41.        *   1: sobel
  42.        *   2: min/max
  43.  
  44. */
  45.  
  46. function maa2(clip c, int "mask", bool "chroma", float "ss", int "aa", int "aac", int "threads", int "show", int "maskt")
  47. {
  48.     chroma = Default(chroma, false)
  49.     mask   = Default(mask, 1)
  50.     maskt   = Default(maskt, 1)
  51.     mtresh = (mask < 0) ? -mask : 7
  52.     show   = Default(show, 0)
  53.     uv     = (chroma) ? 3 : 1
  54.  
  55.     Assert(c.IsY8 || c.IsYV12 || c.IsYV24 || c.IsYV16, "MAA2: Input must be Y8, YV12, YV16 or YV24")
  56.     Assert(0 <= show <= 2, "MAA2: Parameter 'show' must be between 0 and 2")
  57.  
  58.     # create mask
  59.     if (mask != 0) {
  60.         m = (maskt != 1) ? c.mt_edge("min/max", 0, mtresh, 0, mtresh-6, u=uv, v=uv).mt_inflate(u=uv, v=uv) : c.mt_edge("sobel", mtresh, mtresh, mtresh-6, mtresh-6, u=uv, v=uv).mt_inflate(u=uv, v=uv)
  61.     }
  62.  
  63.     # run sangnom2-based aa
  64.     if (!chroma || show > 0) {
  65.         c_aa = c.ConvertToY8().Sangnom2AA(ss, aa, threads=threads)
  66.     }
  67.     else if (c.IsYV16) {
  68.         c_aa_u = c.UtoY8().Sangnom2AA(ss, aac, threads=threads)
  69.         c_aa_v = c.VtoY8().Sangnom2AA(ss, aac, threads=threads)
  70.         c_aa = YToUV(c_aa_u, c_aa_v, c.ConvertToY8().Sangnom2AA(ss, aa, threads=threads))
  71.     }
  72.     else { c_aa = c.Sangnom2AA(ss, aa, aac, threads) }
  73.  
  74.     # prepare chroma planes for mask overlay
  75.     if (show == 1) {
  76.         c_aa = (c.IsY8) ? c.ConvertToYV12().mt_lut(y=2, u=0, v=0)
  77.                       \ : c.mt_lut("x 2 /", y=2, u=3, v=3)
  78.     }
  79.     else if (show == 2) {
  80.         c_aa = (c.IsY8) ? c_aa.ConvertToYV12().mt_lut(y=2, u=0, v=0)
  81.                       \ : YtoUV(c.UtoY8(), c.VtoY8(), c_aa).mt_lut("x 2 /", y=2, u=3, v=3)
  82.     }
  83.  
  84.     # merge aa'ed lines into source
  85.     if (mask == 0) {
  86.         return mt_logic(c_aa, "and", y=4, u=2, v=2)
  87.     }
  88.     else if (show > 0) {
  89.         if (c.IsYV16) {
  90.             m_uv = BilinearResize(m, m.width/2, m.height)
  91.             return mt_merge(c, c_aa, YtoUV(m_uv, m_uv, m), u=3, v=3)
  92.         }
  93.         else {
  94.             return (c.IsYV24) ? mt_merge(c, c_aa, m.YtoUV(m,m), u=3, v=3)
  95.                             \ : mt_merge(c.ConvertToYV12(), c_aa, m, u=3, v=3, luma=true)
  96.         }
  97.     }
  98.     else {
  99.         return (chroma) ? mt_merge(c, c_aa, m, u=3, v=3)
  100.                       \ : mt_merge(c, c_aa, m, u=2, v=2)
  101.     }
  102. }
  103.  
  104. function Sangnom2AA(clip c, float "ss", int "aa", int "aac", int "threads")
  105. {
  106.     threads = Default(threads, 4)
  107.     aa = Default(aa, 48)
  108.     aac = Default(aac, aa-8)
  109.     aac = (aac < 0) ? 0 : aac
  110.     ss = Default(ss, 2.0)
  111.     ss_w = int(round(c.width*ss/4.0)*4)
  112.     ss_h = int(round(c.height*ss/4.0)*4)
  113.  
  114.     Assert(ss > 0, "MAA2: Supersampling factor must be > 0")
  115.  
  116.     return c.Spline36Resize(ss_w, ss_h).TurnLeft() \
  117.             .SangNom2(threads=threads, aa=aa, aac=aac).TurnRight().SangNom2(threads=threads, aa=aa, aac=aac).Spline36Resize(c.width, c.height)
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement