feat: logs to a scene
This commit is contained in:
parent
c0ed10b2e5
commit
86c03f64b2
30
Cargo.lock
generated
30
Cargo.lock
generated
|
|
@ -199,6 +199,15 @@ dependencies = [
|
||||||
"objc2-encode",
|
"objc2-encode",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bmp"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69985ff4f58085ac696454692d0b646a66ad1f9cc9be294c91dc51bb5df511ae"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.16.0"
|
version = "3.16.0"
|
||||||
|
|
@ -513,6 +522,12 @@ dependencies = [
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "font8x8"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types"
|
name = "foreign-types"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
|
|
@ -651,18 +666,6 @@ version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
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]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.9.3"
|
version = "1.9.3"
|
||||||
|
|
@ -1373,9 +1376,10 @@ checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
|
||||||
name = "rsrt"
|
name = "rsrt"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bmp",
|
||||||
"criterion",
|
"criterion",
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"image",
|
"font8x8",
|
||||||
"paste",
|
"paste",
|
||||||
"rayon",
|
"rayon",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bmp = "0.5.0"
|
||||||
fastrand = "2.1.0"
|
fastrand = "2.1.0"
|
||||||
image = { version = "0.25.1", default-features = false, features = ["png"] }
|
font8x8 = "0.3.1"
|
||||||
paste = "1.0.15"
|
paste = "1.0.15"
|
||||||
rayon = "1.10.0"
|
rayon = "1.10.0"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
|
|
|
||||||
14
src/main.rs
14
src/main.rs
|
|
@ -1,6 +1,8 @@
|
||||||
use rsrt::{cover, out};
|
use rsrt::{cover, out};
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
|
const LOGS: &str = include_str!("../logs.txt");
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
const WIDTH: usize = 1920;
|
const WIDTH: usize = 1920;
|
||||||
const HEIGHT: usize = 1080;
|
const HEIGHT: usize = 1080;
|
||||||
|
|
@ -10,7 +12,15 @@ fn main() {
|
||||||
.with(tracing_subscriber::EnvFilter::from_default_env())
|
.with(tracing_subscriber::EnvFilter::from_default_env())
|
||||||
.init();
|
.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.png", &image[..], WIDTH as u32, HEIGHT as u32, LOGS).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
53
src/out.rs
53
src/out.rs
|
|
@ -1,5 +1,8 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use bmp::Pixel;
|
||||||
|
use font8x8::{UnicodeFonts, BASIC_FONTS};
|
||||||
|
|
||||||
use crate::{interval::Interval, vec3::Color};
|
use crate::{interval::Interval, vec3::Color};
|
||||||
|
|
||||||
fn linear_to_gamma(linear_component: f64) -> f64 {
|
fn linear_to_gamma(linear_component: f64) -> f64 {
|
||||||
|
|
@ -15,23 +18,47 @@ pub fn write_image<P: AsRef<Path>>(
|
||||||
image: &[Color],
|
image: &[Color],
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> Result<(), image::ImageError> {
|
logs: &str,
|
||||||
let mut out = image::ImageBuffer::new(width, height);
|
) -> 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 mut out = bmp::Image::new(width * per_pixel as u32 * 8, height * per_pixel as u32 * 8);
|
||||||
let index = (y * width) + x;
|
|
||||||
|
for y in 0..height {
|
||||||
|
for x in 0..width {
|
||||||
|
let index = (y as usize * width as usize) + x as usize;
|
||||||
|
|
||||||
let r = linear_to_gamma(image[index as usize].r());
|
let r = linear_to_gamma(image[index as usize].r());
|
||||||
let g = linear_to_gamma(image[index as usize].g());
|
let g = linear_to_gamma(image[index as usize].g());
|
||||||
let b = linear_to_gamma(image[index as usize].b());
|
let b = linear_to_gamma(image[index as usize].b());
|
||||||
|
|
||||||
const INTENSITY: Interval = Interval::new(0.000, 0.999);
|
const INTENSITY: Interval = Interval::new(0.000, 0.999);
|
||||||
|
|
||||||
*pixel = image::Rgb([
|
let r = (INTENSITY.clamp(r) * 256.0) as u8;
|
||||||
(INTENSITY.clamp(r) * 256.0) as u8,
|
let g = (INTENSITY.clamp(g) * 256.0) as u8;
|
||||||
(INTENSITY.clamp(g) * 256.0) as u8,
|
let b = (INTENSITY.clamp(b) * 256.0) as u8;
|
||||||
(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)?;
|
out.save(path)?;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue