aboutsummaryrefslogtreecommitdiffstats
path: root/test
blob: 407c6681d6f05ce3947d3984f31e4ff45120ba70 (plain) (blame)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#!/usr/bin/env python3
# See LICENSE file for copyright and license details.

import os, sys, time, errno, select

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()
    pass

print('\033[1m%s:\033[m' % 'CRTC:s')
crtcs = g.get_crtcs_sync()
for crtc in crtcs:
    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_nc = table

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()
table_c = table

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
redid = [Y(x / (table.red_size - 1)) for x in range(table.red_size)]
greenid = [Y(x / (table.green_size - 1)) for x in range(table.green_size)]
blueid = [Y(x / (table.blue_size - 1)) for x in range(table.blue_size)]

fltr.ramps.red = redid
g.set_gamma_sync(fltr)
time.sleep(0.5)
fltr.ramps.red = redzero

fltr.ramps.green = greenid
g.set_gamma_sync(fltr)
time.sleep(0.5)
fltr.ramps.green = greenzero

fltr.ramps.blue = blueid
g.set_gamma_sync(fltr)
time.sleep(0.5)

g.set_nonbreaking(False)

asynch = cg.AsyncContext()

def flush(e):
    if e.errno in (errno.EINTR, errno.EWOULDBLOCK, errno.EAGAIN):
        while True:
            try:
                g.flush()
            except OSError as ex:
                if ex.errno in (errno.EINTR, errno.EWOULDBLOCK, errno.EAGAIN):
                    continue
                else:
                    raise ex
            break
    else:
        raise e

try:
    g.get_crtcs_send(asynch)
except OSError as e:
    flush(e)
if g.synchronise([asynch]) != 0:
     sys.exit(1)
if g.get_crtcs_recv(asynch) != crtcs:
    sys.exit(2)

try:
    g.get_gamma_info_send(crtc, asynch)
except OSError as e:
    flush(e)
if g.synchronise([asynch]) != 0:
     sys.exit(3)
info2 = g.get_gamma_info_recv(asynch)
if info2.cooperative != info.cooperative:
    sys.exit(4)
if info2.depth != info.depth:
    sys.exit(4)
if info2.supported != info.supported:
    sys.exit(4)
if info2.red_size != info.red_size:
    sys.exit(4)
if info2.green_size != info.green_size:
    sys.exit(4)
if info2.blue_size != info.blue_size:
    sys.exit(4)
if info2.colourspace != info.colourspace:
    sys.exit(4)
if (info2.gamut is None) != (info.gamut is None):
    sys.exit(4)
if info.gamut is not None:
    if info2.gamut.red.x_raw != info.gamut.red.x_raw or info2.gamut.red.x != info.gamut.red.x:
        sys.exit(4)
    if info2.gamut.red.y_raw != info.gamut.red.y_raw or info2.gamut.red.y != info.gamut.red.y:
        sys.exit(4)
    if info2.gamut.green.x_raw != info.gamut.green.x_raw or info2.gamut.green.x != info.gamut.green.x:
        sys.exit(4)
    if info2.gamut.green.y_raw != info.gamut.green.y_raw or info2.gamut.green.y != info.gamut.green.y:
        sys.exit(4)
    if info2.gamut.blue.x_raw != info.gamut.blue.x_raw or info2.gamut.blue.x != info.gamut.blue.x:
        sys.exit(4)
    if info2.gamut.blue.y_raw != info.gamut.blue.y_raw or info2.gamut.blue.y != info.gamut.blue.y:
        sys.exit(4)
    if info2.gamut.white.x_raw != info.gamut.white.x_raw or info2.gamut.white.x != info.gamut.white.x:
        sys.exit(4)
    if info2.gamut.white.y_raw != info.gamut.white.y_raw or info2.gamut.white.y != info.gamut.white.y:
        sys.exit(4)

try:
    g.set_gamma_send(cg.Filter(crtc = crtc, fclass = 'pylibcoopgamma::test::test',
                               lifespan = cg.Lifespan.REMOVE), asynch)
except OSError as e:
    flush(e)
if g.synchronise([asynch]) != 0:
     sys.exit(1)
g.set_gamma_recv(asynch)

try:
    g.get_gamma_send(cg.FilterQuery(crtc = crtc, coalesce = False), asynch)
except OSError as e:
    flush(e)
if g.synchronise([asynch]) != 0:
     sys.exit(5)
