esp32 firmware for a toaster reflow oven WIP!!!!!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
reflower/aseprite_c/font/ico2h.rs

56 lines
1.6 KiB

use std::fs;
use std::process::Command;
use std::string::ToString;
fn main() {
for entry in fs::read_dir(".").unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if !path.display().to_string().ends_with(".ico") {
continue;
}
let name = path.file_stem().unwrap().to_str().unwrap();
Command::new("/bin/convert").arg(&path).arg("./tmp.xbm").output().unwrap();
let content = fs::read_to_string("./tmp.xbm").unwrap();
let a = content.find('{').unwrap() + 1;
let b = content.find('}').unwrap();
let bytes = &content[a..b].trim();
let bytes = bytes.split(",")
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.map(|s| u8::from_str_radix(&s[2..], 16).unwrap())
.collect::<Vec<_>>();
assert!(bytes.len() == 8);
let mut columns : [u8; 5] = [0,0,0,0,0];
for (n, r) in bytes.iter().enumerate() {
for i in 0..5 {
if 0 != *r & (1<<i) {
columns[i] |= 1 << n;
}
}
}
fn testchar(c : char) -> bool {
c.is_alphanumeric() || c=='_'
}
let mut name = name.replace(|c:char|!testchar(c), "_");
if !name.starts_with(testchar) {
name = format!("_{}", name);
}
println!("const uint8_t {}[5] = {{ {} }};", name, columns.iter().map(|c| format!("{:#04x}", !c)).collect::<Vec<_>>().join(", "));
}
let _ = fs::remove_file("./tmp.xbm");
}