Compare commits

...

1 commit

Author SHA1 Message Date
Elise Amber Katze 00a185c8fd
feat: logs to a scene 2024-07-09 22:09:58 +02:00
4 changed files with 71 additions and 29 deletions

30
Cargo.lock generated
View file

@ -199,6 +199,15 @@ dependencies = [
"objc2-encode",
]
[[package]]
name = "bmp"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69985ff4f58085ac696454692d0b646a66ad1f9cc9be294c91dc51bb5df511ae"
dependencies = [
"byteorder",
]
[[package]]
name = "bumpalo"
version = "3.16.0"
@ -513,6 +522,12 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "font8x8"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
[[package]]
name = "foreign-types"
version = "0.3.2"
@ -651,18 +666,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "image"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11"
dependencies = [
"bytemuck",
"byteorder",
"num-traits",
"png",
]
[[package]]
name = "indexmap"
version = "1.9.3"
@ -1373,9 +1376,10 @@ checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
name = "rsrt"
version = "0.1.0"
dependencies = [
"bmp",
"criterion",
"fastrand",
"image",
"font8x8",
"paste",
"rayon",
"tracing",

View file

@ -8,8 +8,9 @@ version = "0.1.0"
edition = "2021"
[dependencies]
bmp = "0.5.0"
fastrand = "2.1.0"
image = { version = "0.25.1", default-features = false, features = ["png"] }
font8x8 = "0.3.1"
paste = "1.0.15"
rayon = "1.10.0"
tracing = "0.1.40"

View file

@ -1,6 +1,8 @@
use rsrt::{cover, out};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
const LOGS: &str = include_str!("../logs.txt");
fn main() {
const WIDTH: usize = 1920;
const HEIGHT: usize = 1080;
@ -10,7 +12,15 @@ fn main() {
.with(tracing_subscriber::EnvFilter::from_default_env())
.init();
let image = cover(WIDTH, HEIGHT, 500).render_multithread_rayon();
let per_pixel = LOGS.len() / (WIDTH * HEIGHT);
out::write_image("./image.png", &image[..], WIDTH as u32, HEIGHT as u32).unwrap();
if per_pixel == 0 {
panic!("Logs had to be more than {} bytes, found {} bytes", WIDTH * HEIGHT, LOGS.len());
}
println!("{} bytes found", LOGS.len());
let image = cover(WIDTH, HEIGHT, 200).render_multithread_rayon();
out::write_image("./image.bmp", &image[..], WIDTH as u32, HEIGHT as u32, LOGS).unwrap();
}

View file

@ -1,5 +1,8 @@
use std::path::Path;
use bmp::Pixel;
use font8x8::{UnicodeFonts, BASIC_FONTS};
use crate::{interval::Interval, vec3::Color};
fn linear_to_gamma(linear_component: f64) -> f64 {
@ -15,23 +18,47 @@ pub fn write_image<P: AsRef<Path>>(
image: &[Color],
width: u32,
height: u32,
) -> Result<(), image::ImageError> {
let mut out = image::ImageBuffer::new(width, height);
logs: &str,
) -> std::io::Result<()> {
let per_pixel = (logs.len() / (width as usize * height as usize)).min(1);
assert_ne!(per_pixel, 0);
for (x, y, pixel) in out.enumerate_pixels_mut() {
let index = (y * width) + x;
let mut out = bmp::Image::new(width * per_pixel as u32 * 8, height * per_pixel as u32 * 8);
let r = linear_to_gamma(image[index as usize].r());
let g = linear_to_gamma(image[index as usize].g());
let b = linear_to_gamma(image[index as usize].b());
for y in 0..height {
for x in 0..width {
let index = (y as usize * width as usize) + x as usize;
const INTENSITY: Interval = Interval::new(0.000, 0.999);
let r = linear_to_gamma(image[index as usize].r());
let g = linear_to_gamma(image[index as usize].g());
let b = linear_to_gamma(image[index as usize].b());
*pixel = image::Rgb([
(INTENSITY.clamp(r) * 256.0) as u8,
(INTENSITY.clamp(g) * 256.0) as u8,
(INTENSITY.clamp(b) * 256.0) as u8,
]);
const INTENSITY: Interval = Interval::new(0.000, 0.999);
let r = (INTENSITY.clamp(r) * 256.0) as u8;
let g = (INTENSITY.clamp(g) * 256.0) as u8;
let b = (INTENSITY.clamp(b) * 256.0) as u8;
for y_sub in 0..per_pixel {
for x_sub in 0..per_pixel {
let y_idx = (y as usize + y_sub) * width as usize;
let x_idx = x as usize + x_sub;
let letter = logs.chars().nth(y_idx + x_idx).unwrap();
let letter_map = BASIC_FONTS.get(letter).unwrap();
for (char_row_idx, char_row) in letter_map.into_iter().enumerate() {
for bit in 0..8 {
let color = match char_row & 1 << bit {
0 => Pixel::new(0, 0, 0),
_ => Pixel::new(r, g, b),
};
out.set_pixel((x_idx as u32 * 8) + bit as u32, ((y as u32 + y_sub as u32) * 8) + char_row_idx as u32, color);
}
}
}
}
}
}
out.save(path)?;