Skip to main content

motion_content/
lib.rs

1//! Content preparation and drawing, independent of CPU/GPU backends.
2
3#![forbid(unsafe_code)]
4
5#[cfg(feature = "captions")]
6use captions::{CaptionCue, CaptionTrack};
7#[cfg(feature = "diagram")]
8use diagram::Scale;
9
10use motion_core::MorphPath;
11
12pub mod asset;
13pub mod atmosphere;
14#[cfg(feature = "captions")]
15pub mod captions;
16#[cfg(feature = "diagram")]
17pub mod diagram;
18#[cfg(feature = "text")]
19pub mod font;
20pub mod image;
21mod options;
22#[cfg(feature = "particles")]
23pub mod particles;
24#[cfg(feature = "svg")]
25pub mod svg;
26#[cfg(feature = "text")]
27pub mod text;
28pub mod vector;
29
30pub use asset::AssetsExt;
31#[cfg(feature = "text")]
32pub use font::{FontFace, FontIdentifier, FontLibrary, MAX_FONT_FACE_BYTES};
33#[cfg(feature = "image")]
34pub use image::{AnimatedImage, AnimatedImageAsset, ImageLoopMode};
35pub use image::{Fit, Image, ImageAsset, ImageLevel, Sampling};
36pub use options::{
37    CollisionResponse, FieldCoordinate, Inherit, ParticleEventKind, Preset, TextAlignment,
38    TextSplit,
39};
40#[cfg(feature = "particles")]
41pub use particles::{
42    Attractor, Ballistic, BounceBox, BurstEmitter, ColorOverLifetime, Converge, CurlNoise,
43    DiskEmitter, Drag, Gravity, NoiseDrift, Orbit, Particle, ParticleEmitter, ParticleModifier,
44    ParticleSimulation, ParticleSimulationBuilder, ParticleStyle, ParticleTrajectory, PathEmitter,
45    PointEmitter, RectEmitter, Seek, SimulationLimits, SimulationStats, SizeOverLifetime,
46    SurfaceEmitter, TrajectoryModel, Vortex, Wind,
47};
48
49#[cfg(feature = "svg")]
50pub use svg::{Svg, SvgAsset, SvgDiagnostic};
51#[cfg(feature = "text")]
52pub use text::{
53    FontWeight, ParagraphLayout, ParagraphStyle, PartStyle, Text, TextGlyph, TextPart, TextSpan,
54};
55pub use vector::{
56    CompileCache, Morph, SurfaceTriangle, VectorGroup, VectorImage, VectorItem, VectorLeaf,
57    VectorMask, VectorPath, VectorSelection, VectorSurface, VectorTree, WriteOptions,
58};
59
60/// Content authoring and core contracts without a renderer dependency.
61pub mod prelude {
62    #[cfg(feature = "image")]
63    pub use crate::{AnimatedImage, AnimatedImageAsset, ImageLoopMode};
64    pub use crate::{
65        AssetsExt, Fit, Image, ImageAsset, ImageLevel, Morph, Sampling, VectorGroup, VectorImage,
66        VectorItem, VectorLeaf, VectorMask, VectorPath, VectorSurface, VectorTree, WriteOptions,
67    };
68    #[cfg(feature = "text")]
69    pub use crate::{
70        FontFace, FontIdentifier, FontLibrary, FontWeight, ParagraphLayout, ParagraphStyle,
71        PartStyle, Text, TextAlignment, TextGlyph, TextPart, TextSpan, TextSplit,
72    };
73    #[cfg(test)]
74    pub use motion_render::{BackendKind, Composition, RenderOptions, RenderPrepare, render_still};
75}
76
77/// Maximum accepted `.cube` LUT text size in bytes.
78const MAX_CUBE_BYTES: u64 = 8 * 1024 * 1024;
79
80/// Loads explicitly requested LUT data without implicit resource discovery.
81pub fn load_lut(path: impl AsRef<std::path::Path>) -> motion_core::Result<motion_core::Lut3d> {
82    use std::io::Read;
83    let file = std::fs::File::open(path)?;
84    let mut text = String::new();
85    file.take(MAX_CUBE_BYTES + 1).read_to_string(&mut text)?;
86    Ok(motion_core::Lut3d::from_cube(&text)?)
87}
88
89/// Loads an explicitly requested standalone 1D `.cube` shaper.
90pub fn load_shaper(path: impl AsRef<std::path::Path>) -> motion_core::Result<motion_core::Lut1d> {
91    use std::io::Read;
92    let file = std::fs::File::open(path)?;
93    let mut text = String::new();
94    file.take(MAX_CUBE_BYTES + 1).read_to_string(&mut text)?;
95    Ok(motion_core::Lut1d::from_cube(&text)?)
96}
97
98#[cfg(feature = "image")]
99pub(crate) fn image_error(error: ::image::ImageError) -> motion_core::Error {
100    motion_core::Error::Other(Box::new(error))
101}