#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;
pub mod atlas;
pub mod bake;
pub mod encode;
pub mod frame;
pub mod palette;
pub use atlas::GlyphAtlas;
pub use bake::bake_static;
pub use encode::{encode_png, save_png, to_rgba};
pub use frame::render_frame;
pub use palette::IndexedPalette;
use clairlune_scene::{BuildError, BuildOptions, SceneGraph, SceneRecipe, build};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct IndexedImage {
pub width: u32,
pub height: u32,
pub pixels: Vec<u8>,
}
impl IndexedImage {
pub fn new(width: u32, height: u32) -> Self {
Self {
width,
height,
pixels: vec![0; width as usize * height as usize],
}
}
}
#[derive(Clone, Debug)]
pub struct Still {
pub image: IndexedImage,
pub palette: IndexedPalette,
pub graph: SceneGraph,
pub t_ms: u64,
}
pub fn render_still(
recipe: &SceneRecipe,
opts: &BuildOptions,
t_ms: Option<u64>,
) -> Result<Still, BuildError> {
let graph = build(recipe, opts)?;
let atlas = GlyphAtlas::for_grid(&graph.grid);
let palette = IndexedPalette::new(&graph.family);
let background = bake_static(&graph, &atlas);
let t = t_ms.unwrap_or(graph.t_hero_ms);
let image = render_frame(&background, &graph, &atlas, &palette, t);
Ok(Still {
image,
palette,
graph,
t_ms: t,
})
}