54 lines
962 B
Python
54 lines
962 B
Python
import numpy as np
|
|
from ctypes import c_float
|
|
|
|
def str2bool(v):
|
|
if isinstance(v,bool):
|
|
return v
|
|
return v.lower() in ('TRUE', 'True', 'true', '1', 'T', 't', 'Y', 'YES', 'y', 'yes')
|
|
|
|
|
|
def str2int(s):
|
|
if s == "":
|
|
s = 0
|
|
s = int(s)
|
|
return s
|
|
|
|
def str2float(s):
|
|
if s == "":
|
|
s = 0
|
|
s = float(s)
|
|
return s
|
|
|
|
def signed_rounding(value, bit):
|
|
if value < 0:
|
|
value = value - (1 << (bit - 1))
|
|
else:
|
|
value = value + (1 << (bit - 1))
|
|
|
|
return value
|
|
|
|
def str_fill(value):
|
|
if len(value) == 1:
|
|
value = "0" + value
|
|
elif len(value) == 0:
|
|
value = "00"
|
|
|
|
return value
|
|
|
|
def clip_ary(value):
|
|
list_v = []
|
|
for i in range(len(value)):
|
|
v = value[i] % 256
|
|
list_v.append(v)
|
|
|
|
return list_v
|
|
|
|
def clip(value, mini, maxi):
|
|
if value < mini:
|
|
result = mini
|
|
elif value > maxi:
|
|
result = maxi
|
|
else:
|
|
result = value
|
|
|
|
return result |