-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathheadless_test.py
37 lines (28 loc) · 1.09 KB
/
headless_test.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
import base64
import subprocess
import time
from PIL import Image
if __name__ == "__main__":
width = 900
height = 900
max_iter = 1000
start = time.time()
with open("models/step-pyramid.rkt", "rb") as infile:
model_source = infile.read()
proc = subprocess.run(f"./tangerine.exe --racket --headless {width} {height} --iterations {max_iter}", capture_output=True, input=model_source)
img_header = b"BEGIN RAW IMAGE"
if proc.stdout.count(img_header) == 0:
print(proc.stdout.decode("utf-8"))
assert(proc.stdout.count(img_header) == 1)
info_end = proc.stdout.index(img_header)
img_start = info_end + len(img_header)
print(proc.stdout[:info_end].decode("utf-8"))
image_bytes = base64.b64decode(proc.stdout[img_start:], validate=True)
raw_mode = "RGB"
stride = 0
orientation = -1
fnord = Image.frombytes("RGB", (width, height), image_bytes, "raw", raw_mode, stride, orientation)
fnord.save("test_render.png")
delta = time.time() - start
delta = round(delta * 100) / 100
print("elapsed time: {} seconds", delta)