1#[cfg(doctest)]
11#[doc = include_str!("../README.md")]
12struct ReadmeDoctests;
13
14pub mod atlas;
15pub mod bake;
16pub mod encode;
17pub mod frame;
18pub mod palette;
19
20pub use atlas::GlyphAtlas;
21pub use bake::bake_static;
22pub use encode::{encode_png, save_png, to_rgba};
23pub use frame::render_frame;
24pub use palette::IndexedPalette;
25
26use clairlune_scene::{BuildError, BuildOptions, SceneGraph, SceneRecipe, build};
27
28#[derive(Clone, Debug, PartialEq, Eq)]
30pub struct IndexedImage {
31 pub width: u32,
32 pub height: u32,
33 pub pixels: Vec<u8>,
34}
35
36impl IndexedImage {
37 pub fn new(width: u32, height: u32) -> Self {
38 Self {
39 width,
40 height,
41 pixels: vec![0; width as usize * height as usize],
42 }
43 }
44}
45
46#[derive(Clone, Debug)]
48pub struct Still {
49 pub image: IndexedImage,
50 pub palette: IndexedPalette,
51 pub graph: SceneGraph,
52 pub t_ms: u64,
54}
55
56pub fn render_still(
58 recipe: &SceneRecipe,
59 opts: &BuildOptions,
60 t_ms: Option<u64>,
61) -> Result<Still, BuildError> {
62 let graph = build(recipe, opts)?;
63 let atlas = GlyphAtlas::for_grid(&graph.grid);
64 let palette = IndexedPalette::new(&graph.family);
65 let background = bake_static(&graph, &atlas);
66 let t = t_ms.unwrap_or(graph.t_hero_ms);
67 let image = render_frame(&background, &graph, &atlas, &palette, t);
68 Ok(Still {
69 image,
70 palette,
71 graph,
72 t_ms: t,
73 })
74}