-
Notifications
You must be signed in to change notification settings - Fork 181
/
hex2img.py
53 lines (45 loc) · 1.03 KB
/
hex2img.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
# Hex to Image Converter
# Copyright (c) 2018 MakotoKurauchi
# MIT License
from PIL import Image
from numpy import *
import sys
argvs = sys.argv
argc = len(argvs)
if (argc != 3):
print ('Usage: $ python %s file output-file' % argvs[0])
quit()
f = open(argvs[1])
txt = f.read()
f.close()
lines = txt.split('\n')
arr = []
for line in lines:
line = line.split('//')
data = line[0].split(',')
ar = []
for hex in data:
hex = hex.strip()
if hex.startswith('0x'):
ar.append(int(hex.replace('0x',''),16))
arr.append(ar)
#print (arr)
img = []
colmax = 32
rowmax = len(arr)//colmax
fontw = 6
fonth = 8
for colc in range(colmax):
for fontwc in range(len(arr[0])):
tmp=[]
for rowc in range(rowmax):
for i in range(fonth):
val = arr[colmax*(rowmax-1)-colmax*rowc+colc][fontwc]
v = 0 if (val>>(7-i))&1 else 255
if (fontwc == 5 and v) or (i==0 and v):
tmp.append([200,255,255])
else:
tmp.append([v,v,v])
img.append(tmp)
#print (img)
Image.fromarray(uint8(img)).rotate(90, expand=True).save(argvs[2]+'.bmp')