SHOW:
|
|
- or go back to the newest paste.
| 1 | /* | |
| 2 | - | MAA2 v0.425 mod |
| 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 |
| 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 | - | function maa2(clip c, int "mask", bool "chroma", float "ss", int "aa", int "aac", int "threads", int "show", int "maskt", val "ext_aa") |
| 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 | - | Assert(c.IsY8 || c.IsYV12 || c.IsYV24 || c.IsYV16, "MAA2: Input must be Y8, YV12, YV16 or YV24") |
| 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 | - | """) : 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 | - | c_aa = c.ConvertToY8().Sangnom2AA(ss, aa, threads=defined(threads) ? threads : undefined) |
| 70 | + | |
| 71 | # run sangnom2-based aa | |
| 72 | - | (c.IsYV16) ? Eval("""
|
| 72 | + | |
| 73 | - | c_aa_u = c.UtoY8().Sangnom2AA(ss, aac, threads) |
| 73 | + | |
| 74 | - | c_aa_v = c.VtoY8().Sangnom2AA(ss, aac, threads) |
| 74 | + | c_aa = c.ConvertToY8().Sangnom2AA(ss, aa, threads, ss_h) |
| 75 | - | c_aa = YToUV(c_aa_u, c_aa_v, c.ConvertToY8().Sangnom2AA(ss, aa, threads)) |
| 75 | + | |
| 76 | !sislumaonly || !sisfullchro ? Eval("""
| |
| 77 | - | c_aa = c.Sangnom2AA(ss, aa, aac, threads) |
| 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 | - | c_aa = (c.IsY8) ? c.ConvertToYV12().mt_lut(y=2, u=0, v=0) |
| 83 | + | |
| 84 | - | \ : c.mt_lut("x 2 /", y=2, u=3, v=3)
|
| 84 | + | |
| 85 | (mask != 0) ? Eval("m = m.mt_inflate(u=uv, v=uv)") : nop()
| |
| 86 | (show == 1) ? Eval("""
| |
| 87 | - | c_aa = (c.IsY8) ? c_aa.ConvertToYV12().mt_lut(y=2, u=0, v=0) |
| 87 | + | c_aa = sislumaonly ? c.invert() |
| 88 | - | \ : YtoUV(c.UtoY8(), c.VtoY8(), c_aa).mt_lut("x 2 /", y=2, u=3, v=3)
|
| 88 | + | \ : c.mt_lut("x 2 /", y=2, u=3, v=3)
|
| 89 | - | """) : nop() |
| 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 | - | return mt_logic(c_aa, "and", y=4, u=2, v=2) |
| 93 | + | """) : nop() |
| 94 | ||
| 95 | - | (show > 0) ? Eval("""
|
| 95 | + | |
| 96 | - | (c.IsYV16) ? Eval("
|
| 96 | + | |
| 97 | - | m_uv = BilinearResize(m, m.width/2, m.height) |
| 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 mt_merge(c, c_aa, YtoUV(m_uv, m_uv, m), u=3, v=3) |
| 98 | + | return lastaa |
| 99 | - | ") : Eval("
|
| 99 | + | """) : \ |
| 100 | - | |
| 100 | + | (show > 0) ? mt_merge(c, c_aa, m, luma=!sislumaonly) : Eval("""
|
| 101 | - | return (c.IsYV24) ? mt_merge(c, c_aa, m.YtoUV(m,m), u=3, v=3) |
| 101 | + | |
| 102 | - | \ : mt_merge(c.ConvertToYV12(), c_aa, m, u=3, v=3, luma=true) |
| 102 | + | |
| 103 | - | ") |
| 103 | + | """) |
| 104 | } | |
| 105 | - | |
| 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 | - | function Sangnom2AA(clip c, float "ss", int "aa", int "aac", int "threads") |
| 111 | + | |
| 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_w = int(round(c.width*ss/4.0)*4) |
| 118 | + | ss_h = hasss_h ? ss_h : ss |
| 119 | - | ss_h = int(round(c.height*ss/4.0)*4) |
| 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 | - | try { fTurnLeft() } catch(error_msg) { TurnLeft() }
|
| 124 | + | |
| 125 | - | threads!=1 ? Eval("try { Spline36Resizemt(ss_h, ss_w, threads=threads) } catch(error_msg) { Spline36Resize(ss_h, ss_w) }") : Spline36Resize(ss_h, ss_w)
|
| 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 | - | try { fTurnRight() } catch(error_msg) { TurnRight() }
|
| 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 | - | threads!=1 ? Eval("try { Spline36Resizemt(c.width, c.height, threads=threads) } catch(error_msg) { Spline36Resize(c.width, c.height) }") : Spline36Resize(c.width, c.height)
|
| 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 | - | 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")""")} |
| 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 | } |