-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.py
41 lines (34 loc) · 1.13 KB
/
send.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
import socket, struct, time, random
from PIL import Image, ImageOps
from io import BytesIO
TCP_IP = '192.168.0.214'
TCP_PORT = 8319
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
def clearScreen(color, apply=True):
header = struct.pack('<BBHHHH', 1, color, 0, 0, 1872, 1404)
s.sendall(header)
if apply:
header = struct.pack('<BBHHHH', 4, 0, 0, 0, 1872, 1404)
s.sendall(header)
def drawImage(posx, posy, origImage):
grayImage = ImageOps.grayscale(origImage)
width, height = grayImage.size
pixels = grayImage.load()
image = bytearray()
for y in range(height):
for x in range(0, width, 2):
byt = (pixels[x,y] // 17) + ((pixels[x+1,y] // 17) << 4)
image.append(byt)
header = struct.pack('<BBHHHH', 2, 15, posx, posy, width, height)
s.sendall(header)
s.sendall(image)
header = struct.pack('<BBHHHH', 4, 0, posx, posy, width, height)
s.sendall(header)
clearScreen(15)
time.sleep(1)
origImage = Image.open('family.jpeg')
origImage = origImage.resize((1872, 1404))
drawImage(0, 0, origImage)
time.sleep(1)
s.close()