-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_tests.py
More file actions
executable file
·99 lines (79 loc) · 2.97 KB
/
gen_tests.py
File metadata and controls
executable file
·99 lines (79 loc) · 2.97 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python3
import random
### Run-length encoding test
# Pure black images
open("test/raw/rgba/black.rgba", "wb").write(b"\0\0\0\xFF" * 240000)
open("test/raw/rgb/black.rgb", "wb").write(b"\0\0\0" * 240000)
# Pure red images
open("test/raw/rgba/red.rgba", "wb").write(b"\xFF\0\0\xFF" * 240000)
open("test/raw/rgb/red.rgb", "wb").write(b"\xFF\0\0" * 240000)
### Seen pixel encoding test
# Exactly 64 repeating colors
data_rgba = []
data_rgb = []
for y in range(600):
for x in range(400):
# Create 64 unique colors using a simple hash
color_idx = ((x // 8) + (y // 8)) % 64
r = (color_idx * 4) % 256
g = (color_idx * 7) % 256
b = (color_idx * 11) % 256
data_rgba.extend([r, g, b, 255])
data_rgb.extend([r, g, b])
open("test/raw/rgba/seen64.rgba", "wb").write(bytes(data_rgba))
open("test/raw/rgb/seen64.rgb", "wb").write(bytes(data_rgb))
# 16 repeating colors
data_rgba = []
data_rgb = []
colors = [(255,0,0), (0,255,0), (0,0,255), (255,255,0), (255,0,255), (0,255,255),
(128,0,0), (0,128,0), (0,0,128), (128,128,0), (128,0,128), (0,128,128),
(255,128,0), (255,0,128), (128,255,0), (0,255,128)]
for y in range(600):
for x in range(400):
color_idx = ((x // 25) + (y // 37)) % 16
r, g, b = colors[color_idx]
data_rgba.extend([r, g, b, 255])
data_rgb.extend([r, g, b])
open("test/raw/rgba/seen16.rgba", "wb").write(bytes(data_rgba))
open("test/raw/rgb/seen16.rgb", "wb").write(bytes(data_rgb))
### Diff encoding test
# Random
data_rgba = []
data_rgb = []
# Base color: medium gray
base_r, base_g, base_b = 128, 128, 128
for i in range(240000):
# Add small random variations within diff range (±2)
r = max(0, min(255, base_r + random.randint(-2, 2)))
g = max(0, min(255, base_g + random.randint(-2, 2)))
b = max(0, min(255, base_b + random.randint(-2, 2)))
data_rgba.extend([r, g, b, 255])
data_rgb.extend([r, g, b])
open("test/raw/rgba/diff.rgba", "wb").write(bytes(data_rgba))
open("test/raw/rgb/diff.rgb", "wb").write(bytes(data_rgb))
# Gradient
data_rgba = []
data_rgb = []
for y in range(600):
for x in range(400):
# Slow gradient with small steps
r = (x * 255 // 400)
g = (y * 255 // 600)
b = 128
data_rgba.extend([r, g, b, 255])
data_rgb.extend([r, g, b])
open("test/raw/rgba/gradient_diff.rgba", "wb").write(bytes(data_rgba))
open("test/raw/rgb/gradient_diff.rgb", "wb").write(bytes(data_rgb))
### Luma encoding test
data_rgba = []
data_rgb = []
base_r, base_g, base_b = 200, 128, 200
for i in range(240000):
# Green varies much more than red/blue
r = max(0, min(255, base_r + random.randint(-8, 8)))
g = max(0, min(255, base_g + random.randint(-32, 32)))
b = max(0, min(255, base_b + random.randint(-8, 8)))
data_rgba.extend([r, g, b, 255])
data_rgb.extend([r, g, b])
open("test/raw/rgba/luma.rgba", "wb").write(bytes(data_rgba))
open("test/raw/rgb/luma.rgb", "wb").write(bytes(data_rgb))