forked from jtauber/ultima4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathega.py
69 lines (61 loc) · 1.98 KB
/
ega.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
from png import write_png
EGA2RGB = [
(0x00, 0x00, 0x00),
(0x00, 0x00, 0xAA),
(0x00, 0xAA, 0x00),
(0x00, 0xAA, 0xAA),
(0xAA, 0x00, 0x00),
(0xAA, 0x00, 0xAA),
(0xAA, 0x55, 0x00),
(0xAA, 0xAA, 0xAA),
(0x55, 0x55, 0x55),
(0x55, 0x55, 0xFF),
(0x55, 0xFF, 0x55),
(0x55, 0xFF, 0xFF),
(0xFF, 0x55, 0x55),
(0xFF, 0x55, 0xFF),
(0xFF, 0xFF, 0x55),
(0xFF, 0xFF, 0xFF),
]
def rle(filename_in, filename_out, w, h):
pixels = []
bytes = open(filename_in, 'rb').read()
state = 0
for d in bytes:
if state == 0:
if d == 0x02:
state = 1
else:
a, b = divmod(d, 16)
pixels.append(EGA2RGB[a])
pixels.append(EGA2RGB[b])
elif state == 1:
run = d
state = 2
elif state == 2:
for i in range(run):
a, b = divmod(d, 16)
pixels.append(EGA2RGB[a])
pixels.append(EGA2RGB[b])
state = 0
write_png(filename_out, w, h, pixels)
rle("ULT/START.EGA", "start.png", 320, 200)
rle("ULT/KEY7.EGA", "key7.png", 320, 200)
rle("ULT/RUNE_0.EGA", "rune_0.png", 320, 200)
rle("ULT/RUNE_1.EGA", "rune_1.png", 320, 200)
rle("ULT/RUNE_2.EGA", "rune_2.png", 320, 200)
rle("ULT/RUNE_3.EGA", "rune_3.png", 320, 200)
rle("ULT/RUNE_4.EGA", "rune_4.png", 320, 200)
rle("ULT/RUNE_5.EGA", "rune_5.png", 320, 200)
rle("ULT/STONCRCL.EGA", "stonecircle.png", 320, 200)
rle("ULT/HONESTY.EGA", "honesty.png", 320, 200)
rle("ULT/COMPASSN.EGA", "compassion.png", 320, 200)
rle("ULT/VALOR.EGA", "valor.png", 320, 200)
rle("ULT/JUSTICE.EGA", "justice.png", 320, 200)
rle("ULT/SACRIFIC.EGA", "sacrifice.png", 320, 200)
rle("ULT/HONOR.EGA", "honor.png", 320, 200)
rle("ULT/SPIRIT.EGA", "spirit.png", 320, 200)
rle("ULT/HUMILITY.EGA", "humility.png", 320, 200)
rle("ULT/TRUTH.EGA", "truth.png", 320, 200)
rle("ULT/LOVE.EGA", "love.png", 320, 200)
rle("ULT/COURAGE.EGA", "courage.png", 320, 200)