-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjoke01.py
73 lines (71 loc) · 2.82 KB
/
joke01.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
import vapoursynth as vs
core=vs.core
import zvs
__all__=['lrnoise','debit']
def lrnoise(src,lr=(1280,720),gy=50,gc=0,hc=0,vc=0,con=0,seed=1,opt=0,a1=20,adg=False,mdg=False,azmdg={},cdif=False,fnoise=None):
src=src.fmtc.bitdepth(bits=16)
za={'thsad':1000,'truemotion':True}
za.update(azmdg)
last=src
lr=last.fmtc.resample(lr[0],lr[1])
if callable(fnoise):
lrn=fnoise(lr)
else:
lrn=core.grain.Add(lr,var=gy,uvar=gc,hcorr=hc,vcorr=vc,constant=con,seed=seed,opt=opt)
if adg:
lr=lr.std.PlaneStats()
lrm=lr.adg.Mask(adg)
lrn=core.std.MaskedMerge(lr,lrn,lrm)
if mdg: mvd=zvs.zmdg(lr,mvout=True,**za)
if cdif:
nd=zvs.cdif(lrn,lr)
else:
nd=core.std.MakeDiff(lrn,lr)
if mdg: nd=zvs.zmdg(nd,mvin=mvd,**za)
ndhr=nd.fmtc.resample(last.width,last.height,kernel='gaussian',a1=a1)
if cdif:
last=zvs.cdif(last,ndhr,1)
else:
last=core.std.MergeDiff(last,ndhr)
return last
# i know mvf.Depth can do just want a simpler approach
# is it still the depth we want if chroma sign is considered? what about the range of values?
# brain cells are dying
def debit(src,depth=1,dither=0,fulls=None,fulld=None,cs=False,cs2=False,count=None):
if depth>=8 or (count!=None and count>=256):
raise ValueError("use normal dither bro")
isrgb=src.format.color_family==vs.RGB
if fulls==None: fulls=True if isrgb else False
if fulld==None: fulld=True if isrgb else False
if src.format.sample_type==vs.FLOAT:
src=core.resize.Point(src,format=src.format.replace(sample_type=vs.INTEGER,bits_per_sample=16),range_s='full')
fulls=True
if src.format.bits_per_sample < 16:
src=core.std.Expr(src,'x {} *'.format(2**(16-src.format.bits_per_sample)),src.format.replace(bits_per_sample=16))
if isinstance(dither,int):
rehtid=lambda x:x.fmtc.bitdepth(bits=8,dmode=dither)
elif isinstance(dither,str):
rehtid=lambda x:x.resize.Point(format=x.format.replace(bits_per_sample=8),dither_type=dither)
elif callable(dither):
rehtid=dither
if count==None:
count=2**depth
scaling=255/(count-1)
scalingc=scaling if not cs2 else scaling/2
last=src
if not fulls:
last=zvs.setrange(last,'rm')
last=last.resize.Point(range_in_s='limited',range_s='full')
if cs:
last=last.std.Expr([f'x {scaling} /',f'x 32768 - {scalingc} / 32768 +'])
else:
last=last.std.Expr(f'x {scaling} /')
last=rehtid(last)
if cs:
last=last.std.Expr([f'x {scaling} *',f'x 128 - {scalingc} * 128 +'])
else:
last=last.std.Expr(f'x {scaling} *')
if not fulld:
last=zvs.setrange(last,'rm')
last=last.resize.Point(range_in_s='full',range_s='limited')
return last