diff options
Diffstat (limited to 'py/tests/ctm_test.py')
-rwxr-xr-x | py/tests/ctm_test.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/py/tests/ctm_test.py b/py/tests/ctm_test.py new file mode 100755 index 0000000..7ceed6f --- /dev/null +++ b/py/tests/ctm_test.py | |||
@@ -0,0 +1,86 @@ | |||
1 | #!/usr/bin/python3 | ||
2 | |||
3 | import sys | ||
4 | import pykms | ||
5 | |||
6 | def ctm_to_blob(ctm, card): | ||
7 | len=9 | ||
8 | arr = bytearray(len*8) | ||
9 | view = memoryview(arr).cast("I") | ||
10 | |||
11 | for x in range(len): | ||
12 | i, d = divmod(ctm[x], 1) | ||
13 | if i < 0: | ||
14 | i = -i | ||
15 | sign = 1 << 31 | ||
16 | else: | ||
17 | sign = 0 | ||
18 | view[x * 2 + 0] = int(d * ((2 ** 32) - 1)) | ||
19 | view[x * 2 + 1] = int(i) | sign | ||
20 | #print("%f = %08x.%08x" % (ctm[x], view[x * 2 + 1], view[x * 2 + 0])) | ||
21 | |||
22 | return pykms.Blob(card, arr); | ||
23 | |||
24 | |||
25 | if len(sys.argv) > 1: | ||
26 | conn_name = sys.argv[1] | ||
27 | else: | ||
28 | conn_name = "" | ||
29 | |||
30 | card = pykms.Card() | ||
31 | res = pykms.ResourceManager(card) | ||
32 | conn = res.reserve_connector(conn_name) | ||
33 | crtc = res.reserve_crtc(conn) | ||
34 | mode = conn.get_default_mode() | ||
35 | |||
36 | fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24"); | ||
37 | pykms.draw_test_pattern(fb); | ||
38 | |||
39 | crtc.set_mode(conn, fb, mode) | ||
40 | |||
41 | input("press enter to set normal ctm\n") | ||
42 | |||
43 | ctm = [ 1.0, 0.0, 0.0, | ||
44 | 0.0, 1.0, 0.0, | ||
45 | 0.0, 0.0, 1.0 ] | ||
46 | |||
47 | ctmb = ctm_to_blob(ctm, card) | ||
48 | |||
49 | crtc.set_prop("CTM", ctmb.id) | ||
50 | |||
51 | input("press enter to set new ctm\n") | ||
52 | |||
53 | ctm = [ 0.0, 1.0, 0.0, | ||
54 | 0.0, 0.0, 1.0, | ||
55 | 1.0, 0.0, 0.0 ] | ||
56 | |||
57 | ctmb = ctm_to_blob(ctm, card) | ||
58 | |||
59 | crtc.set_prop("CTM", ctmb.id) | ||
60 | |||
61 | print("r->b g->r b->g ctm active\n") | ||
62 | |||
63 | input("press enter to set new ctm\n") | ||
64 | |||
65 | ctm = [ 0.0, 0.0, 1.0, | ||
66 | 1.0, 0.0, 0.0, | ||
67 | 0.0, 1.0, 0.0 ] | ||
68 | |||
69 | ctmb = ctm_to_blob(ctm, card) | ||
70 | |||
71 | crtc.set_prop("CTM", ctmb.id) | ||
72 | input("r->g g->b b->r ctm active\n") | ||
73 | |||
74 | input("press enter to turn off the crtc\n") | ||
75 | |||
76 | crtc.disable_mode() | ||
77 | |||
78 | input("press enter to enable crtc again\n") | ||
79 | |||
80 | crtc.set_mode(conn, fb, mode) | ||
81 | |||
82 | input("press enter to remove ctm\n") | ||
83 | |||
84 | crtc.set_prop("CTM", 0) | ||
85 | |||
86 | input("press enter to exit\n") | ||