forked from vdcrim/AvsP-macros
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GraMaMa mask.py
109 lines (83 loc) · 3.25 KB
/
GraMaMa mask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
"""
Overlay a clip on top of another using a mask with a prescribed shape
Requirements:
- GraMaMa AviSynth filter <http://www.wilbertdijkhof.com/>
Instructions:
This macro uses the last assigned variable as the overlay clip and 'last'
as the overlayed. Example:
ColorBars(pixel_type="yv12")
alt=Invert()
becomes:
ColorBars(pixel_type="yv12")
alt=Invert()
Overlay(alt, mask=GraMaMa(mode=1, a=200, b=200, rad=100, rad2=100, binarize=False).Invert(), mode="blend")
where (a, b) is the center of the mask, selected by clicking on the video
preview.
Date: 2012-09-11
Latest version: https://github.com/vdcrim/avsp-macros
Changelog:
- fix Python 2.6 compatibility
Copyright (C) 2012 Diego Fernández Gosende <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
"""
# PREFERENCES
# GraMaMa parameters (actually called 'mode', 'rad', 'rad2' and 'binarize')
shape = 'Circle'
horizontal_radius = 100
vertical_radius = 100
binarize = False
# The macro uses the last assigned variable as the "overlay" clip. If there
# isn't any assign in the script it uses the following variable name:
clip = 'b'
# Refresh the video preview at the end
refresh_preview = True
# ------------------------------------------------------------------------------
import re
shape_list = [_('Circle'), _('Square'), _('Diamond'), _('Line'), _('Ellipse'),
_('Rectangle')]
options = avsp.GetTextEntry(title=_('GraMaMa mask'),
message=[[_('Shape'), _('Horizontal radius'), _('Vertical radius'), _('Binarize')],
_('Select the center of the mask after pressing OK')],
default=[[shape_list + [shape], horizontal_radius, vertical_radius, binarize], 0],
types=[['list_read_only', 'spin', 'spin', 'check'], 'sep'],
width=0)
if not options:
return
for i, shape in enumerate(shape_list):
if options[0] == shape:
mode = i + 1
break
rad = options[1]
rad2 = options[2]
binarize = options[3]
avs_text = avsp.GetText()
re_assign = re.compile(r'\s*(\w+)\s*=')
for line in reversed(avs_text.splitlines()):
if re_assign.match(line):
clip = re_assign.match(line).group(1)
break
if avs_text.endswith('\n'):
avsp.InsertText('last')
else:
avsp.InsertText('\nlast')
xy = avsp.GetPixelInfo()
avs = avsp.GetWindow().currentScript
avs.SetSelection(avs.PositionFromLine(avs.GetLineCount() - 1), -1)
avs.Clear()
if xy:
avsp.InsertText(u'Overlay({0}, mask=GraMaMa(mode={1}, a={2}, b={3}, '
'rad={4}, rad2={5}, binarize={6}).Invert(), mode="blend")'
'\n'.format(clip, mode, xy[0][0], xy[0][1], rad, rad2,
binarize))
if refresh_preview:
avsp.UpdateVideo()