annnd we have our character rom!!!

This commit is contained in:
august kline 2024-02-13 18:07:58 -05:00
parent 401c142c75
commit 9bacd1d28f
3 changed files with 36 additions and 18 deletions

BIN
cozette.bin Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -1,5 +1,10 @@
#![allow(clippy::println_empty_string)]
use std::{fs::File, io, path::PathBuf, u8};
use std::{
fs::File,
io::{self, Write},
path::PathBuf,
u8,
};
extern crate png;
@ -26,26 +31,39 @@ fn to_bitmap(path: &str, max_chars: u16, max_rows: usize) -> Result<Vec<u8>, io:
Ok(finalbuf)
}
fn reorder_bitmap(bitmap: Vec<u8>) -> Vec<u8> {
unimplemented!()
fn reorder_bitmap(bitmap: &[u8]) -> Vec<u8> {
let mut reordered: Vec<u8> = Vec::new();
for row in 0..MAX_ROWS {
for character in 0x00..MAX_CHARS {
let mut byte = 0u8;
for i in 0..8 {
// character number + row offset & bitmask = pixel
if bitmap[character as usize + (row * 0xFF)] & 0x80 >> i > 0 {
byte |= 0x80 >> i;
}
}
reordered.push(byte);
}
}
reordered
}
fn main() -> std::io::Result<()> {
let compressed = to_bitmap("./cozette.png", MAX_CHARS, MAX_ROWS)?;
for row in 0..MAX_ROWS {
for character in 0x00..MAX_CHARS {
print!("{:#04x}, {} ", character, row); // character as usize * row);
print!("{:#04x}: ", compressed[character as usize + (row * 0xFF)]);
for i in 0..8 {
// character number * char width + pixel offset + row offset = pixel
if compressed[character as usize + (row * 0xFF)] & 0x80 >> i > 0 {
print!("");
} else {
print!(" ");
}
}
println!("");
}
}
let reordered = reorder_bitmap(&compressed);
let mut outfile = File::create("./cozette.bin")?;
outfile.set_len(0xFFFF)?;
outfile.write_all(&reordered)?;
//for byte in reordered.iter() {
// for i in 0..8 {
// // character number + row offset & bitmask = pixel
// if byte & 0x80 >> i > 0 {
// print!("█");
// } else {
// print!(" ");
// }
// }
// println!("");
//}
Ok(())
}