-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgaconvb.py
More file actions
64 lines (48 loc) · 1.05 KB
/
cgaconvb.py
File metadata and controls
64 lines (48 loc) · 1.05 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
from PIL import Image
import sys
input=Image.open(sys.argv[1])
pixels=input.load()
out_even=[]
out_odd=[]
for y in range(200):
for x in range(0,200,4):
out = (pixels[x+0,y] & 0x03) << 6
out|= (pixels[x+1,y] & 0x03) << 4
out|= (pixels[x+2,y] & 0x03) << 2
out|= (pixels[x+3,y] & 0x03) << 0
if (y%2):
out_odd.append(out)
else:
out_even.append(out)
def hexify_rle_line(data):
totc=0
out=""
curc=None;
numc=0;
for y in range(100):
for x in range(50):
c = data[y*50+x]
if c != curc:
if curc is not None:
out+="0x{:02X},".format(curc)
out+="0x{:02X},".format(numc)
totc+=numc
curc = c
numc = 0
numc+=1
out+="0x{:02X},".format(curc)
out+="0x{:02X},".format(numc)
totc+=numc
return out[:-1]
def hexify_straight(data):
out=""
for b in out_odd:
out+="0x{:02X},".format(b)
return out[:-1]
print ('#include "bmpdata.h"\n')
print("const unsigned char bmp_even[] = {")
print(hexify_rle_line(out_even))
print("};\n");
print("const unsigned char bmp_odd[] = {")
print(hexify_rle_line(out_odd))
print("};\n");