Initial commit, font address order works i think
This commit is contained in:
Binary file not shown.
+73
@@ -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(())
|
||||
}
|
||||
Reference in New Issue
Block a user