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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#!/usr/bin/env python3
'''
pylibcoopgamma -- Python library for interfacing with cooperative gamma servers
Copyright (C) 2016 Mattias Andrée (maandree@kth.se)
This library 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 3 of the License, or
(at your option) any later version.
This library 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 library. If not, see <http://www.gnu.org/licenses/>.
'''
import os, sys, time
os.chdir('/'.join(sys.argv[0].split('/')[:-1]))
sys.path.append('../bin')
import libcoopgamma
cg = libcoopgamma
if len(sys.argv) == 1:
print('\033[1m%s:\033[m' % 'Methods')
for m in cg.get_methods():
print(m)
print()
print('\033[1m%s:\033[m' % 'Method')
print(cg.get_method_and_site()[0])
print()
print('\033[1m%s:\033[m' % 'Site')
print(cg.get_method_and_site()[1])
print()
print('\033[1m%s:\033[m' % 'PID file')
print(cg.get_pid_file())
print()
print('\033[1m%s:\033[m' % 'Socket')
print(cg.get_socket_file())
print()
g = cg.Context()
g.connect()
g.detach()
gstr = repr(g)
del g
argv0 = './' + sys.argv[0].split('/')[-1]
os.execl(argv0, argv0, gstr)
else:
g = eval(sys.argv[1])
g.attach()
print('\033[1m%s:\033[m' % 'CRTC:s')
for crtc in g.get_crtcs_sync():
print(crtc)
print()
info = g.get_gamma_info_sync(crtc)
print('\033[1m%s:\033[m' % 'CRTC info')
print('Cooperative:', 'yes' if info.cooperative else 'no')
if info.depth is not None:
print('Depth:', cg.Depth.str(info.depth))
print('Supported:', cg.Support.str(info.supported))
if info.red_size is not None:
print('Red stops:', info.red_size)
if info.green_size is not None:
print('Green stops:', info.green_size)
if info.blue_size is not None:
print('Blue stops:', info.blue_size)
print('Colourspace:', cg.Colourspace.str(info.colourspace))
if info.gamut is not None:
print('Red point:', str(info.gamut.red))
print('Green point:', str(info.gamut.green))
print('Blue point:', str(info.gamut.blue))
print('White point:', str(info.gamut.white))
print()
table = g.get_gamma_sync(cg.FilterQuery(crtc = crtc, coalesce = False))
print('\033[1m%s:\033[m' % 'Filter table')
print('Red stops:', table.red_size)
print('Green stops:', table.green_size)
print('Blue stops:', table.blue_size)
print('Depth:', cg.Depth.str(table.depth))
for i, fltr in enumerate(table.filters):
print('Filter %i:' % i)
print(' Priority:', fltr.priority)
print(' Class:', fltr.fclass)
print(' Ramps:')
rr, gr, br = fltr.ramps.red, fltr.ramps.green, fltr.ramps.blue
n = max(len(rr), len(gr), len(br))
fmt = ' \033[31m%s \033[32m%s \033[34m%s\033[m'
rr = [str(rr[i]) if i < len(rr) else '' for i in range(n)]
gr = [str(gr[i]) if i < len(gr) else '' for i in range(n)]
br = [str(br[i]) if i < len(br) else '' for i in range(n)]
for y in zip(rr, gr, br):
print(fmt % y)
print()
table = g.get_gamma_sync(cg.FilterQuery(crtc = crtc, coalesce = True))
print('\033[1m%s:\033[m' % 'Filter table')
print('Red stops:', table.red_size)
print('Green stops:', table.green_size)
print('Blue stops:', table.blue_size)
print('Depth:', cg.Depth.str(table.depth))
for fltr in table.filters:
print('Ramps:')
rr, gr, br = fltr.ramps.red, fltr.ramps.green, fltr.ramps.blue
n = max(len(rr), len(gr), len(br))
fmt = ' \033[31m%s \033[32m%s \033[34m%s\033[m'
rr = [str(rr[i]) if i < len(rr) else '' for i in range(n)]
gr = [str(gr[i]) if i < len(gr) else '' for i in range(n)]
br = [str(br[i]) if i < len(br) else '' for i in range(n)]
for y in zip(rr, gr, br):
print(fmt % y)
print()
fltr = cg.Filter(0, crtc, 'pylibcoopgamma::test::test', cg.Lifespan.UNTIL_DEATH, table.depth,
cg.Ramps(table.red_size, table.green_size, table.blue_size))
if table.depth < 0:
Y = lambda x : x
else:
m = 2 ** table.depth - 1
Y = lambda x : int(x * m)
redzero = fltr.ramps.red
greenzero = fltr.ramps.green
fltr.ramps.red = [Y(x / (table.red_size - 1)) for x in range(table.red_size)]
g.set_gamma_sync(fltr)
time.sleep(0.5)
fltr.ramps.red = redzero
fltr.ramps.green = [Y(x / (table.green_size - 1)) for x in range(table.green_size)]
g.set_gamma_sync(fltr)
time.sleep(0.5)
fltr.ramps.green = greenzero
fltr.ramps.blue = [Y(x / (table.blue_size - 1)) for x in range(table.blue_size)]
g.set_gamma_sync(fltr)
time.sleep(0.5)
del g
|