Initial commit, font address order works i think

This commit is contained in:
2024-02-12 01:54:14 -05:00
commit dfbfa2b732
10 changed files with 3960 additions and 0 deletions
View File
BIN
View File
Binary file not shown.
View File
+73
View File
@@ -0,0 +1,73 @@
#![allow(dead_code, clippy::println_empty_string)]
use std::{
fs::File,
ops::{Add, AddAssign},
};
extern crate png;
extern crate bdf;
const ADDRESS_SIZE: usize = 13;
const ROW_BITS: usize = 5;
const CHAR_BITS: usize = 8;
const MAX_ROWS: usize = 13;
const MAX_CHARS: u8 = 0xFF;
struct CharRowAddress {
row_address: u8,
char_address: u8,
}
impl CharRowAddress {
fn new() -> Self {
Self {
row_address: 0x00,
char_address: 0x00,
}
}
fn inc_row(&mut self) {
if self.row_address.add(0x01) > 0b0001_1111 {
} else {
self.row_address.add_assign(0x01);
}
}
fn inc_char(&mut self) {
if self.char_address.add(0x01) > 0b0111_1111 {
} else {
self.char_address.add_assign(0x01);
}
}
}
impl std::fmt::Display for CharRowAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:05b}{:07b}", self.row_address, self.char_address)
}
}
fn main() -> std::io::Result<()> {
let decoder = png::Decoder::new(File::open("./cozette.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
let bytes = &buf[..info.buffer_size()];
let compressed: Vec<u8> = bytes.iter().step_by(4).cloned().collect();
let mut address = CharRowAddress::new();
for row in 0..MAX_ROWS {
address.inc_row();
for character in 0x00..0x7F {
address.inc_char();
print!("{} ", character as usize * row);
for i in 0..7 {
if compressed[character as usize * 7 + i + (row * 0x7f)] == 255 {
print!("");
} else {
print!(" ");
}
}
println!("");
}
}
Ok(())
}