summaryrefslogtreecommitdiff
path: root/py/tests/gamma.py
blob: 03499bc56fe564619c70b10a03c6b66cb75feec9 (plain)
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
#!/usr/bin/python3

import pykms
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-c", "--connector", default="")
parser.add_argument("-l", "--legacy", action="store_true", default=False)
args = parser.parse_args()

card = pykms.Card()
res = pykms.ResourceManager(card)
conn = res.reserve_connector(args.connector)
crtc = res.reserve_crtc(conn)
mode = conn.get_default_mode()

fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
pykms.draw_test_pattern(fb);

crtc.set_mode(conn, fb, mode)

use_legacy = args.legacy

if not use_legacy:
	prop = crtc.get_prop("GAMMA_LUT")

	if not prop:
		prop = crtc.get_prop("DEGAMMA_LUT")

		if not prop:
			print("No gamma property found")
			exit(-1)
		else:
			print("Using DEGAMMA_LUT for gamma")


def legacy_gamma_set():
	len = crtc.legacy_gamma_size()

	table = []

	for i in range(len):
	    g = round(65535 * pow(i / float(len), 1 / 2.2))
	    table.append((g, g, g))

	crtc.legacy_gamma_set(table)

def legacy_gamma_clear():
	len = crtc.legacy_gamma_size()

	table = []

	for i in range(len):
	    g = round(65535 * (i / float(len)))
	    table.append((g, g, g))

	crtc.legacy_gamma_set(table)

def gamma_set():
	len=256
	arr = bytearray(len*2*4)
	view = memoryview(arr).cast("H")

	for i in range(len):
	    g = round(65535 * pow(i / float(len), 1 / 2.2))

	    view[i * 4 + 0] = g
	    view[i * 4 + 1] = g
	    view[i * 4 + 2] = g
	    view[i * 4 + 3] = 0

	gamma = pykms.Blob(card, arr);

	crtc.set_prop(prop, gamma.id)


def gamma_clear():
	crtc.set_prop(prop, 0)

input("press enter to apply gamma\n")

if use_legacy:
	legacy_gamma_set()
else:
	gamma_set()

input("press enter to remove gamma\n")

if use_legacy:
	legacy_gamma_clear()
else:
	gamma_clear()

input("press enter to exit\n")