SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | - | MAA2 v0.41 mod |
2 | + | MAA2+ v0.42 mod |
3 | ========= | |
4 | ||
5 | - | Updated version of the MAA antialising script from AnimeIVTC. |
5 | + | Updated version of the MAA antialising script from AnimeIVTC. |
6 | - | MAA2 uses tp7's SangNom2 and FTurn, which provide a nice speedup for SangNom-based antialiasing, |
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 and YV24 input. |
11 | + | MAA2 supports Y8, YV12, YV16 and YV24 input. |
12 | ||
13 | Requirements: | |
14 | ||
15 | - | * AviSynth 2.6a4 |
15 | + | * AviSynth+ |
16 | * SangNom2 0.3+ | |
17 | - | * FTurn |
17 | + | * Masktools 2.0b1 |
18 | - | * Masktools 2.0a48 |
18 | + | |
19 | - | |
19 | + | |
20 | ||
21 | + [int] mask (1) | |
22 | - | + [int] mask (-200) |
22 | + | |
23 | * 1: Enable masking | |
24 | - | * 1: Enable masking |
24 | + | * -i: Enable masking with custom treshold |
25 | - | * -i: Enable masking with custom treshold (sensible values are between 0 and 30) |
25 | + | |
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 | - | |
41 | + | * 1: sobel |
42 | * 2: min/max | |
43 | ||
44 | - | function maa2(clip c, int "mask", bool "chroma", float "ss", int "aa", int "aac", int "threads", int "show") |
44 | + | |
45 | ||
46 | function maa2(clip c, int "mask", bool "chroma", float "ss", int "aa", int "aac", int "threads", int "show", int "maskt") | |
47 | - | mask = Default(mask, -200) |
47 | + | |
48 | chroma = Default(chroma, false) | |
49 | - | show = Default(show, 0) |
49 | + | mask = Default(mask, 1) |
50 | - | uv = (chroma) ? 3 : 1 |
50 | + | maskt = Default(maskt, 1) |
51 | mtresh = (mask < 0) ? -mask : 7 | |
52 | - | Assert(c.IsY8 || c.IsYV12 || c.IsYV24, "MAA2: Input must be Y8, YV12 or YV24") |
52 | + | show = Default(show, 0) |
53 | uv = (chroma) ? 3 : 1 | |
54 | ||
55 | - | m = (mask != 0) ? c.mt_edge("min/max",0,mtresh,0,mtresh-6,u=uv,v=uv).mt_inflate(u=uv,v=uv) : nop() |
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 | - | c_aa = (chroma && show==0) ? c.Sangnom2AA(ss,aa,aac,threads) : c.ConvertToY8().Sangnom2AA(ss,aa,threads=threads) |
57 | + | |
58 | # create mask | |
59 | - | c_aa = (show==1) ? (c.IsY8) ? c_aa.ConvertToYV12().mt_lut(y=2, u=0,v=0) |
59 | + | if (mask != 0) { |
60 | - | \ : c.mt_lut("x 2 /", y=2, u=3,v=3) |
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 | - | \ : (show==2) ? (c.IsY8) ? c_aa.ConvertToYV12().mt_lut(y=2, u=0,v=0) |
61 | + | } |
62 | - | \ : YtoUV(c.UtoY8(), c.VtoY8(), c_aa).mt_lut("x 2 /", y=2, u=3,v=3) |
62 | + | |
63 | - | \ : c_aa |
63 | + | # run sangnom2-based aa |
64 | if (!chroma || show > 0) { | |
65 | - | return (mask !=0) ? (show > 0) ? (c.IsYV24) ? mt_merge(c,c_aa,m.YtoUV(m,m),u=3,v=3) |
65 | + | c_aa = c.ConvertToY8().Sangnom2AA(ss, aa, threads=threads) |
66 | - | \ : mt_merge(c.ConvertToYV12(),c_aa,m,u=3,v=3, luma=true) |
66 | + | } |
67 | - | \ : (chroma) ? mt_merge(c,c_aa,m,u=3,v=3) |
67 | + | else if (c.IsYV16) { |
68 | - | \ : mt_merge(c,c_aa,m,u=2,v=2) |
68 | + | c_aa_u = c.UtoY8().Sangnom2AA(ss, aac, threads=threads) |
69 | - | \ : c.mt_logic(c_aa,"and", y=4, u=2, v=2) |
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 | - | threads = Default(threads, 4) |
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 | - | aac = (aac<0) ? 0 : aac |
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 | - | return c.Spline36Resize(ss_w,ss_h).FTurnLeft() \ |
84 | + | # merge aa'ed lines into source |
85 | - | .SangNom2(threads=threads, aa=aa, aac=aac).FTurnRight().SangNom2(threads=threads, aa=aa, aac=aac).Spline36Resize(c.width,c.height) |
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 | } |