Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, clip):
super(MaskParent, self).__init__(clip)
if clip.format.color_family is not vs.GRAY:
self.clip = self.core.std.ShufflePlanes(self.clip, 0, vs.GRAY)
self.clip = mvf.Depth(self.clip, 8) # Mask will always be processed in 8bit scale
self.mask = None
self.multi = ((1 << self.clip_bits) - 1) // 255
ow = src.width
oh = src.height
bits = src.format.bits_per_sample
sample_type = src.format.sample_type
if sample_type == vs.INTEGER:
maxvalue = (1 << bits) - 1
thr = thr * maxvalue // 0xFF
else:
maxvalue = 1
thr /= (235 - 16)
# Fix lineart
src_y = core.std.ShufflePlanes(src, planes=0, colorfamily=vs.GRAY)
deb = Resize(src_y, w, h, kernel=kernel, a1=b, a2=c, taps=taps, invks=True)
sharp = nnp2.nnedi3_rpow2(deb, 2, ow, oh)
thrlow = 4 * maxvalue // 0xFF if sample_type == vs.INTEGER else 4 / 0xFF
thrhigh = 24 * maxvalue // 0xFF if sample_type == vs.INTEGER else 24 / 0xFF
edgemask = core.std.Prewitt(sharp, planes=0)
edgemask = core.std.Expr(edgemask, "x {thrhigh} >= {maxvalue} x {thrlow} <= 0 x ? ?"
.format(thrhigh=thrhigh, maxvalue=maxvalue, thrlow=thrlow))
if kernel == "bicubic" and c >= 0.7:
edgemask = core.std.Maximum(edgemask, planes=0)
sharp = core.resize.Point(sharp, format=src.format.id)
# Restore true 1080p
deb_upscale = Resize(deb, ow, oh, kernel=kernel, a1=b, a2=c, taps=taps)
diffmask = core.std.Expr([src_y, deb_upscale], 'x y - abs')
for _ in range(expand):
diffmask = core.std.Maximum(diffmask, planes=0)
def Tweak(clip, hue=None, sat=None, bright=None, cont=None, coring=True):
if clip.format is None:
raise vs.Error("Tweak: only clips with constant format are accepted.")
if clip.format.color_family == vs.RGB:
raise vs.Error("Tweak: RGB clips are not accepted.")
c = vs.get_core()
if (hue is not None or sat is not None) and clip.format.color_family != vs.GRAY:
hue = 0.0 if hue is None else hue
sat = 1.0 if sat is None else sat
hue = hue * math.pi / 180.0
hue_sin = math.sin(hue)
hue_cos = math.cos(hue)
gray = 128 << (clip.format.bits_per_sample - 8)
chroma_min = 0
chroma_max = (2 ** clip.format.bits_per_sample) - 1
if coring:
chroma_min = 16 << (clip.format.bits_per_sample - 8)
chroma_max = 240 << (clip.format.bits_per_sample - 8)
expr_u = "x {} - {} * y {} - {} * + {} + {} max {} min".format(gray, hue_cos * sat, gray, hue_sin * sat, gray, chroma_min, chroma_max)
strength = _clamp(0, strength, 100)
threshold = _clamp(0, threshold, 100)
if ss_x < 1.0:
ss_x = 1.0
if ss_y < 1.0:
ss_y = 1.0
if ss_x != 1.0 or ss_y != 1.0:
clip = core.resize.Lanczos(clip, width=_m4(ox*ss_x), height=_m4(oy*ss_y))
orig = clip
if orig.format.num_planes != 1:
clip = core.std.ShufflePlanes(clips=clip, planes=[0],
colorfamily=vs.GRAY)
val = clip
max_ = core.std.Maximum(clip)
min_ = core.std.Minimum(clip)
nmax = core.std.Expr([max_, min_], ['x y -'])
nval = core.std.Expr([val, min_], ['x y -'])
s = strength/100.0
t = threshold/100.0
x0 = t * (1.0 - s) / (1.0 - (1.0 - t) * (1.0 - s))
expr = ('{x} {y} / 2 * 1 - abs {x0} < {s} 1 = {x} {y} 2 / = 0 {y} 2 / ? '
'{x} {y} / 2 * 1 - abs 1 {s} - / ? {x} {y} / 2 * 1 - abs 1 {t} - '
'* {t} + ? {x} {y} 2 / > 1 -1 ? * 1 + {y} * 2 / {scl} *').format(
x=x, y=y, x0=x0, t=t, s=s, scl=scl)
else:
aaov = 4
if w > 1100 and aablk is None:
aablk = 16
else:
aablk = 8
_max = (1 << orig.format.bits_per_sample) - 1
_mid = (1 << orig.format.bits_per_sample) / 2
aatype = aatype.lower()
# Mask
m = core.std.ShufflePlanes(orig, planes=0, colorfamily=vs.GRAY)
m = core.std.Expr(core.std.Expr([core.std.Convolution(m, [5, 10, 5, 0, 0, 0, -5, -10, -5], divisor=4, saturate=False),
core.std.Convolution(m, [5, 0, -5, 10, 0, -10, 5, 0, -5], divisor=4, saturate=False)],
['x y max']),
['x {_mid} / 0.86 pow {_max} *'.format(_max=_max, _mid=_mid)])
# darkening and thining work different than in the original script because of effort
if dark != 0 or thin != 0:
preaa = haf.FastLineDarkenMOD(orig, strength=dark, thinning=thin)
else:
preaa = orig
# Antialiasing
if aatype == 'sangnom':
def __init__(self, clip):
self.core = vs.get_core()
self.clip = clip
if not isinstance(clip, vs.VideoNode):
raise TypeError(MODULE_NAME + ': clip is invalid.')
self.clip_width = clip.width
self.clip_height = clip.height
self.clip_bits = clip.format.bits_per_sample
self.clip_color_family = clip.format.color_family
self.clip_sample_type = clip.format.sample_type
self.clip_id = clip.format.id
self.clip_subsample_w = clip.format.subsampling_w
self.clip_subsample_h = clip.format.subsampling_h
self.clip_is_gray = True if clip.format.num_planes == 1 else False
# Register format for GRAY10
vs.GRAY10 = self.core.register_format(vs.GRAY, vs.INTEGER, 10, 0, 0).id
raise TypeError(funcName + ': \"clip\" must be a clip!')
# Get properties of input clip
sFormat = clip.format
sNumPlanes = sFormat.num_planes
# Parameters
if plane is None:
plane = 0
elif not isinstance(plane, int):
raise TypeError(funcName + ': \"plane\" must be an int!')
elif plane < 0 or plane > sNumPlanes:
raise ValueError(funcName + ': valid range of \"plane\" is [0, sNumPlanes)!'.format(sNumPlanes=sNumPlanes))
# Process
return core.std.ShufflePlanes(clip, plane, vs.GRAY)
################################################################################################################################
temp = core.fmtc.resample(temp, *original, kernel=kernel, taps=taps)
diff = core.std.MakeDiff(startclip, temp, 0)
mask = core.std.Lut(diff, function=luma16).rgvs.RemoveGrain(mode=[RGmode])
mask = core.std.Lut(mask, function=f16)
for i in range(expandN):
mask = core.generic.Maximum(mask, planes=[0])
for i in range(inflateN):
mask = core.generic.Inflate(mask, planes=[0])
mask = core.fmtc.resample(mask, *target, taps=taps)
if blur_more:
mask = core.rgvs.RemoveGrain(mask, mode=[12,0,0])
mask = core.std.ShufflePlanes(mask, planes=0, colorfamily=vs.GRAY)
return core.fmtc.bitdepth(mask, bits=depth, dmode=1)
src_st = src_f.sample_type
src_bits = src_f.bits_per_sample
src_sw = src_f.subsampling_w
src_sh = src_f.subsampling_h
descale_getnative_filter = get_descale_getnative_filter(b, c, taps, kernel)
if src_cf == vs.RGB and not gray:
rgb = descale_getnative_filter(to_rgbs(src), width, height)
return rgb.resize.Point(format=src_f.id)
y = descale_getnative_filter(to_grays(src), width, height)
y_f = core.register_format(vs.GRAY, src_st, src_bits, 0, 0)
y = y.resize.Point(format=y_f.id)
if src_cf == vs.GRAY or gray:
return y
if not yuv444 and ((width % 2 and src_sw) or (height % 2 and src_sh)):
raise ValueError('descale_getnative: The output dimension and the subsampling are incompatible.')
uv_f = core.register_format(src_cf, src_st, src_bits, 0 if yuv444 else src_sw, 0 if yuv444 else src_sh)
uv = src.resize.Spline36(width, height, format=uv_f.id, chromaloc_s=chromaloc)
return core.std.ShufflePlanes([y, uv], [0, 1, 2], vs.YUV)
chroma_min = 0
chroma_max = (2 ** clip.format.bits_per_sample) - 1
if coring:
chroma_min = 16 << (clip.format.bits_per_sample - 8)
chroma_max = 240 << (clip.format.bits_per_sample - 8)
expr_u = "x {} - {} * y {} - {} * + {} + {} max {} min".format(gray, hue_cos * sat, gray, hue_sin * sat, gray, chroma_min, chroma_max)
expr_v = "y {} - {} * x {} - {} * - {} + {} max {} min".format(gray, hue_cos * sat, gray, hue_sin * sat, gray, chroma_min, chroma_max)
if clip.format.sample_type == vs.FLOAT:
expr_u = "x {} * y {} * + -0.5 max 0.5 min".format(hue_cos * sat, hue_sin * sat)
expr_v = "y {} * x {} * - -0.5 max 0.5 min".format(hue_cos * sat, hue_sin * sat)
src_u = clip.std.ShufflePlanes(planes=1, colorfamily=vs.GRAY)
src_v = clip.std.ShufflePlanes(planes=2, colorfamily=vs.GRAY)
dst_u = c.std.Expr(clips=[src_u, src_v], expr=expr_u)
dst_v = c.std.Expr(clips=[src_u, src_v], expr=expr_v)
clip = c.std.ShufflePlanes(clips=[clip, dst_u, dst_v], planes=[0, 0, 0], colorfamily=clip.format.color_family)
if bright is not None or cont is not None:
bright = 0.0 if bright is None else bright
cont = 1.0 if cont is None else cont
if clip.format.sample_type == vs.INTEGER:
luma_lut = []
luma_min = 0
luma_max = (2 ** clip.format.bits_per_sample) - 1
if coring: