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)]
|
#![allow(clippy::println_empty_string)]
|
||||||
use std::{
|
use std::{fs::File, io, path::PathBuf, u8};
|
||||||
fs::File,
|
|
||||||
ops::{Add, AddAssign},
|
|
||||||
};
|
|
||||||
|
|
||||||
extern crate png;
|
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_ROWS: usize = 13;
|
||||||
const MAX_CHARS: u8 = 0xFF;
|
const MAX_CHARS: u16 = 0x100; // Non inclusive, first char is 0x00
|
||||||
|
|
||||||
struct CharRowAddress {
|
fn to_bitmap(path: &str, max_chars: u16, max_rows: usize) -> Result<Vec<u8>, io::Error> {
|
||||||
row_address: u8,
|
let decoder = png::Decoder::new(File::open(path)?);
|
||||||
char_address: u8,
|
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 reorder_bitmap(bitmap: Vec<u8>) -> Vec<u8> {
|
||||||
fn new() -> Self {
|
unimplemented!()
|
||||||
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<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let decoder = png::Decoder::new(File::open("./cozette.png").unwrap());
|
let compressed = to_bitmap("./cozette.png", MAX_CHARS, MAX_ROWS)?;
|
||||||
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 {
|
for row in 0..MAX_ROWS {
|
||||||
address.inc_row();
|
for character in 0x00..MAX_CHARS {
|
||||||
for character in 0x00..0x7F {
|
print!("{:#04x}, {} ", character, row); // character as usize * row);
|
||||||
address.inc_char();
|
print!("{:#04x}: ", compressed[character as usize + (row * 0xFF)]);
|
||||||
print!("{} ", character as usize * row);
|
for i in 0..8 {
|
||||||
for i in 0..7 {
|
// character number * char width + pixel offset + row offset = pixel
|
||||||
if compressed[character as usize * 7 + i + (row * 0x7f)] == 255 {
|
if compressed[character as usize + (row * 0xFF)] & 0x80 >> i > 0 {
|
||||||
print!("█");
|
print!("█");
|
||||||
} else {
|
} else {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
|
|
Loading…
Reference in New Issue