SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | - | MAA2 v0.422 mod |
2 | + | MAA2 v0.423 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 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 | |
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 | * 1: sobel | |
43 | * 2: min/max | |
44 | - | + [clip] ext_aa (undefined) |
44 | + | + [val] ext_aa (undefined) |
45 | - | * External aa clip to use it instead of Sangnom2, you can use nnedi3_resize16(Width*2, Height*2) then nnedi3_resize16(Width/2, Height/2) or something else according to your source |
45 | + | * 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 |
46 | ||
47 | */ | |
48 | ||
49 | - | function maa2(clip c, int "mask", bool "chroma", float "ss", int "aa", int "aac", int "threads", int "show", int "maskt", clip "ext_aa") |
49 | + | function maa2(clip c, int "mask", bool "chroma", float "ss", int "aa", int "aac", int "threads", int "show", int "maskt", val "ext_aa") |
50 | { | |
51 | chroma = Default(chroma, false) | |
52 | mask = Default(mask, 1) | |
53 | maskt = Default(maskt, 1) | |
54 | mtresh = (mask < 0) ? -mask : 7 | |
55 | show = Default(show, 0) | |
56 | uv = (chroma) ? 3 : 1 | |
57 | ||
58 | Assert(c.IsY8 || c.IsYV12 || c.IsYV24 || c.IsYV16, "MAA2: Input must be Y8, YV12, YV16 or YV24") | |
59 | Assert(0 <= show <= 2, "MAA2: Parameter 'show' must be between 0 and 2") | |
60 | defined(ext_aa) ? Assert((Isclip(ext_aa) || IsString(ext_aa)), "'ext_aa' only accepts clip or string") : nop() | |
61 | ||
62 | # create mask | |
63 | (mask != 0) ? Eval(""" | |
64 | 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) | |
65 | """) : nop() | |
66 | ||
67 | - | defined(ext_aa) ? Eval("c_aa=ext_aa") : (!chroma || show > 0) ? Eval(""" |
67 | + | |
68 | extclip = defined(ext_aa) ? isclip(ext_aa) ? ext_aa : eval("c." + ext_aa) : nop() | |
69 | defined(ext_aa) ? Eval("c_aa=extclip") : (!chroma || show > 0) ? Eval(""" | |
70 | c_aa = c.ConvertToY8().Sangnom2AA(ss, aa, threads=defined(threads) ? threads : undefined) | |
71 | """) : \ | |
72 | (c.IsYV16) ? Eval(""" | |
73 | c_aa_u = c.UtoY8().Sangnom2AA(ss, aac, threads) | |
74 | c_aa_v = c.VtoY8().Sangnom2AA(ss, aac, threads) | |
75 | c_aa = YToUV(c_aa_u, c_aa_v, c.ConvertToY8().Sangnom2AA(ss, aa, threads)) | |
76 | """) : Eval(""" | |
77 | c_aa = c.Sangnom2AA(ss, aa, aac, threads) | |
78 | """) | |
79 | ||
80 | # prepare chroma planes for mask overlay | |
81 | (show == 1) ? Eval(""" | |
82 | c_aa = (c.IsY8) ? c.ConvertToYV12().mt_lut(y=2, u=0, v=0) | |
83 | \ : c.mt_lut("x 2 /", y=2, u=3, v=3) | |
84 | """) : \ | |
85 | (show == 2) ? Eval(""" | |
86 | c_aa = (c.IsY8) ? c_aa.ConvertToYV12().mt_lut(y=2, u=0, v=0) | |
87 | \ : YtoUV(c.UtoY8(), c.VtoY8(), c_aa).mt_lut("x 2 /", y=2, u=3, v=3) | |
88 | """) : nop() | |
89 | ||
90 | # merge aa'ed lines into source | |
91 | (mask == 0) ? Eval(""" | |
92 | return mt_logic(c_aa, "and", y=4, u=2, v=2) | |
93 | """) : \ | |
94 | (show > 0) ? Eval(""" | |
95 | (c.IsYV16) ? Eval(" | |
96 | m_uv = BilinearResize(m, m.width/2, m.height) | |
97 | return mt_merge(c, c_aa, YtoUV(m_uv, m_uv, m), u=3, v=3) | |
98 | ") : Eval(" | |
99 | ||
100 | return (c.IsYV24) ? mt_merge(c, c_aa, m.YtoUV(m,m), u=3, v=3) | |
101 | \ : mt_merge(c.ConvertToYV12(), c_aa, m, u=3, v=3, luma=true) | |
102 | ") | |
103 | """) : Eval(""" | |
104 | ||
105 | return (chroma) ? mt_merge(c, c_aa, m, u=3, v=3) | |
106 | \ : mt_merge(c, c_aa, m, u=2, v=2) | |
107 | """) | |
108 | } | |
109 | ||
110 | function Sangnom2AA(clip c, float "ss", int "aa", int "aac", int "threads") | |
111 | { | |
112 | threads = Default(threads, 4) | |
113 | aa = Default(aa, 48) | |
114 | aac = Default(aac, aa-8) | |
115 | aac = (aac < 0) ? 0 : aac | |
116 | ss = Default(ss, 2.0) | |
117 | ss_w = int(round(c.width*ss/4.0)*4) | |
118 | ss_h = int(round(c.height*ss/4.0)*4) | |
119 | ||
120 | Assert(ss > 0, "MAA2: Supersampling factor must be > 0") | |
121 | c | |
122 | return Eval(""" | |
123 | try { fTurnLeft() } catch(error_msg) { TurnLeft() } | |
124 | Spline36Resize(ss_h, ss_w) | |
125 | SangNom2(threads=threads, aa=aa, aac=aac) | |
126 | try { fTurnRight() } catch(error_msg) { TurnRight() } | |
127 | SangNom2(threads=threads, aa=aa, aac=aac).Spline36Resize(c.width, c.height) | |
128 | """) | |
129 | } |