Debian Codegraph @

util/lincal.py

raw
1 #!/usr/bin/env python3
2 import os
3 import sys
4 from time import strftime
5
6
7 if __name__ == "__main__":
8 if len(sys.argv) in (3, 4):
9 curve = []
10 start = float(sys.argv[1]) / 100
11 end = float(sys.argv[2]) / 100
12 steps = 256
13 if len(sys.argv) > 3:
14 steps = int(sys.argv[3])
15 if start == end:
16 print("ERROR: start == end")
17 else:
18 step = (end - start) / (steps - 1)
19 i = start
20 for _x in range(steps):
21 curve += [i]
22 i += step
23 if curve[-1] != end:
24 curve += [end]
25 print("CAL ")
26 print("")
27 print('DESCRIPTOR "Argyll Device Calibration Curves"')
28 print('ORIGINATOR "lincal.py"')
29 print('CREATED "%s"' % strftime("%a %b %d %H:%I:%S %Y"))
30 print('KEYWORD "DEVICE_CLASS"')
31 print('DEVICE_CLASS "DISPLAY"')
32 print('KEYWORD "COLOR_REP"')
33 print('COLOR_REP "RGB"')
34 print("")
35 print('KEYWORD "RGB_I"')
36 print("NUMBER_OF_FIELDS 4")
37 print("BEGIN_DATA_FORMAT")
38 print("RGB_I RGB_R RGB_G RGB_B")
39 print("END_DATA_FORMAT")
40 print("")
41 print("NUMBER_OF_SETS %i" % steps)
42 print("BEGIN_DATA")
43 for i in range(steps):
44 print(
45 " ".join(
46 [
47 str(round(col, 7 if col < 0.1 else 6)).ljust(7, "0")
48 for col in [(1.0 / (steps - 1)) * i] + [curve[i]] * 3
49 ]
50 )
51 )
52 print("END_DATA")
53 else:
54 print("Usage: %s start end steps" % os.path.basename(__file__))
55 print(" start, end = integer between 0 and 100")
56 print(" steps = number of steps (default 256)")