changed futex crate for mac compat (maybe) and image to bitmap assembly converter
This commit is contained in:
@@ -1,12 +1,27 @@
|
||||
use regex::Regex;
|
||||
use std::env::args;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let path = args().nth(1).expect("usage: 1 image file argument");
|
||||
let (data, name, width, height) = path_to_img(path.as_str());
|
||||
|
||||
println!("{name}:");
|
||||
println!(" D {width}");
|
||||
println!(" D {height}");
|
||||
for d in data {
|
||||
println!(" D 0x{d:08x}");
|
||||
}
|
||||
}
|
||||
fn remove_non_alphanumeric(input: &str) -> String {
|
||||
let re = Regex::new(r"[^a-zA-Z0-9_]+").unwrap();
|
||||
re.replace_all(input, "").to_string()
|
||||
}
|
||||
|
||||
fn path_to_img(path: &str) -> (Vec<u32>, String, u32, u32){
|
||||
fn path_to_img(path: &str) -> (Vec<u32>, String, u32, u32) {
|
||||
let img = match image::open(path) {
|
||||
Ok(img) => img.to_luma8(),
|
||||
Err(e) => panic!("failed to open image {path}: {e}"),
|
||||
}
|
||||
};
|
||||
|
||||
let width = img.width();
|
||||
let height = img.height();
|
||||
@@ -18,7 +33,7 @@ fn path_to_img(path: &str) -> (Vec<u32>, String, u32, u32){
|
||||
for x in 0..width {
|
||||
let pix = img.get_pixel(x, y)[0];
|
||||
if pix >= 127 {
|
||||
byte |= 1<<bit
|
||||
byte |= 1 << bit
|
||||
}
|
||||
bit += 1;
|
||||
if bit == 32 {
|
||||
@@ -31,6 +46,8 @@ fn path_to_img(path: &str) -> (Vec<u32>, String, u32, u32){
|
||||
if bit != 0 {
|
||||
bytes.push(byte);
|
||||
}
|
||||
let path = path.split
|
||||
(bytes,name,width,height)
|
||||
let path = path.split('/').next_back().unwrap();
|
||||
let split: Vec<_> = path.split('.').collect();
|
||||
let name = remove_non_alphanumeric(&split[0..split.len() - 1].join("_")).to_lowercase();
|
||||
(bytes, name, width, height)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user