table = g.get_gamma_recv(asynch)
if table.red_size != table_nc.red_size:
    sys.exit(6)
if table.green_size != table_nc.green_size:
    sys.exit(6)
if table.blue_size != table_nc.blue_size:
    sys.exit(6)
if table.depth != table_nc.depth:
    sys.exit(6)
if len(table.filters) != len(table_nc.filters):
    sys.exit(6)
for i, (fltr1, fltr2) in enumerate(zip(table.filters, table_nc.filters)):
    if fltr1.priority != fltr2.priority:
        sys.exit(6)
    if fltr1.fclass != fltr2.fclass:
        sys.exit(6)
    if fltr1.ramps.red != fltr2.ramps.red:
        sys.exit(6)
    if fltr1.ramps.green != fltr2.ramps.green:
        sys.exit(6)
    if fltr1.ramps.blue != fltr2.ramps.blue:
        sys.exit(6)

try:
    g.get_gamma_send(cg.FilterQuery(crtc = crtc, coalesce = True), asynch)
except OSError as e:
    flush(e)
if g.synchronise([asynch]) != 0:
     sys.exit(7)
table = g.get_gamma_recv(asynch)
if table.red_size != table_c.red_size:
    sys.exit(8)
if table.green_size != table_c.green_size:
    sys.exit(8)
if table.blue_size != table_c.blue_size:
    sys.exit(8)
if table.depth != table_c.depth:
    sys.exit(8)
if len(table.filters) != len(table_c.filters):
    sys.exit(8)
for i, (fltr1, fltr2) in enumerate(zip(table.filters, table_c.filters)):
    if fltr1.ramps.red != fltr2.ramps.red:
        sys.exit(8)
    if fltr1.ramps.green != fltr2.ramps.green:
        sys.exit(8)
    if fltr1.ramps.blue != fltr2.ramps.blue:
        sys.exit(8)


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))

fltr.ramps.red = list(reversed(redid))
fltr.ramps.green = list(reversed(greenid))
fltr.ramps.blue = list(reversed(blueid))
try:
    g.set_gamma_send(fltr, asynch)
except OSError as e:
    flush(e)
if g.synchronise([asynch]) != 0:
    sys.exit(9)
g.skip_message()
time.sleep(0.5)

fltr.ramps.red = redid
fltr.ramps.green = greenid
fltr.ramps.blue = blueid
g.set_gamma_sync(fltr)

g.set_nonbreaking(True)

async1 = asynch
async2 = cg.AsyncContext()
async3 = cg.AsyncContext()
time.sleep(0.5)

fltr.ramps.red = list(reversed(redid))
fltr.fclass = 'pylibcoopgamma::test::red'
try:
    g.set_gamma_send(fltr, async1)
    need_flush = True
except OSError as e:
    if e.errno not in (errno.EINTR, errno.EWOULDBLOCK, errno.EAGAIN):
        sys.exit(10)
    need_flush = False
fltr.ramps.red = redid

fltr.ramps.green = list(reversed(greenid))
fltr.fclass = 'pylibcoopgamma::test::green'
try:
    g.set_gamma_send(fltr, async2)
    need_flush = True
except OSError as e:
    if e.errno not in (errno.EINTR, errno.EWOULDBLOCK, errno.EAGAIN):
        sys.exit(10)
    need_flush = False
fltr.ramps.green = greenid

fltr.ramps.blue = list(reversed(blueid))
fltr.fclass = 'pylibcoopgamma::test::blue'
try:
    g.set_gamma_send(fltr, async3)
    need_flush = True
except OSError as e:
    if e.errno not in (errno.EINTR, errno.EWOULDBLOCK, errno.EAGAIN):
        sys.exit(10)
    need_flush = False
fltr.ramps.blue = blueid

while need_flush:
    try:
        g.flush()
        break
    except OSError as e:
        if e.errno in (errno.EINTR, errno.EWOULDBLOCK, errno.EAGAIN):
            continue
        else:
            sys.exit(11)

poll = select.poll()
poll.register(g.fd, select.POLLIN | select.POLLPRI)

unsynced = [True] * 3
while any(unsynced):
    poll.poll()
    n = g.synchronise([async1, async2, async3])
    if n < 0 or n >= 3 or not unsynced[n]:
        sys.exit(12)
    unsynced[n] = False
    g.set_gamma_recv([async1, async2, async3][n])

time.sleep(0.5)
del g