Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_depth(self):
with self.assertRaisesRegex(ValueError, 'sample_type must be in'):
vsutil.depth(self.RGB24_CLIP, 8, sample_type=2)
with self.assertRaisesRegex(ValueError, 'range must be in'):
vsutil.depth(self.RGB24_CLIP, 8, range=2)
with self.assertRaisesRegex(ValueError, 'range_in must be in'):
vsutil.depth(self.RGB24_CLIP, 8, range_in=2)
with self.assertRaisesRegex(ValueError, 'dither_type must be in'):
vsutil.depth(self.RGB24_CLIP, 8, dither_type='test')
full_clip = vs.core.std.BlankClip(format=vs.RGB24)
int_10_clip = full_clip.resize.Point(format=full_clip.format.replace(bits_per_sample=10))
int_16_clip = full_clip.resize.Point(format=full_clip.format.replace(bits_per_sample=16))
float_16_clip = full_clip.resize.Point(format=full_clip.format.replace(bits_per_sample=16, sample_type=vs.FLOAT))
float_32_clip = full_clip.resize.Point(format=full_clip.format.replace(bits_per_sample=32, sample_type=vs.FLOAT))
limited_clip = vs.core.std.BlankClip(format=vs.YUV420P8)
l_int_10_clip = limited_clip.resize.Point(format=limited_clip.format.replace(bits_per_sample=10))
l_int_16_clip = limited_clip.resize.Point(format=limited_clip.format.replace(bits_per_sample=16))
l_float_16_clip = limited_clip.resize.Point(format=limited_clip.format.replace(bits_per_sample=16, sample_type=vs.FLOAT))
l_float_32_clip = limited_clip.resize.Point(format=limited_clip.format.replace(bits_per_sample=32, sample_type=vs.FLOAT))
self.assertEqual(vsutil.depth(full_clip, 8), full_clip)
self.assert_same_format(vsutil.depth(full_clip, 10), int_10_clip)
self.assert_same_format(vsutil.depth(full_clip, 16), int_16_clip)
self.assert_same_format(vsutil.depth(full_clip, 16, sample_type=vs.FLOAT), float_16_clip)
self.assert_same_format(vsutil.depth(full_clip, 32), float_32_clip)
self.assert_same_format(vsutil.depth(float_16_clip, 16, sample_type=vs.INTEGER), int_16_clip)
self.assertEqual(vsutil.depth(limited_clip, 8), limited_clip)
raise TypeError(funcName + ': \"fulls\" must be a bool!')
else:
clip = SetColorSpace(clip, ColorRange=0 if fulls else 1)
# Get properties of output clip
if depth is None:
dbitPS = sbitPS
elif not isinstance(depth, int):
raise TypeError(funcName + ': \"depth\" must be an int!')
else:
dbitPS = depth
if sample is None:
if depth is None:
dSType = sSType
else:
dSType = vs.FLOAT if dbitPS >= 32 else vs.INTEGER
elif not isinstance(sample, int):
raise TypeError(funcName + ': \"sample\" must be an int!')
elif sample != vs.INTEGER and sample != vs.FLOAT:
raise ValueError(funcName + ': \"sample\" must be either 0(vs.INTEGER) or 1(vs.FLOAT)!')
else:
dSType = sample
if dSType == vs.INTEGER and (dbitPS < 8 or dbitPS > 16):
raise ValueError(funcName + ': {0}-bit integer output is not supported!'.format(dbitPS))
if dSType == vs.FLOAT and (dbitPS != 16 and dbitPS != 32):
raise ValueError(funcName + ': {0}-bit float output is not supported!'.format(dbitPS))
if fulld is None:
fulld = fulls
elif not isinstance(fulld, int):
raise TypeError(funcName + ': \"fulld\" must be a bool!')
# Get properties of output clip
if depth is None:
dbitPS = sbitPS
elif not isinstance(depth, int):
raise TypeError(funcName + ': \"depth\" must be an int!')
else:
dbitPS = depth
if sample is None:
if depth is None:
dSType = sSType
else:
dSType = vs.FLOAT if dbitPS >= 32 else vs.INTEGER
elif not isinstance(sample, int):
raise TypeError(funcName + ': \"sample\" must be an int!')
elif sample != vs.INTEGER and sample != vs.FLOAT:
raise ValueError(funcName + ': \"sample\" must be either 0(vs.INTEGER) or 1(vs.FLOAT)!')
else:
dSType = sample
if dSType == vs.INTEGER and (dbitPS < 8 or dbitPS > 16):
raise ValueError(funcName + ': {0}-bit integer output is not supported!'.format(dbitPS))
if dSType == vs.FLOAT and (dbitPS != 16 and dbitPS != 32):
raise ValueError(funcName + ': {0}-bit float output is not supported!'.format(dbitPS))
if fulld is None:
fulld = fulls
elif not isinstance(fulld, int):
raise TypeError(funcName + ': \"fulld\" must be a bool!')
# Whether to use z.Depth or fmtc.bitdepth for conversion
# If not set, when full range is involved for integer format, use z.Depth
# When 11-,13-,14-,15-bit integer or 16-bit float format is involved, always use z.Depth
# Get properties of output clip
if depth is None:
dbitPS = sbitPS
elif not isinstance(depth, int):
raise TypeError(funcName + ': \"depth\" must be an int!')
else:
dbitPS = depth
if sample is None:
if depth is None:
dSType = sSType
else:
dSType = vs.FLOAT if dbitPS >= 32 else vs.INTEGER
elif not isinstance(sample, int):
raise TypeError(funcName + ': \"sample\" must be an int!')
elif sample != vs.INTEGER and sample != vs.FLOAT:
raise ValueError(funcName + ': \"sample\" must be either 0(vs.INTEGER) or 1(vs.FLOAT)!')
else:
dSType = sample
if dSType == vs.INTEGER and (dbitPS < 8 or dbitPS > 16):
raise ValueError(funcName + ': {0}-bit integer output is not supported!'.format(dbitPS))
if dSType == vs.FLOAT and (dbitPS != 16 and dbitPS != 32):
raise ValueError(funcName + ': {0}-bit float output is not supported!'.format(dbitPS))
if full is None:
# If not set, assume limited range for YUV and Gray output
# Assume full range for YCgCo and OPP output
if matrix == "RGB" or matrix == "YCgCo" or matrix == "OPP":
fulld = True
else:
fulld = True if sIsYCOCG else False
elif not isinstance(full, int):
n = n + 1
if not isinstance(c, vs.VideoNode):
raise TypeError(funcName + ': \"clips\" must be a list of clips!')
tlist.append(c)
clips = tlist
ref = clips[0]
else:
raise TypeError(funcName + ': \"clips\" must be a list of clips!')
# Get properties of output clip
if depth is None:
depth = 10
elif not isinstance(depth, int):
raise TypeError(funcName + ': \"depth\" must be an int!')
if depth >= 32:
sample = vs.FLOAT
else:
sample = vs.INTEGER
dFormat = core.register_format(vs.YUV, sample, depth, 0, 0).id
def Conv(clip,txt):
if (ref.width % clip.width == 0) and (ref.height % clip.height == 0):
clip = core.resize.Point(clip, ref.width, ref.height, matrix_s = matrix_s, format=dFormat, matrix_in=mvs.GetMatrix(clip, matrix, True, True), range_in=full, dither_type=dither, prefer_props=prefer_props)
else:
clip = core.resize.Bicubic(clip, ref.width, ref.height, matrix_s = matrix_s, format=dFormat, matrix_in=mvs.GetMatrix(clip, matrix, True, True), range_in=full, filter_param_a=0, filter_param_b=0.5, dither_type=dither, prefer_props=prefer_props)
if txt is not None:
clip = core.text.Text(clip, txt, alignment = alignment)
return clip
for i in range(len(clips)):
clips[i] = Conv(clips[i], writelist[i])
clip = core.std.Interleave(clips, extend = False)
def retinex_edgemask(src: vs.VideoNode, sigma=1) -> vs.VideoNode:
"""
Use retinex to greatly improve the accuracy of the edge detection in dark scenes.
sigma is the sigma of tcanny
"""
luma = get_y(src)
max_value = 1 if src.format.sample_type == vs.FLOAT else (1 << get_depth(src)) - 1
ret = core.retinex.MSRCP(luma, sigma=[50, 200, 350], upper_thr=0.005)
tcanny = ret.tcanny.TCanny(mode=1, sigma=sigma).std.Minimum(coordinates=[1, 0, 1, 0, 0, 1, 0, 1])
return core.std.Expr([kirsch(luma), tcanny], f'x y + {max_value} min')
sSType = sFormat.sample_type
sbitPS = sFormat.bits_per_sample
sNumPlanes = sFormat.num_planes
valueRange = (1 << sbitPS) - 1 if sSType == vs.INTEGER else 1
# 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))
floatFormat = core.register_format(vs.GRAY, vs.FLOAT, 32, 0, 0)
floatBlk = core.std.BlankClip(clip, format=floatFormat.id)
clipPlane = GetPlane(clip, plane)
# Plane Mean
clip = core.std.PlaneAverage(clip, plane, "PlaneMean")
# Plane MAD (mean absolute deviation)
if mad:
'''# always float precision
def _PlaneADFrame(n, f, clip):
mean = f.props.PlaneMean
expr = "x {gain} * {mean} - abs".format(gain=1 / valueRange, mean=mean)
return core.std.Expr(clip, expr, floatFormat.id)
ADclip = core.std.FrameEval(floatBlk, functools.partial(_PlaneADFrame, clip=clipPlane), clip)'''
def _PlaneADFrame(n, f, clip):
def TempLinearApproximateMC(clip, meclip = None, radius = 2, planes = None, denoise = None, subpel = 4, subpelinterp = None, dct = None, refine = True, blocksize = None, overlap = None, search = None, searchparam = None, pelsearch = None, chromamotion = True, truemotion = True, _lambda = None, lsad = None, pnew = None, plevel = None, globalmotion = True, thsad = None, thscd1 = None, thscd2 = None, badsad = None, badrange = None, trymany = None, gamma = None, ftype = None, sigma = None, sigma2 = None, pmin = None, pmax = None, sbsize = None, smode = None, sosize = None, swin = None, twin = None, sbeta = None, tbeta = None, zmean = None, f0beta = None, nstring = None, sstring = None, ssx = None, ssy = None, sst = None):
#-------------------------------------------------------------------------------------------------------------------------------------
core = vs.get_core()
if not isinstance(radius, int) or radius < 1:
raise ValueError("MCDenoise.TempLinearApproximate: 'radius' must be an integer larger than 1.")
if denoise is None:
denoise = 'tla'
if denoise not in ['tla', 'dfttest']:
raise ValueError("MCDenoise.TempLinearApproximate: invalid value for 'denoise'. Valid values are: 'tla', 'dfttest'.")
mv = core.mv
if clip.format.sample_type == vs.FLOAT:
mv = core.mvsf
#-------------------------------------------------------------------------------------------------------------------------------------
tla_arguments = {'radius': radius, 'planes': planes, 'gamma': gamma}
dfttest_arguments = {
'ftype': ftype,
'sigma': sigma,
'sigma2': sigma2,
'pmin': pmin,
'pmax': pmax,
'sbsize': sbsize,
'smode': smode,
'sosize': sosize,
'tbsize': radius * 2 + 1,
'swin': swin,
raise TypeError(funcName + ': \"full\" must be a bool!')
else:
fulls = full
# Get properties of output clip
if depth is None:
dbitPS = sbitPS
elif not isinstance(depth, int):
raise TypeError(funcName + ': \"depth\" must be an int!')
else:
dbitPS = depth
if sample is None:
if depth is None:
dSType = sSType
else:
dSType = vs.FLOAT if dbitPS >= 32 else vs.INTEGER
elif not isinstance(sample, int):
raise TypeError(funcName + ': \"sample\" must be an int!')
elif sample != vs.INTEGER and sample != vs.FLOAT:
raise ValueError(funcName + ': \"sample\" must be either 0(vs.INTEGER) or 1(vs.FLOAT)!')
else:
dSType = sample
if dSType == vs.INTEGER and (dbitPS < 8 or dbitPS > 16):
raise ValueError(funcName + ': {0}-bit integer output is not supported!'.format(dbitPS))
if dSType == vs.FLOAT and (dbitPS != 16 and dbitPS != 32):
raise ValueError(funcName + ': {0}-bit float output is not supported!'.format(dbitPS))
fulld = True
# Get properties of internal processed clip
pSType = max(sSType, dSType) # If float sample type is involved, then use float for conversion
if pSType == vs.FLOAT:
else:
dbitPS = depth
if sample is None:
if depth is None:
dSType = sSType
else:
dSType = vs.FLOAT if dbitPS >= 32 else vs.INTEGER
elif not isinstance(sample, int):
raise TypeError(funcName + ': \"sample\" must be an int!')
elif sample != vs.INTEGER and sample != vs.FLOAT:
raise ValueError(funcName + ': \"sample\" must be either 0(vs.INTEGER) or 1(vs.FLOAT)!')
else:
dSType = sample
if dSType == vs.INTEGER and (dbitPS < 8 or dbitPS > 16):
raise ValueError(funcName + ': {0}-bit integer output is not supported!'.format(dbitPS))
if dSType == vs.FLOAT and (dbitPS != 16 and dbitPS != 32):
raise ValueError(funcName + ': {0}-bit float output is not supported!'.format(dbitPS))
if fulld is None:
fulld = fulls
elif not isinstance(fulld, int):
raise TypeError(funcName + ': \"fulld\" must be a bool!')
# Whether to use z.Depth or fmtc.bitdepth for conversion
# If not set, when full range is involved for integer format, use z.Depth
# When 11-,13-,14-,15-bit integer or 16-bit float format is involved, always use z.Depth
if useZ is None:
useZ = (sSType == vs.INTEGER and fulls) or (dSType == vs.INTEGER and fulld)
elif not isinstance(useZ, int):
raise TypeError(funcName + ': \"useZ\" must be a bool!')
if sSType == vs.INTEGER and (sbitPS == 13 or sbitPS == 15):
useZ = True