mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-22 10:21:59 +01:00
* codecs,raw,preview,meta,engine: cut over TIFF/JPEG/focus to craft-libs and fix CI * docs: update parity-checklist paths after craft-raw/craft-metadata cutover * Remove unused codec workspace deps and cut examples over to craft-image-codecs * chore: update Cargo.lock after removing unused codec deps
34 lines
1.6 KiB
Rust
34 lines
1.6 KiB
Rust
//! Render every demo scene into a contact sheet PNG (simple clamp + sRGB encode, no develop).
|
|
//! `cargo run --release -p lightcraft-scenes --example contact_sheet -- out.png`
|
|
use lightcraft_color::{REC2020, SRGB, transfer::encode_srgb8};
|
|
|
|
fn main() {
|
|
let out = std::env::args().nth(1).unwrap_or_else(|| "contact.png".into());
|
|
let lib = lightcraft_scenes::demo_library();
|
|
let (cw, ch, cols) = (360usize, 240usize, 6usize);
|
|
let rows = lib.len().div_ceil(cols);
|
|
let (sw, sh) = (cw * cols, ch * rows);
|
|
let mut sheet = vec![0u8; sw * sh * 3];
|
|
let m = REC2020.to_space(&SRGB);
|
|
for (i, s) in lib.iter().enumerate() {
|
|
let img = s.render_fit(cw.min(ch * 3 / 2).max(ch));
|
|
let (ox, oy) = ((i % cols) * cw + (cw - img.width.min(cw)) / 2, (i / cols) * ch + (ch - img.height.min(ch)) / 2);
|
|
for y in 0..img.height.min(ch) {
|
|
for x in 0..img.width.min(cw) {
|
|
let c = m.apply_f32(img.get(x, y));
|
|
// simple Reinhard-ish shoulder for preview
|
|
let t = |v: f32| {
|
|
let v = v.max(0.0);
|
|
encode_srgb8(v / (1.0 + v * 0.35))
|
|
};
|
|
let idx = ((oy + y) * sw + (ox + x)) * 3;
|
|
sheet[idx..idx + 3].copy_from_slice(&[t(c[0]), t(c[1]), t(c[2])]);
|
|
}
|
|
}
|
|
}
|
|
let img = craft_image_codecs::Image::from_u8(sw as u32, sh as u32, craft_image_codecs::ChannelLayout::Rgb, sheet).unwrap();
|
|
let png = craft_image_codecs::encode(&img, craft_image_codecs::Format::Png, &Default::default()).unwrap();
|
|
std::fs::write(&out, png).unwrap();
|
|
println!("{out}");
|
|
}
|