-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkutils.py
54 lines (43 loc) · 1.49 KB
/
mkutils.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
'''
Mortal Kombat GRA files parser
Copyright (c) 2018 ReWolf
http://blog.rewolf.pl/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
MULT = 255.0/31
def convert15to24bitRGB(r, g, b):
return int(round(r*MULT)), int(round(g*MULT)), int(round(b*MULT))
def getCompressedData(br):
# HACK: skip unknown number of padding 0 bytes
b = 0
while b == 0:
b = br.getBits(8)
width = b | (br.getBits(8) << 8)
height = br.getWord()
c = br.getBits(8)
blocks = []
while not br.isEnd():
block_size = br.getBits(8)
if block_size == 0:
break
block = br.getBytes(block_size)
blocks.append(block)
return width, height, c, b''.join(blocks)
def getPalette(br):
palette = []
record_num = br.getWord()
for _ in range(0, record_num):
record_size = br.getWord()
for _ in range(0, record_size):
c = br.getWord()
palette.append(convert15to24bitRGB((c >> 10) & 0x1F, (c >> 5) & 0x1F, c & 0x1F))
return palette