-1 on unrecognized input and start bitmap converter
This commit is contained in:
36
bitmap_to_asm/src/main.rs
Normal file
36
bitmap_to_asm/src/main.rs
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user