From cebc8fcc5b7c640fe88365360812f54f26acbabe Mon Sep 17 00:00:00 2001 From: Mwa Date: Thu, 26 Mar 2026 13:18:51 +0100 Subject: [PATCH] bitmap to asm moved to the other repo --- bitmap_to_asm/Cargo.toml | 8 ---- bitmap_to_asm/src/main.rs | 82 --------------------------------------- 2 files changed, 90 deletions(-) delete mode 100644 bitmap_to_asm/Cargo.toml delete mode 100644 bitmap_to_asm/src/main.rs diff --git a/bitmap_to_asm/Cargo.toml b/bitmap_to_asm/Cargo.toml deleted file mode 100644 index 04866e4..0000000 --- a/bitmap_to_asm/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "bitmap_to_asm" -version = "0.1.0" -edition = "2024" - -[dependencies] -image = "0.25.10" -regex = "1.12.3" diff --git a/bitmap_to_asm/src/main.rs b/bitmap_to_asm/src/main.rs deleted file mode 100644 index 7a0cc8a..0000000 --- a/bitmap_to_asm/src/main.rs +++ /dev/null @@ -1,82 +0,0 @@ -use image::GenericImageView; -use regex::Regex; -use std::{borrow::Cow, env::args, process::exit}; - -fn main() { - let path = args().nth(1).expect("usage: file [--nosize]"); - let nosize = match args().nth(2) { - None => false, - Some(t) => { - if t == "--nosize" { - true - } else { - eprint!("usage: file [--nosize]"); - exit(1) - } - } - }; - let (data, name, width, height, color) = path_to_img(path.as_str()); - println!("{name}:"); - if !nosize { - println!(" D 0x{:08x}", color); - println!(" D {width}"); - println!(" D {height}"); - } - for d in data { - println!(" D 0x{d:08x}"); - } -} -fn remove_non_alphanumeric(input: &str) -> Cow<'_, str> { - let re = Regex::new(r"[^a-zA-Z0-9_]+").unwrap(); - re.replace_all(input, "") -} - -fn path_to_img(path: &str) -> (Vec, String, u32, u32, u32) { - let (base_img, img) = match image::open(path) { - Ok(img) => (img.clone(), 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; - let mut color = None; - - for y in 0..height { - for x in 0..width { - let pix = img.get_pixel(x, y)[0]; - if pix >= 5 { - byte |= 1 << bit; - if color == None { - color = Some(base_img.get_pixel(x, y)); - } - } - bit += 1; - if bit == 32 { - bytes.push(byte); - byte = 0; - bit = 0; - } - } - } - if bit != 0 { - bytes.push(byte); - } - let path = path.split('/').next_back().unwrap(); - let split: Vec<_> = path.split('.').collect(); - let name = format!( - "picture_{}", - remove_non_alphanumeric(&split[0..split.len() - 1].join("_")).to_lowercase() - ); - let color = color.map_or(0, |c| { - let mut r = 0; - r |= (c[0] as u32) << 24; - r |= (c[1] as u32) << 16; - r |= (c[2] as u32) << 8; - r - }); - (bytes, name, width, height, color) -}