-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin2img.in
executable file
·37 lines (31 loc) · 1.06 KB
/
bin2img.in
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
#!/usr/bin/python
'''
Convert binary framebuffer to an image
'''
from __future__ import print_function, division, unicode_literals
import argparse,struct
from binascii import b2a_hex
def parse_arguments():
parser = argparse.ArgumentParser(description='Convert binary framebuffer to an image.')
parser.add_argument('input', metavar='INFILE', type=str,
help='Texture raw file')
parser.add_argument('output', metavar='OUTFILE', type=str,
help='Output image')
parser.add_argument('-w', dest='img_width', type=int,
help='Width of image to export')
return parser.parse_args()
def main():
args = parse_arguments()
with open(args.input, 'rb') as f:
data = f.read()
if args.img_width is None:
print('Specify width of image with -w')
exit(1)
width = args.img_width
height = len(data)//(width*4)
from PIL import Image
img = Image.frombuffer("RGBX", (width, height), data, "raw", "RGBX", 0, 1)
img = img.convert("RGB")
img.save(args.output)
if __name__ == '__main__':
main()