forked from chezsick/MyGist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
clear2ff.py
executable file
·86 lines (86 loc) · 2.04 KB
/
clear2ff.py
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
import sys
mode = sys.argv[1]
if not "farbfeld" == sys.stdin.read(8):
exit(1)
size = sys.stdin.read(8)
x = (pow(256,3)*ord(size[0]))+(pow(256,2)*ord(size[1]))+(pow(256,1)*ord(size[2]))+(pow(256,0)*ord(size[3]))
y = (pow(256,3)*ord(size[4]))+(pow(256,2)*ord(size[5]))+(pow(256,1)*ord(size[6]))+(pow(256,0)*ord(size[7]))
n = x*y
sys.stdout.write("farbfeld")
sys.stdout.write(size)
while bool(n):
o = sys.stdin.read(8)
r = (ord(o[0])*256)+ord(o[1])
g = (ord(o[2])*256)+ord(o[3])
b = (ord(o[4])*256)+ord(o[5])
rv=r
gv=g
bv=b
if mode == "rc":
d=r-((g+b)/2)
if d < 0:
rv = min(r + abs(d),65535)
elif d > 0:
rv = max(r - abs(d),0)
if mode == "gm":
d=g-((r+b)/2)
if d < 0:
gv = min(g + abs(d),65535)
elif d > 0:
gv = max(g - abs(d),0)
if mode == "by":
d=b-((r+g)/2)
if d < 0:
bv = min(b + abs(d),65535)
elif d > 0:
bv = max(b - abs(d),0)
if mode == "cr":
d=((g+b)/2)-r
if d < 0:
gv = min(g + abs(d),65535)
bv = min(b + abs(d),65535)
elif d > 0:
gv = max(g - abs(d),0)
bv = max(b - abs(d),0)
if mode == "mg":
d=((r+b)/2)-g
if d < 0:
rv = min(r + abs(d),65535)
bv = min(b + abs(d),65535)
elif d > 0:
rv = max(r - abs(d),0)
bv = max(b - abs(d),0)
if mode == "yb":
d=((r+g)/2)-b
if d < 0:
rv = min(r + abs(d),65535)
gv = min(g + abs(d),65535)
elif d > 0:
rv = max(r - abs(d),0)
gv = max(g - abs(d),0)
if mode == "gr":
d=r-b
if d < 0:
rv = min(r + abs(d),65535)
elif d > 0:
rv = max(r - abs(d),0)
d=((rv+bv)/2)-gv
if d < 0:
rv = min(rv + abs(d),65535)
bv = min(bv + abs(d),65535)
elif d > 0:
rv = max(rv - abs(d),0)
bv = max(bv - abs(d),0)
if mode == "gb":
d=b-r
if d < 0:
bv = min(b + abs(d),65535)
elif d > 0:
bv = max(b - abs(d),0)
d=gv-((rv+bv)/2)
if d < 0:
gv = min(gv + abs(d),65535)
elif d > 0:
gv = max(gv - abs(d),0)
sys.stdout.write("%s%s%s%s%s%s%s%s" %(chr(rv/256),chr(rv%256),chr(gv/256),chr(gv%256),chr(bv/256),chr(bv%256),o[6],o[7]))
n=n-1