-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalDisplay.py
executable file
·75 lines (66 loc) · 2.64 KB
/
LocalDisplay.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
#!/usr/bin/env python
import sys
from Transportation.Sockets.ServerSocketUDP import ServerSocketUDP
from Display.Pygame.pgCurtain import PygameCurtain
import socket
import Transportation.Protocol.SimpleProtocol as P
try:
import LocalConfig as Config
except:
import Config as Config
from Config import LocalDisplayConfig as LocalDisplayConfig
try:
from LocalConfig import InputServerConfig as InputConfig
except:
from Config import InputServerConfig as InputConfig
from ColorManager import convertColorByteToS
def testServer(host, port, height, width):
server = Config.ServerProtocolClass(host, port)
curtain = PygameCurtain(width,height)
lastServer=["",""]
while(1):
isUDP = Config.whichProtocol =="UDP"
if isUDP:
dataRaw = server.getDataHost()
data =dataRaw[0]
else:
data = server.getData()
dataRaw = [data, ['','']] #compatibility for tcp code
if data =="" and isUDP: #Necessary for games
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
newClientIP= dataRaw[1][0]
newClientPort = InputConfig.port
sock.sendto(lastServer[0], (newClientIP,newClientPort))
except:
pass
else:
lastServer=dataRaw[1]
colorArray=P.dataToColorArray(data)
if LocalDisplayConfig.linearColorProfileCorretion:
colorArray=map(lambda y: map(lambda x:convertColorByteToS(x),y),colorArray)
if LocalDisplayConfig.normalize:
brightest= max ([1]+[c for row in colorArray for color in row for c in color ])
def normalize((r,g,b)):
r = int(r*255./brightest)
g = int(g*255./brightest)
b = int(b*255./brightest)
return tuple([r,g,b])
colorArray=map(lambda y: map(lambda x: normalize(x) ,y), colorArray)
curtain.sendColorArray(colorArray)
def main(argv):
if len(argv)==4:
host, height,width,port=argv
testServer(host, int(port), int(height), int(width))
if len(argv)==3:
height,width,port=argv
host =''
testServer(host, int(port), int(height), int(width))
elif len(argv)==0:
host =''
testServer(host, LocalDisplayConfig.port, LocalDisplayConfig.height, LocalDisplayConfig.width)
else:
print "Usage Cli [host] <height> <width> <port> "
if __name__ == "__main__":
main(sys.argv[1:])