3 from __future__
import division
, print_function
8 image
= Image
.open(sys
.argv
[1])
9 width
, height
= image
.size
11 image_fmt
= image
.format
13 def writeSize(f
, width
, height
):
15 f
.write("%d,%d,%d,%d,\n" % (width
% 256, width
// 256, height
% 256, height
// 256))
17 f
.write("%d,%d,\n" % (width
, height
))
20 with
open(sys
.argv
[2], "w") as f
:
21 lcdwidth
= int(sys
.argv
[3])
26 for s
in ("03x05", "04x06", "05x07", "08x10", "10x14", "22x38"):
34 rows
= int(sys
.argv
[5])
35 image
= image
.convert(mode
='1')
36 writeSize(f
, width
, height
// rows
)
37 for y
in range(0, height
, 8):
38 for x
in range(width
):
42 if image_fmt
== 'XBM':
43 if image
.getpixel((x
, y
+ z
)) > 0:
46 if image
.getpixel((x
, y
+ z
)) == 0:
48 f
.write("0x%02x," % value
)
50 elif what
== "4/4/4/4":
51 constant
= sys
.argv
[2].upper()[:-4]
53 for y
in range(height
):
54 for x
in range(width
):
55 pixel
= image
.getpixel((x
, y
))
56 val
= ((pixel
[3] // 16) << 12) + ((pixel
[0] // 16) << 8) + ((pixel
[1] // 16) << 4) + ((pixel
[2] // 16) << 0)
57 values
.append(str(val
))
58 f
.write("const uint16_t __%s[] __ALIGNED = { %s };\n" % (constant
, ",".join(values
)))
59 f
.write("const Bitmap %s(BMP_ARGB4444, %d, %d, __%s);\n" % (constant
, width
, height
, constant
))
60 elif what
== "4/4/4/4-R":
61 constant
= sys
.argv
[2].upper()[:-4]
63 for y
in range(height
):
64 for x
in range(width
):
65 pixel
= image
.getpixel((width
-x
-1, height
-y
-1))
66 val
= ((pixel
[3] // 16) << 12) + ((pixel
[0] // 16) << 8) + ((pixel
[1] // 16) << 4) + ((pixel
[2] // 16) << 0)
67 values
.append(str(val
))
68 f
.write("const uint16_t __%s[] __ALIGNED = { %s };\n" % (constant
, ",".join(values
)))
69 f
.write("const Bitmap %s(BMP_ARGB4444, %d, %d, __%s);\n" % (constant
, width
, height
, constant
))
71 constant
= sys
.argv
[2].upper()[:-4]
73 for y
in range(height
):
74 for x
in range(width
):
75 pixel
= image
.getpixel((x
, y
))
76 val
= ((pixel
[0] >> 3) << 11) + ((pixel
[1] >> 2) << 5) + ((pixel
[2] >> 3) << 0)
77 values
.append(str(val
))
78 f
.write("const uint16_t __%s[] __ALIGNED = { %s };\n" % (constant
, ",".join(values
)))
79 f
.write("const Bitmap %s(BMP_RGB565, %d, %d, __%s);\n" % (constant
, width
, height
, constant
))
80 elif what
== "5/6/5-R":
81 constant
= sys
.argv
[2].upper()[:-4]
83 for y
in range(height
):
84 for x
in range(width
):
85 pixel
= image
.getpixel((width
-x
-1, height
-y
-1))
86 val
= ((pixel
[0] >> 3) << 11) + ((pixel
[1] >> 2) << 5) + ((pixel
[2] >> 3) << 0)
87 values
.append(str(val
))
88 f
.write("const uint16_t __%s[] __ALIGNED = { %s };\n" % (constant
, ",".join(values
)))
89 f
.write("const Bitmap %s(BMP_RGB565, %d, %d, __%s);\n" % (constant
, width
, height
, constant
))
90 # elif what == "5/6/5/8":
92 # writeSize(f, width, height)
93 # for y in range(height):
94 # for x in range(width):
95 # pixel = image.pixel(x, y)
96 # val = ((Qt.qRed(pixel) >> 4) << 12) + ((Qt.qGreen(pixel) >> 4) << 7) + ((Qt.qBlue(pixel) >> 4) << 1)
97 # f.write("%d,%d,%d," % (val % 256, val // 256, Qt.qAlpha(pixel)))
101 writeSize(f
, width
, height
)
102 image
= image
.convert(mode
='L')
103 for y
in range(0, height
, 2):
104 for x
in range(width
):
106 gray1
= image
.getpixel((x
, y
))
108 gray2
= image
.getpixel((x
, y
+ 1))
112 if (gray1
& (1 << (4 + i
))):
114 if (gray2
& (1 << (4 + i
))):
115 value
-= 1 << (4 + i
)
116 f
.write("0x%02x," % value
)
118 elif what
== "8bits":
120 writeSize(f
, width
, height
)
121 image
= image
.convert(mode
='L')
122 for y
in range(height
):
123 for x
in range(width
):
124 value
= image
.getpixel((x
, y
))
125 value
= 0x0f - (value
>> 4)
126 f
.write("0x%02x," % value
)
128 elif what
== "03x05":
129 image
= image
.convert(mode
='L')
130 for y
in range(0, height
, 5):
131 for x
in range(width
):
134 if image
.getpixel((x
, y
+ z
)) == 0:
136 f
.write("0x%02x," % value
)
138 elif what
== "04x06":
139 image
= image
.convert(mode
='L')
140 for y
in range(0, height
, 7):
141 for x
in range(width
):
144 if image
.getpixel((x
, y
+ z
)) == 0:
148 f
.write("0x%02x," % value
)
150 elif what
== "05x07":
151 image
= image
.convert(mode
='L')
152 for y
in range(0, height
, 8):
153 for x
in range(width
):
156 if image
.getpixel((x
, y
+ z
)) == 0:
158 f
.write("0x%02x," % value
)
160 elif what
== "08x10":
161 image
= image
.convert(mode
='L')
162 for y
in range(0, height
, 12):
163 for x
in range(width
):
165 for l
in range(0, 12, 8):
169 if image
.getpixel((x
, y
+ l
+ z
)) == 0:
175 f
.write("0x%02x," % value
)
176 #print ("0x%02x (%d,%d,%d)" % (value,x,y,l))
178 elif what
== "10x14":
179 image
= image
.convert(mode
='L')
180 for y
in range(0, height
, 16):
181 for x
in range(width
):
182 for l
in range(0, 16, 8):
185 if image
.getpixel((x
, y
+ l
+ z
)) == 0:
187 f
.write("0x%02x," % value
)
189 elif what
== "22x38":
190 image
= image
.convert(mode
='L')
191 for y
in range(0, height
, 40):
192 for x
in range(width
):
193 for l
in range(0, 40, 8):
196 if image
.getpixel((x
, y
+ l
+ z
)) == 0:
198 f
.write("0x%02x," % value
)
201 print("wrong argument", sys
.argv
[4])