good god that took way to long but this kinda works
This commit is contained in:
parent
dfbfa2b732
commit
401c142c75
793
Cozette.sfd
793
Cozette.sfd
File diff suppressed because it is too large
Load Diff
BIN
cozette.png
BIN
cozette.png
Binary file not shown.
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 5.2 KiB |
82
src/main.rs
82
src/main.rs
|
@ -1,66 +1,44 @@
|
|||
#![allow(dead_code, clippy::println_empty_string)]
|
||||
use std::{
|
||||
fs::File,
|
||||
ops::{Add, AddAssign},
|
||||
};
|
||||
#![allow(clippy::println_empty_string)]
|
||||
use std::{fs::File, io, path::PathBuf, u8};
|
||||
|
||||
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;
|
||||
const MAX_CHARS: u16 = 0x100; // Non inclusive, first char is 0x00
|
||||
|
||||
struct CharRowAddress {
|
||||
row_address: u8,
|
||||
char_address: u8,
|
||||
fn to_bitmap(path: &str, max_chars: u16, max_rows: usize) -> Result<Vec<u8>, io::Error> {
|
||||
let decoder = png::Decoder::new(File::open(path)?);
|
||||
let mut reader = decoder.read_info()?;
|
||||
let mut buf = vec![0; reader.output_buffer_size()];
|
||||
let info = reader.next_frame(&mut buf)?;
|
||||
let bytes = &buf[..info.buffer_size()];
|
||||
let compressed: Vec<u8> = bytes.iter().step_by(4).cloned().collect(); // We're not using color, so we skip duplicate color components
|
||||
let mut finalbuf = Vec::new();
|
||||
for (i, _bit) in compressed.iter().step_by(8).enumerate() {
|
||||
let mut byte = 0u8;
|
||||
for j in (0..8).rev() {
|
||||
if compressed[i * 8 + j] == 255 {
|
||||
byte |= 0x80 >> j;
|
||||
}
|
||||
}
|
||||
finalbuf.push(byte);
|
||||
}
|
||||
Ok(finalbuf)
|
||||
}
|
||||
|
||||
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 reorder_bitmap(bitmap: Vec<u8>) -> Vec<u8> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
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();
|
||||
let compressed = to_bitmap("./cozette.png", MAX_CHARS, MAX_ROWS)?;
|
||||
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 {
|
||||
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!(" ");
|
||||
|
|
Loading…
Reference in New Issue