-1 on unrecognized input and start bitmap converter
This commit is contained in:
754
Cargo.lock
generated
754
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
members = ["simu","asm"]
|
members = ["simu","asm","bitmap_to_asm"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
debug = "line-tables-only"
|
debug = "line-tables-only"
|
||||||
|
|||||||
8
bitmap_to_asm/Cargo.toml
Normal file
8
bitmap_to_asm/Cargo.toml
Normal 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
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)
|
||||||
|
}
|
||||||
@@ -93,20 +93,21 @@ impl<'a> ApplicationHandler for App<'a> {
|
|||||||
print!("Keyboard event: ");
|
print!("Keyboard event: ");
|
||||||
#[cfg(feature = "rich_keyboard")]
|
#[cfg(feature = "rich_keyboard")]
|
||||||
{
|
{
|
||||||
let kb0 = key_event
|
let kb0 = key_event.text_with_all_modifiers().map_or(u32::MAX, |s| {
|
||||||
.text_with_all_modifiers()
|
s.as_bytes()
|
||||||
.unwrap_or("")
|
.into_iter()
|
||||||
.as_bytes()
|
.fold(0, |a, e| a << 8 | (*e as u32))
|
||||||
.into_iter()
|
});
|
||||||
.fold(0, |a, e| a << 8 | (*e as u32));
|
|
||||||
SHARED.keyboard[0].store(kb0, Relaxed);
|
SHARED.keyboard[0].store(kb0, Relaxed);
|
||||||
let kb1 = key_event
|
let kb1 = key_event
|
||||||
.key_without_modifiers()
|
.key_without_modifiers()
|
||||||
.to_text()
|
.to_text()
|
||||||
.unwrap_or("")
|
.map_or(u32::MAX, |s| {
|
||||||
.as_bytes()
|
s.as_bytes()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.fold(0, |a, e| a << 8 | (*e as u32));
|
.fold(0, |a, e| a << 8 | (*e as u32))
|
||||||
|
});
|
||||||
|
|
||||||
SHARED.keyboard[1].store(kb1, Relaxed);
|
SHARED.keyboard[1].store(kb1, Relaxed);
|
||||||
let kb2 =
|
let kb2 =
|
||||||
key_event.state.is_pressed() as u32 | ((key_event.repeat as u32) << 1);
|
key_event.state.is_pressed() as u32 | ((key_event.repeat as u32) << 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user