Added scripts to generate color bitmaps
This commit is contained in:
parent
ea380afff8
commit
2789acd044
1409
src/logo.rs
1409
src/logo.rs
File diff suppressed because it is too large
Load Diff
|
@ -145,7 +145,7 @@ fn run(mut scs: scs::Instance, mut p: hcl::platform::Instance) {
|
||||||
systick::delay_ms(1000);
|
systick::delay_ms(1000);
|
||||||
st7735io.draw_mono_bitmap(11, 4, &logo::LOGO_BW, st7735::COLOR_WHITE, st7735::COLOR_BLACK);
|
st7735io.draw_mono_bitmap(11, 4, &logo::LOGO_BW, st7735::COLOR_WHITE, st7735::COLOR_BLACK);
|
||||||
systick::delay_ms(1000);
|
systick::delay_ms(1000);
|
||||||
st7735io.draw_color_bitmap(11, 4, &logo::LOGO);
|
st7735io.draw_color_bitmap(11, 4, &logo::LOGO_COLOR);
|
||||||
systick::delay_ms(5000);
|
systick::delay_ms(5000);
|
||||||
}
|
}
|
||||||
let (st7735, mut spi, mut gpio) = st7735io.done();
|
let (st7735, mut spi, mut gpio) = st7735io.done();
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print("Usage: %s <image> <output file>" % sys.argv[0])
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
img = Image.open(sys.argv[1]).convert('RGB')
|
||||||
|
|
||||||
|
width, height = img.size
|
||||||
|
|
||||||
|
print("Size: %d x %d = %d bytes" % (width, height, width * height / 8))
|
||||||
|
|
||||||
|
file_name = os.path.basename(sys.argv[2])
|
||||||
|
variable_name = '_'.join(file_name.split('.')[:-1])
|
||||||
|
variable_name = variable_name.upper()
|
||||||
|
|
||||||
|
output_file = open(sys.argv[2], 'w')
|
||||||
|
output_file.write("use st7735::bitmaps::MonoBitmap;\n\n")
|
||||||
|
output_file.write("const %s_PX: [u16; %d] = [\n" % (variable_name, width * height))
|
||||||
|
|
||||||
|
bit_pos = 0
|
||||||
|
bits = 0
|
||||||
|
|
||||||
|
for y in range(0, height):
|
||||||
|
output_file.write("\t")
|
||||||
|
for x in range(0, width):
|
||||||
|
r, g, b = img.getpixel((x, y))
|
||||||
|
|
||||||
|
if (r + b + g) / 3 > 127:
|
||||||
|
bits = bits | (1 << (bit_pos % 8))
|
||||||
|
|
||||||
|
bit_pos += 1
|
||||||
|
|
||||||
|
if bit_pos % 8 == 0:
|
||||||
|
output_file.write("0x%x, " % bits)
|
||||||
|
bits = 0
|
||||||
|
|
||||||
|
output_file.write("\n")
|
||||||
|
|
||||||
|
output_file.write("];\n\n")
|
||||||
|
output_file.write("pub const %s: MonoBitmap = MonoBitmap {\n" % variable_name)
|
||||||
|
output_file.write("\twidth: %d,\n" % width)
|
||||||
|
output_file.write("\theight: %d,\n" % height)
|
||||||
|
output_file.write("pixels: &%s_PX,\n" % variable_name)
|
||||||
|
output_file.write("};\n")
|
||||||
|
output_file.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print("Usage: %s <image> <output file>" % sys.argv[0])
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
img = Image.open(sys.argv[1]).convert('RGB')
|
||||||
|
|
||||||
|
width, height = img.size
|
||||||
|
|
||||||
|
print("Size: %d x %d = %d bytes" % (width, height, width * height * 2))
|
||||||
|
|
||||||
|
file_name = os.path.basename(sys.argv[2])
|
||||||
|
variable_name = '_'.join(file_name.split('.')[:-1])
|
||||||
|
variable_name = variable_name.upper()
|
||||||
|
|
||||||
|
output_file = open(sys.argv[2], 'w')
|
||||||
|
output_file.write("use st7735::bitmaps::ColorBitmap;\n\n")
|
||||||
|
output_file.write("const %s_PX: [u16; %d] = [\n" % (variable_name, width * height))
|
||||||
|
|
||||||
|
|
||||||
|
for y in range(0, height):
|
||||||
|
output_file.write("\t")
|
||||||
|
|
||||||
|
for x in range(0, width):
|
||||||
|
r, g, b = img.getpixel((x, y))
|
||||||
|
|
||||||
|
packed_color = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)
|
||||||
|
output_file.write("0x%x, " % packed_color)
|
||||||
|
|
||||||
|
output_file.write("\n")
|
||||||
|
|
||||||
|
output_file.write("];\n\n")
|
||||||
|
output_file.write("pub const %s: ColorBitmap = ColorBitmap {\n" % variable_name)
|
||||||
|
output_file.write("\twidth: %d,\n" % width)
|
||||||
|
output_file.write("\theight: %d,\n" % height)
|
||||||
|
output_file.write("pixels: &%s_PX,\n" % variable_name)
|
||||||
|
output_file.write("};\n")
|
||||||
|
output_file.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Loading…
Reference in New Issue