-1 on unrecognized input and start bitmap converter

This commit is contained in:
Mwa
2026-03-17 13:22:33 +01:00
parent 30a7d1c5e4
commit 20f7c289ed
5 changed files with 798 additions and 23 deletions

8
bitmap_to_asm/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "bitmap_to_asm"
version = "0.1.0"
edition = "2024"
[dependencies]
image = "0.25.10"
regex = "1.12.3"

36
bitmap_to_asm/src/main.rs Normal file
View File

@@ -0,0 +1,36 @@
fn main() {
println!("Hello, world!");
}
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();
let mut bytes = Vec::new();
let mut bit = 0;
let mut byte = 0;
for y in 0..height {
for x in 0..width {
let pix = img.get_pixel(x, y)[0];
if pix >= 127 {
byte |= 1<<bit
}
bit += 1;
if bit == 32 {
bytes.push(byte);
byte = 0;
bit = 0;
}
}
}
if bit != 0 {
bytes.push(byte);
}
let path = path.split
(bytes,name,width,height)
}