Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

A look can be a table: .cube files import as packages and bind as 3D textures

Jareerc3b99b06b21c
diff --git a/engine/Cargo.lock b/engine/Cargo.lock
index 95575f11..d02f8f67 100644
--- a/engine/Cargo.lock
+++ b/engine/Cargo.lock
@@ -1154,6 +1154,7 @@ dependencies = [
"concat-speech",
"concat-vision",
"opener",
+ "png 0.17.16",
"pollster",
"rfd",
"serde",
diff --git a/engine/crates/concat-core/src/lib.rs b/engine/crates/concat-core/src/lib.rs
index 6346010d..864d3435 100644
--- a/engine/crates/concat-core/src/lib.rs
+++ b/engine/crates/concat-core/src/lib.rs
@@ -26,6 +26,6 @@ pub mod timeline;
pub use frame::Frame;
pub use retime::SpeedCurve;
-pub use shader::ShaderPass;
+pub use shader::{Lut, ShaderPass};
pub use time::{FrameRate, Rational, TimeRange};
pub use timeline::{Blend, Clip, ClipId, Project, Timeline, Track, TrackId, TrackKind};
diff --git a/engine/crates/concat-core/src/shader.rs b/engine/crates/concat-core/src/shader.rs
index 47a6d509..87a07003 100644
--- a/engine/crates/concat-core/src/shader.rs
+++ b/engine/crates/concat-core/src/shader.rs
@@ -33,6 +33,9 @@ pub struct ShaderPass {
/// How much of the result to keep over the untouched layer, `0..=1`. A
/// look at half strength is half the look; an effect is always one.
pub intensity: f32,
+ /// The package's look-up table, bound as a 3D texture the shader's
+ /// `lut()` samples; None binds the identity so the call is harmless.
+ pub lut: Option<Arc<Lut>>,
}
impl ShaderPass {
@@ -40,3 +43,124 @@ impl ShaderPass {
/// needs a binding.
pub const MIN_PARAMS: usize = 16;
}
+
+/// A 3D look-up table: `size` texels a side, RGBA8, red fastest, then
+/// green, then blue - the order a `.cube` file lists its rows in and the
+/// layout a `texture_3d` is uploaded from. A colour is looked up by its
+/// own components: the table maps every input colour to an output one.
+#[derive(Clone, Debug, PartialEq)]
+pub struct Lut {
+ /// A hash of the contents, so a renderer can cache the upload.
+ pub id: u64,
+ /// Texels a side, at least 2.
+ pub size: u32,
+ /// `size³ × 4` bytes.
+ pub rgba: Arc<[u8]>,
+}
+
+impl Lut {
+ /// A table from `size³` RGB triples in 0..=1, red fastest. Values
+ /// outside the range are clamped; a table of the wrong length is None.
+ pub fn from_rgb(size: u32, rgb: &[f32]) -> Option<Lut> {
+ let texels = (size as usize).checked_pow(3)?;
+ if size < 2 || rgb.len() != texels * 3 {
+ return None;
+ }
+ let mut rgba = Vec::with_capacity(texels * 4);
+ for triple in rgb.chunks_exact(3) {
+ for channel in triple {
+ rgba.push((channel.clamp(0.0, 1.0) * 255.0).round() as u8);
+ }
+ rgba.push(255);
+ }
+ let id = fnv64(&rgba) ^ u64::from(size);
+ Some(Lut {
+ id,
+ size,
+ rgba: rgba.into(),
+ })
+ }
+
+ /// The table that changes nothing: what a pass without one binds.
+ pub fn identity(size: u32) -> Lut {
+ let size = size.max(2);
+ let step = 1.0 / (size - 1) as f32;
+ let mut rgb = Vec::with_capacity((size * size * size * 3) as usize);
+ for b in 0..size {
+ for g in 0..size {
+ for r in 0..size {
+ rgb.extend_from_slice(&[r as f32 * step, g as f32 * step, b as f32 * step]);
+ }
+ }
+ }
+ Lut::from_rgb(size, &rgb).expect("a square table")
+ }
+
+ /// The colour the table maps `rgb` to, trilinearly interpolated - the
+ /// same arithmetic the GPU's sampler does, for a CPU that wants it.
+ pub fn sample(&self, rgb: [f32; 3]) -> [f32; 3] {
+ let n = self.size as usize;
+ let last = (n - 1) as f32;
+ let at = |c: f32| {
+ let x = c.clamp(0.0, 1.0) * last;
+ let i = (x.floor() as usize).min(n - 2);
+ (i, x - i as f32)
+ };
+ let (ri, rf) = at(rgb[0]);
+ let (gi, gf) = at(rgb[1]);
+ let (bi, bf) = at(rgb[2]);
+ let texel = |r: usize, g: usize, b: usize| {
+ let o = ((b * n + g) * n + r) * 4;
+ [
+ f32::from(self.rgba[o]) / 255.0,
+ f32::from(self.rgba[o + 1]) / 255.0,
+ f32::from(self.rgba[o + 2]) / 255.0,
+ ]
+ };
+ let lerp = |a: [f32; 3], b: [f32; 3], t: f32| {
+ [
+ a[0] + (b[0] - a[0]) * t,
+ a[1] + (b[1] - a[1]) * t,
+ a[2] + (b[2] - a[2]) * t,
+ ]
+ };
+ let c00 = lerp(texel(ri, gi, bi), texel(ri + 1, gi, bi), rf);
+ let c10 = lerp(texel(ri, gi + 1, bi), texel(ri + 1, gi + 1, bi), rf);
+ let c01 = lerp(texel(ri, gi, bi + 1), texel(ri + 1, gi, bi + 1), rf);
+ let c11 = lerp(texel(ri, gi + 1, bi + 1), texel(ri + 1, gi + 1, bi + 1), rf);
+ lerp(lerp(c00, c10, gf), lerp(c01, c11, gf), bf)
+ }
+}
+
+/// FNV-1a, so a table's id needs no dependency and is the same on every
+/// machine.
+fn fnv64(bytes: &[u8]) -> u64 {
+ let mut hash: u64 = 0xcbf2_9ce4_8422_2325;
+ for byte in bytes {
+ hash ^= u64::from(*byte);
+ hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
+ }
+ hash
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn the_identity_table_returns_what_it_is_given() {
+ let lut = Lut::identity(17);
+ for rgb in [[0.0, 0.0, 0.0], [1.0, 1.0, 1.0], [0.25, 0.5, 0.75], [0.9, 0.1, 0.3]] {
+ let out = lut.sample(rgb);
+ for (a, b) in out.iter().zip(rgb.iter()) {
+ assert!((a - b).abs() < 0.01, "{rgb:?} -> {out:?}");
+ }
+ }
+ }
+
+ #[test]
+ fn a_table_of_the_wrong_length_is_refused() {
+ assert!(Lut::from_rgb(3, &[0.0; 26 * 3]).is_none());
+ assert!(Lut::from_rgb(1, &[0.0; 3]).is_none());
+ }
+}
diff --git a/engine/crates/concat-effects/src/catalogue.rs b/engine/crates/concat-effects/src/catalogue.rs
index 7ebfcf76..e5f415d8 100644
--- a/engine/crates/concat-effects/src/catalogue.rs
+++ b/engine/crates/concat-effects/src/catalogue.rs
@@ -10,14 +10,14 @@
use std::collections::{BTreeMap, HashMap};
use std::path::Path;
-use std::sync::OnceLock;
+use std::sync::{Arc, RwLock};
use concat_project::model::AppliedFilter;
use serde::Deserialize;
use crate::Error;
use crate::expr::{Expr, Value};
-use concat_core::ShaderPass;
+use concat_core::{Lut, ShaderPass};
use crate::manifest::{Kind, Manifest};
use crate::shader::Shader;
@@ -75,6 +75,10 @@ pub struct Package {
shader: Option<Shader>,
/// The pinned outputs shipped with the package.
pub fixtures: Vec<Fixture>,
+ /// The folder the package was loaded from; None for a built-in.
+ pub folder: Option<std::path::PathBuf>,
+ /// The table the manifest's `[lut]` names, read at load.
+ lut: Option<Arc<Lut>>,
}
/// Where a fixture's parameters start from.
@@ -126,7 +130,17 @@ impl Package {
fixtures: Option<&str>,
shader: Option<&str>,
) -> Result<Package, Error> {
- let manifest = Manifest::parse(manifest)?;
+ Package::from_manifest(Manifest::parse(manifest)?, fixtures, shader, None)
+ }
+
+ /// `from_sources` with the manifest already parsed, and the table its
+ /// `[lut]` names read from `folder`, when it has one.
+ fn from_manifest(
+ manifest: Manifest,
+ fixtures: Option<&str>,
+ shader: Option<&str>,
+ table: Option<(std::path::PathBuf, Arc<Lut>)>,
+ ) -> Result<Package, Error> {
let invalid = |message: String| Error::Invalid {
id: manifest.effect.id.clone(),
message,
@@ -164,6 +178,9 @@ impl Package {
let mut known: Vec<String> =
manifest.params.iter().map(|p| p.key.clone()).collect();
known.push("index".to_owned());
+ if manifest.lut.is_some() {
+ known.push("lut".to_owned());
+ }
let mut lets = Vec::new();
for binding in &ffmpeg.lets {
let Some((name, source)) = binding.split_once('=') else {
@@ -207,11 +224,24 @@ impl Package {
}
};
+ if manifest.lut.is_some() && table.is_none() {
+ // The table is a file beside the manifest, and only a folder
+ // has one; see `from_folder`.
+ return Err(invalid(
+ "a package with a [lut] must be loaded from its folder".to_owned(),
+ ));
+ }
+ let (folder, lut) = match table {
+ Some((folder, lut)) => (Some(folder), Some(lut)),
+ None => (None, None),
+ };
let package = Package {
manifest,
chain,
shader,
fixtures,
+ folder,
+ lut,
};
// Render at every bound now, so a type error in an expression is a
// load failure and never a silent gap in an export.
@@ -294,6 +324,13 @@ impl Package {
.map(|(key, value)| (key, Value::Float(value)))
.collect();
env.insert("index".to_owned(), Value::Int(index as i64));
+ if let (Some(table), Some(folder)) = (&self.manifest.lut, &self.folder) {
+ let path = folder.join(&table.file);
+ env.insert(
+ "lut".to_owned(),
+ Value::Text(escape_option(&path.to_string_lossy())),
+ );
+ }
let invalid = |message: String| Error::Invalid {
id: self.id().to_owned(),
message,
@@ -312,6 +349,49 @@ impl Package {
}
/// Runs every fixture; returns one line per failure.
+ /// Loads a package from its folder: the manifest, and beside it the
+ /// fixtures, the shader and the table, whichever the manifest names.
+ pub fn from_folder(folder: &Path) -> Result<Package, Error> {
+ let read = |name: &str| {
+ std::fs::read_to_string(folder.join(name)).map_err(|error| Error::Io {
+ path: folder.join(name),
+ message: error.to_string(),
+ })
+ };
+ let manifest_text = read("effect.toml")?;
+ let fixtures = read("fixtures.toml").ok();
+ let shader = read("effect.wgsl").ok();
+ let manifest = Manifest::parse(&manifest_text)?;
+ let table = match &manifest.lut {
+ Some(table) => {
+ let text = read(&table.file)?;
+ let lut = crate::cube::parse(&text).map_err(|message| Error::Invalid {
+ id: manifest.effect.id.clone(),
+ message: format!("{}: {message}", table.file),
+ })?;
+ Some(Arc::new(lut))
+ }
+ None => None,
+ };
+ let mut package = Package::from_manifest(
+ manifest,
+ fixtures.as_deref(),
+ shader.as_deref(),
+ table.map(|lut| (folder.to_path_buf(), lut)),
+ )?;
+ if package.folder.is_none() {
+ package.folder = Some(folder.to_path_buf());
+ }
+ Ok(package)
+ }
+
+ /// The table the package ships, if it does.
+ pub fn lut(&self) -> Option<&Arc<Lut>> {
+ self.lut.as_ref()
+ }
+
+ /// Renders every fixture and reports the ones whose chain came out
+ /// different: the package's own regression suite.
pub fn check_fixtures(&self) -> Vec<String> {
let mut failures = Vec::new();
for (n, case) in self.fixtures.iter().enumerate() {
@@ -339,6 +419,12 @@ impl Package {
}
}
+/// A path as one FFmpeg option value: single-quoted, with the quote
+/// itself the one character that has to be spelt out.
+fn escape_option(text: &str) -> String {
+ format!("'{}'", text.replace('\'', "'\\''"))
+}
+
fn check_names(expr: &Expr, known: &[String]) -> Result<(), String> {
let mut names = Vec::new();
expr.names(&mut names);
@@ -350,6 +436,9 @@ fn check_names(expr: &Expr, known: &[String]) -> Result<(), String> {
Ok(())
}
+/// The catalogue every caller reads; see `Catalogue::builtin`.
+static CURRENT: RwLock<Option<&'static Catalogue>> = RwLock::new(None);
+
/// Every package the app knows.
#[derive(Clone, Debug, Default)]
pub struct Catalogue {
@@ -363,27 +452,57 @@ impl Catalogue {
Self::default()
}
- /// The packages compiled into the binary. Loaded once; a built-in that
- /// fails to load is a build defect, and the tests catch it.
+ /// Every package the process knows: the ones compiled into the binary
+ /// and, once [`Catalogue::install`] has run, the ones in the user's
+ /// folder. Built on first use; a built-in that fails to load is a
+ /// build defect, and the tests catch it.
pub fn builtin() -> &'static Catalogue {
- static BUILTIN: OnceLock<Catalogue> = OnceLock::new();
- BUILTIN.get_or_init(|| {
- let mut catalogue = Catalogue::new();
- for (folder, manifest, fixtures, shader) in crate::builtins::BUILTIN_SOURCES {
- let package = Package::from_sources(manifest, *fixtures, *shader)
- .unwrap_or_else(|error| panic!("built-in package {folder}: {error}"));
- assert_eq!(
- package.id(),
- *folder,
- "package folder must be named after its id"
- );
- catalogue
- .add(package)
- .unwrap_or_else(|error| panic!("built-in package {folder}: {error}"));
- }
- catalogue.sort();
+ if let Some(current) = *CURRENT.read().expect("catalogue lock") {
+ return current;
+ }
+ let mut slot = CURRENT.write().expect("catalogue lock");
+ if let Some(current) = *slot {
+ return current;
+ }
+ let built: &'static Catalogue = Box::leak(Box::new(Catalogue::compiled_in()));
+ *slot = Some(built);
+ built
+ }
+
+ /// Makes the packages under `dir` part of the catalogue, beside the
+ /// built-ins, and reports the ones that would not load. Called at
+ /// start and again after an import; each call builds the catalogue
+ /// afresh and leaks the last one, which is a few kilobytes a time and
+ /// what keeps every caller's `&'static` honest.
+ pub fn install(dir: &Path) -> Vec<Error> {
+ let mut catalogue = Catalogue::compiled_in();
+ let errors = if dir.is_dir() {
+ catalogue.load_dir(dir)
+ } else {
+ Vec::new()
+ };
+ let built: &'static Catalogue = Box::leak(Box::new(catalogue));
+ *CURRENT.write().expect("catalogue lock") = Some(built);
+ errors
+ }
+
+ /// The packages compiled into the binary, and nothing else.
+ fn compiled_in() -> Catalogue {
+ let mut catalogue = Catalogue::new();
+ for (folder, manifest, fixtures, shader) in crate::builtins::BUILTIN_SOURCES {
+ let package = Package::from_sources(manifest, *fixtures, *shader)
+ .unwrap_or_else(|error| panic!("built-in package {folder}: {error}"));
+ assert_eq!(
+ package.id(),
+ *folder,
+ "package folder must be named after its id"
+ );
catalogue
- })
+ .add(package)
+ .unwrap_or_else(|error| panic!("built-in package {folder}: {error}"));
+ }
+ catalogue.sort();
+ catalogue
}
/// Adds a package. Its id and aliases must be new to the catalogue.
@@ -426,22 +545,7 @@ impl Catalogue {
.collect();
folders.sort();
for folder in folders {
- let read = |name: &str| std::fs::read_to_string(folder.join(name));
- let manifest = match read("effect.toml") {
- Ok(text) => text,
- Err(error) => {
- errors.push(Error::Io {
- path: folder.join("effect.toml"),
- message: error.to_string(),
- });
- continue;
- }
- };
- let fixtures = read("fixtures.toml").ok();
- let shader = read("effect.wgsl").ok();
- match Package::from_sources(&manifest, fixtures.as_deref(), shader.as_deref())
- .and_then(|p| self.add(p))
- {
+ match Package::from_folder(&folder).and_then(|p| self.add(p)) {
Ok(()) => {}
Err(error) => errors.push(error),
}
@@ -532,7 +636,7 @@ impl Catalogue {
1.0
};
let values = package.resolve(&set);
- Some(shader.pass(&values, &package.manifest.params, intensity))
+ Some(shader.pass(&values, &package.manifest.params, intensity, package.lut.clone()))
})
.collect()
}
diff --git a/engine/crates/concat-effects/src/cube.rs b/engine/crates/concat-effects/src/cube.rs
new file mode 100644
index 00000000..1a250c5d
--- /dev/null
+++ b/engine/crates/concat-effects/src/cube.rs
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+//! The `.cube` file: the look-up table format every grading tool writes.
+//!
+//! A header of `LUT_3D_SIZE n`, optionally a `TITLE` and a `DOMAIN_MIN` /
+//! `DOMAIN_MAX`, then `n³` rows of three numbers, red changing fastest.
+//! Read with the same tolerance as a manifest: comments and blank lines
+//! are skipped, a domain other than 0..1 is rescaled, and anything the
+//! rows do not add up to is an error naming the line.
+
+use concat_core::Lut;
+
+/// Parses the text of a `.cube` file into a table.
+pub fn parse(text: &str) -> Result<Lut, String> {
+ let mut size: Option<u32> = None;
+ let mut domain_min = [0.0f32; 3];
+ let mut domain_max = [1.0f32; 3];
+ let mut rgb: Vec<f32> = Vec::new();
+ for (number, raw) in text.lines().enumerate() {
+ let line = raw.split('#').next().unwrap_or("").trim();
+ if line.is_empty() {
+ continue;
+ }
+ let mut words = line.split_whitespace();
+ let head = words.next().unwrap_or("");
+ let at = number + 1;
+ match head {
+ "TITLE" => {}
+ "LUT_1D_SIZE" => return Err(format!("line {at}: a 1D table; only 3D tables are read")),
+ "LUT_3D_SIZE" => {
+ let n: u32 = words
+ .next()
+ .and_then(|w| w.parse().ok())
+ .ok_or_else(|| format!("line {at}: LUT_3D_SIZE needs a number"))?;
+ if !(2..=129).contains(&n) {
+ return Err(format!("line {at}: a table {n} a side is out of range"));
+ }
+ size = Some(n);
+ rgb.reserve((n as usize).pow(3) * 3);
+ }
+ "DOMAIN_MIN" | "DOMAIN_MAX" => {
+ let mut triple = [0.0f32; 3];
+ for slot in &mut triple {
+ *slot = words
+ .next()
+ .and_then(|w| w.parse().ok())
+ .ok_or_else(|| format!("line {at}: {head} needs three numbers"))?;
+ }
+ if head == "DOMAIN_MIN" {
+ domain_min = triple;
+ } else {
+ domain_max = triple;
+ }
+ }
+ _ => {
+ let mut triple = [0.0f32; 3];
+ let mut rest = line.split_whitespace();
+ for slot in &mut triple {
+ *slot = rest
+ .next()
+ .and_then(|w| w.parse().ok())
+ .ok_or_else(|| format!("line {at}: expected three numbers"))?;
+ }
+ rgb.extend_from_slice(&triple);
+ }
+ }
+ }
+ let size = size.ok_or_else(|| "no LUT_3D_SIZE".to_owned())?;
+ let expected = (size as usize).pow(3) * 3;
+ if rgb.len() != expected {
+ return Err(format!(
+ "{} rows for a table {size} a side, which wants {}",
+ rgb.len() / 3,
+ expected / 3
+ ));
+ }
+ for (i, value) in rgb.iter_mut().enumerate() {
+ let channel = i % 3;
+ let span = domain_max[channel] - domain_min[channel];
+ if span.abs() > f32::EPSILON {
+ *value = (*value - domain_min[channel]) / span;
+ }
+ }
+ Lut::from_rgb(size, &rgb).ok_or_else(|| "the table did not fit".to_owned())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn identity(n: u32) -> String {
+ let mut text = format!("TITLE \"id\"\nLUT_3D_SIZE {n}\n# rows\n");
+ for b in 0..n {
+ for g in 0..n {
+ for r in 0..n {
+ let s = 1.0 / (n - 1) as f32;
+ text.push_str(&format!("{} {} {}\n", r as f32 * s, g as f32 * s, b as f32 * s));
+ }
+ }
+ }
+ text
+ }
+
+ #[test]
+ fn an_identity_cube_reads_as_the_identity() {
+ let lut = parse(&identity(9)).expect("parses");
+ assert_eq!(lut.size, 9);
+ let out = lut.sample([0.3, 0.6, 0.9]);
+ assert!((out[0] - 0.3).abs() < 0.01 && (out[1] - 0.6).abs() < 0.01 && (out[2] - 0.9).abs() < 0.01);
+ }
+
+ #[test]
+ fn a_short_table_names_the_shortfall() {
+ let mut text = identity(3);
+ text.push_str("0 0 0\n");
+ assert!(parse(&text).unwrap_err().contains("28 rows"));
+ assert!(parse("LUT_1D_SIZE 4\n").unwrap_err().contains("1D"));
+ }
+}
diff --git a/engine/crates/concat-effects/src/lib.rs b/engine/crates/concat-effects/src/lib.rs
index efed4af9..68953fd8 100644
--- a/engine/crates/concat-effects/src/lib.rs
+++ b/engine/crates/concat-effects/src/lib.rs
@@ -19,6 +19,7 @@
//! skipped at render time.
pub mod catalogue;
+pub mod cube;
pub mod expr;
pub mod manifest;
pub mod shader;
@@ -98,6 +99,45 @@ mod tests {
assert!(!effect.contains("blend"), "{effect}");
}
+ #[test]
+ fn a_folder_package_with_a_table_loads_and_names_its_file() {
+ let dir = std::env::temp_dir().join(format!("concat-lut-{}", std::process::id()));
+ let folder = dir.join("test.table");
+ std::fs::create_dir_all(&folder).expect("temp dir");
+ std::fs::write(
+ folder.join("effect.toml"),
+ "[effect]\nid = \"test.table\"\nname = \"Table\"\nkind = \"filter\"\n\n[lut]\nfile = \"look.cube\"\n\n[ffmpeg]\nchain = \"lut3d=file={lut}\"\n\n[wgsl]\nentry = \"effect.wgsl\"\n",
+ )
+ .expect("manifest");
+ std::fs::write(
+ folder.join("effect.wgsl"),
+ "fn effect(uv: vec2<f32>) -> vec4<f32> { let c = sample(uv); return vec4<f32>(lut(c.rgb), c.a); }",
+ )
+ .expect("shader");
+ let mut cube = String::from("LUT_3D_SIZE 2\n");
+ for b in 0..2 {
+ for g in 0..2 {
+ for r in 0..2 {
+ cube.push_str(&format!("{r} {g} {b}\n"));
+ }
+ }
+ }
+ std::fs::write(folder.join("look.cube"), cube).expect("cube");
+
+ let mut catalogue = Catalogue::new();
+ let errors = catalogue.load_dir(&dir);
+ assert!(errors.is_empty(), "{errors:?}");
+ let package = catalogue.get("test.table").expect("loaded");
+ assert_eq!(package.lut().map(|lut| lut.size), Some(2));
+ let chain = package
+ .ffmpeg_fragment(&BTreeMap::new(), 0)
+ .expect("renders")
+ .expect("has a chain");
+ assert!(chain.starts_with("lut3d=file='") && chain.ends_with("look.cube'"), "{chain}");
+ assert_eq!(catalogue.shader_passes(&[AppliedFilter::new("test.table")])[0].lut.as_ref().map(|l| l.size), Some(2));
+ let _ = std::fs::remove_dir_all(&dir);
+ }
+
#[test]
fn every_built_in_package_loads_and_its_fixtures_pass() {
let catalogue = Catalogue::builtin();
diff --git a/engine/crates/concat-effects/src/manifest.rs b/engine/crates/concat-effects/src/manifest.rs
index 8edb98dd..39d7c337 100644
--- a/engine/crates/concat-effects/src/manifest.rs
+++ b/engine/crates/concat-effects/src/manifest.rs
@@ -28,6 +28,18 @@ pub struct Manifest {
/// The WGSL backend, when the package is a shader.
#[serde(default)]
pub wgsl: Option<Wgsl>,
+ /// A look-up table the package ships: the shader reads it through
+ /// `lut()`, and a chain names its file as `{lut}`.
+ #[serde(default)]
+ pub lut: Option<LutTable>,
+}
+
+/// The `[lut]` table: a `.cube` file beside the manifest.
+#[derive(Deserialize, Clone, PartialEq, Debug)]
+#[serde(deny_unknown_fields)]
+pub struct LutTable {
+ /// The file, beside the manifest. Only `.cube` is read.
+ pub file: String,
}
/// The `[effect]` table.
@@ -243,6 +255,12 @@ impl Manifest {
if self.effect.name.trim().is_empty() {
return Err(self.invalid("name is empty"));
}
+ if let Some(lut) = &self.lut {
+ let plain = !lut.file.contains('/') && !lut.file.contains('\\');
+ if !plain || !lut.file.to_ascii_lowercase().ends_with(".cube") {
+ return Err(self.invalid("[lut] file must be a `.cube` beside the manifest"));
+ }
+ }
for alias in &self.effect.aliases {
if !is_id_segment(alias)
&& !alias
diff --git a/engine/crates/concat-effects/src/shader.rs b/engine/crates/concat-effects/src/shader.rs
index 4db0ed37..5dd26c54 100644
--- a/engine/crates/concat-effects/src/shader.rs
+++ b/engine/crates/concat-effects/src/shader.rs
@@ -21,7 +21,7 @@
use std::collections::BTreeMap;
use std::sync::Arc;
-use concat_core::ShaderPass;
+use concat_core::{Lut, ShaderPass};
use crate::manifest::{Manifest, Param, ParamType};
@@ -41,6 +41,8 @@ struct Frame {
@group(0) @binding(1) var source_sampler: sampler;
@group(1) @binding(0) var<uniform> frame: Frame;
@group(1) @binding(1) var<uniform> params: Params;
+@group(2) @binding(0) var lut_texture: texture_3d<f32>;
+@group(2) @binding(1) var lut_sampler: sampler;
/// The layer's colour at `uv`, straight alpha.
fn sample(uv: vec2<f32>) -> vec4<f32> {
@@ -57,6 +59,15 @@ fn luma(rgb: vec3<f32>) -> f32 {
return dot(rgb, vec3<f32>(0.2126, 0.7152, 0.0722));
}
+/// The package's look-up table applied to a colour - the identity when
+/// the package ships none, so the call is always safe. Sampled at the
+/// texel centres, so the table's ends land on black and white exactly.
+fn lut(rgb: vec3<f32>) -> vec3<f32> {
+ let n = f32(textureDimensions(lut_texture).x);
+ let uvw = clamp(rgb, vec3<f32>(0.0), vec3<f32>(1.0)) * (n - 1.0) / n + vec3<f32>(0.5 / n);
+ return textureSampleLevel(lut_texture, lut_sampler, uvw, 0.0).rgb;
+}
+
/// A hash in 0..1 from a point and a seed, for grain and dither.
fn hash(p: vec2<f32>, seed: f32) -> f32 {
let q = vec3<f32>(p, seed);
@@ -468,12 +479,14 @@ impl Shader {
values: &BTreeMap<String, f64>,
params: &[Param],
intensity: f32,
+ lut: Option<Arc<Lut>>,
) -> ShaderPass {
ShaderPass {
key: self.key.clone(),
source: Arc::clone(&self.source),
params: self.params_bytes(values, params),
intensity,
+ lut,
}
}
}
diff --git a/engine/crates/concat-render/src/gpu.rs b/engine/crates/concat-render/src/gpu.rs
index 32afa47c..1af8c50e 100644
--- a/engine/crates/concat-render/src/gpu.rs
+++ b/engine/crates/concat-render/src/gpu.rs
@@ -29,7 +29,7 @@
use std::collections::HashMap;
use concat_core::frame::Frame;
-use concat_core::shader::ShaderPass;
+use concat_core::shader::{Lut, ShaderPass};
use concat_core::timeline::Blend;
use crate::compositor::{Compositor, CpuCompositor, Layer};
@@ -142,6 +142,10 @@ pub struct WgpuCompositor {
bind_layout: wgpu::BindGroupLayout,
/// Group 1 of a shader pass: the frame block and the package's params.
uniform_layout: wgpu::BindGroupLayout,
+ /// Group 2 of a shader pass: the package's look-up table, a 3D texture.
+ lut_layout: wgpu::BindGroupLayout,
+ /// Uploaded tables by their id, the identity among them; see `lut_group`.
+ luts: HashMap<u64, wgpu::BindGroup>,
/// Compiled passes by their key; see `ShaderPass::key`.
shaders: HashMap<String, CompiledShader>,
sampler: wgpu::Sampler,
@@ -228,6 +232,29 @@ impl WgpuCompositor {
label: Some("concat pass uniforms"),
entries: &[uniform_entry(0), uniform_entry(1)],
});
+ // Group 2: a look-up table. Every pass binds one - the identity when
+ // the package has none - so one pipeline layout serves them all.
+ let lut_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
+ label: Some("concat pass lut"),
+ entries: &[
+ wgpu::BindGroupLayoutEntry {
+ binding: 0,
+ visibility: wgpu::ShaderStages::FRAGMENT,
+ ty: wgpu::BindingType::Texture {
+ sample_type: wgpu::TextureSampleType::Float { filterable: true },
+ view_dimension: wgpu::TextureViewDimension::D3,
+ multisampled: false,
+ },
+ count: None,
+ },
+ wgpu::BindGroupLayoutEntry {
+ binding: 1,
+ visibility: wgpu::ShaderStages::FRAGMENT,
+ ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
+ count: None,
+ },
+ ],
+ });
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("concat compositor"),
bind_group_layouts: &[Some(&bind_layout)],
@@ -337,6 +364,8 @@ impl WgpuCompositor {
pipelines,
bind_layout,
uniform_layout,
+ lut_layout,
+ luts: HashMap::new(),
shaders: HashMap::new(),
sampler,
vertices,
@@ -670,7 +699,11 @@ impl WgpuCompositor {
.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some(&pass.key),
- bind_group_layouts: &[Some(&self.bind_layout), Some(&self.uniform_layout)],
+ bind_group_layouts: &[
+ Some(&self.bind_layout),
+ Some(&self.uniform_layout),
+ Some(&self.lut_layout),
+ ],
immediate_size: 0,
});
let pipeline = self
@@ -739,6 +772,74 @@ impl WgpuCompositor {
);
}
+ /// The bind group for a pass's table, uploaded the first time its id is
+ /// seen, and the identity's for a pass without one. Returns the id the
+ /// group is filed under.
+ fn lut_group(&mut self, lut: Option<&Lut>) -> u64 {
+ let identity;
+ let lut = match lut {
+ Some(lut) => lut,
+ None => {
+ identity = Lut::identity(2);
+ &identity
+ }
+ };
+ if self.luts.contains_key(&lut.id) {
+ return lut.id;
+ }
+ let size = lut.size;
+ let texture = self.device.create_texture(&wgpu::TextureDescriptor {
+ label: Some("concat lut"),
+ size: wgpu::Extent3d {
+ width: size,
+ height: size,
+ depth_or_array_layers: size,
+ },
+ mip_level_count: 1,
+ sample_count: 1,
+ dimension: wgpu::TextureDimension::D3,
+ format: wgpu::TextureFormat::Rgba8Unorm,
+ usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
+ view_formats: &[],
+ });
+ self.queue.write_texture(
+ wgpu::TexelCopyTextureInfo {
+ texture: &texture,
+ mip_level: 0,
+ origin: wgpu::Origin3d::ZERO,
+ aspect: wgpu::TextureAspect::All,
+ },
+ &lut.rgba,
+ wgpu::TexelCopyBufferLayout {
+ offset: 0,
+ bytes_per_row: Some(size * 4),
+ rows_per_image: Some(size),
+ },
+ wgpu::Extent3d {
+ width: size,
+ height: size,
+ depth_or_array_layers: size,
+ },
+ );
+ let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
+ let bind_group = self.device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: Some("concat lut"),
+ layout: &self.lut_layout,
+ entries: &[
+ wgpu::BindGroupEntry {
+ binding: 0,
+ resource: wgpu::BindingResource::TextureView(&view),
+ },
+ wgpu::BindGroupEntry {
+ binding: 1,
+ resource: wgpu::BindingResource::Sampler(&self.sampler),
+ },
+ ],
+ });
+ self.luts.insert(lut.id, bind_group);
+ lut.id
+ }
+
/// Runs `passes` over the pooled texture `source` of `width` × `height`,
/// each drawing into a fresh pooled texture of the same size, and
/// returns the index of the last one drawn. Each pass is its own
@@ -755,7 +856,9 @@ impl WgpuCompositor {
for pass in passes {
let target = self.claim(width, height);
self.shader(pass);
+ let lut_id = self.lut_group(pass.lut.as_deref());
let shader = &self.shaders[&pass.key];
+ let lut_group = &self.luts[&lut_id];
let frame_block: [f32; 4] = [width as f32, height as f32, time, pass.intensity];
let frame_bytes: Vec<u8> = frame_block.iter().flat_map(|v| v.to_le_bytes()).collect();
self.queue.write_buffer(&shader.frame, 0, &frame_bytes);
@@ -792,6 +895,7 @@ impl WgpuCompositor {
render.set_pipeline(&shader.pipeline);
render.set_bind_group(0, &pool[current].bind_group, &[]);
render.set_bind_group(1, &shader.bind_group, &[]);
+ render.set_bind_group(2, lut_group, &[]);
render.draw(0..3, 0..1);
}
self.queue.submit([encoder.finish()]);
@@ -972,10 +1076,10 @@ mod tests {
}
frame
};
- let full = [shader.pass(&Default::default(), &[], 1.0)];
+ let full = [shader.pass(&Default::default(), &[], 1.0, None)];
let out = gpu.composite(4, 4, &[Layer::new(&red).with_passes(&full)]);
assert_eq!(&out.pixels()[..3], &[0, 255, 255]);
- let half = [shader.pass(&Default::default(), &[], 0.5)];
+ let half = [shader.pass(&Default::default(), &[], 0.5, None)];
let out = gpu.composite(4, 4, &[Layer::new(&red).with_passes(&half)]);
let p = &out.pixels()[..3];
assert!(
@@ -984,6 +1088,31 @@ mod tests {
);
}
+ /// A pass reads its table through `lut()`: a table that answers green
+ /// to every colour turns a red frame green, and a pass without one is
+ /// handed the identity and changes nothing.
+ #[test]
+ fn a_pass_samples_its_table_and_the_identity_without_one() {
+ let Some(mut gpu) = gpu() else { return };
+ let manifest = concat_effects::Manifest::parse(
+ "[effect]\nid = \"test.table\"\nname = \"Table\"\nkind = \"effect\"\n[wgsl]\nentry = \"effect.wgsl\"\n",
+ )
+ .expect("a manifest");
+ let shader = concat_effects::Shader::compile(
+ &manifest,
+ "fn effect(uv: vec2<f32>) -> vec4<f32> { let c = sample(uv); return vec4<f32>(lut(c.rgb), c.a); }",
+ )
+ .expect("compiles");
+ let red = solid(4, 4, [255, 0, 0, 255]);
+ let green = Lut::from_rgb(2, &[0.0, 1.0, 0.0].repeat(8)).expect("a table");
+ let tabled = [shader.pass(&Default::default(), &[], 1.0, Some(std::sync::Arc::new(green)))];
+ let out = gpu.composite(4, 4, &[Layer::new(&red).with_passes(&tabled)]);
+ assert_eq!(&out.pixels()[..3], &[0, 255, 0]);
+ let plain = [shader.pass(&Default::default(), &[], 1.0, None)];
+ let out = gpu.composite(4, 4, &[Layer::new(&red).with_passes(&plain)]);
+ assert_eq!(&out.pixels()[..3], &[255, 0, 0]);
+ }
+
fn gpu() -> Option<WgpuCompositor> {
let compositor = WgpuCompositor::new();
if compositor.is_none() {
diff --git a/engine/crates/concat/Cargo.toml b/engine/crates/concat/Cargo.toml
index 114bfb7f..9456f0f2 100644
--- a/engine/crates/concat/Cargo.toml
+++ b/engine/crates/concat/Cargo.toml
@@ -79,6 +79,9 @@ slint = { version = "1.17", default-features = false, features = [
] }
[dependencies]
+# Writes the card still an imported look gets, rendered here from the
+# reference picture through the table.
+png = "0.17"
# The one device: created in gpu.rs, handed to Slint and to the monitor.
wgpu.workspace = true
pollster.workspace = true
diff --git a/engine/crates/concat/locales/en.json b/engine/crates/concat/locales/en.json
index 62ec8dae..fe5953dc 100644
--- a/engine/crates/concat/locales/en.json
+++ b/engine/crates/concat/locales/en.json
@@ -126,6 +126,7 @@
"Copied": "Copied",
"Copy": "Copy",
"Copy system information": "Copy system information",
+ "Could not import {0}: {1}": "Could not import {0}: {1}",
"Could not save: {0}": "Could not save: {0}",
"Could not show the file: {0}": "Could not show the file: {0}",
"Create": "Create",
@@ -258,10 +259,13 @@
"Hindi": "Hindi",
"Horizontal": "Horizontal",
"Images": "Images",
+ "Import a LUT (.cube)": "Import a LUT (.cube)",
+ "Import LUT": "Import LUT",
"Import media": "Import media",
"Import media…": "Import media…",
"Imported 1 file": "Imported 1 file",
"Imported {0} files": "Imported {0} files",
+ "Imported {0} look(s); find them under Imported": "Imported {0} look(s); find them under Imported",
"Importing…": "Importing…",
"In": "In",
"In and Out play over the clip's first and last seconds; Combo runs its whole length. Each moves the clip from where you placed it, so position it first.": "In and Out play over the clip's first and last seconds; Combo runs its whole length. Each moves the clip from where you placed it, so position it first.",
@@ -308,6 +312,7 @@
"Low light opened up: shadows lifted, the darks softened so the noise does not come up with them, the blue kept.": "Low light opened up: shadows lifted, the darks softened so the noise does not come up with them, the blue kept.",
"Lower and fuller.": "Lower and fuller.",
"Lower third": "Lower third",
+ "LUT": "LUT",
"Magenta in the shadows, cyan in the highlights, hard contrast and colour turned up. Night streets and signage.": "Magenta in the shadows, cyan in the highlights, hard contrast and colour turned up. Night streets and signage.",
"male": "male",
"Mask": "Mask",
diff --git a/engine/crates/concat/src/lib.rs b/engine/crates/concat/src/lib.rs
index 82ab62f2..3a2472de 100644
--- a/engine/crates/concat/src/lib.rs
+++ b/engine/crates/concat/src/lib.rs
@@ -60,6 +60,12 @@ pub fn run() -> Result<(), slint::PlatformError> {
}
};
+ // The user's own packages - imported looks - sit beside the built-ins
+ // from the first frame. One that will not load is reported and skipped.
+ for error in concat_effects::Catalogue::install(&Studio::looks_dir(&host.dirs)) {
+ eprintln!("concat: look: {error}");
+ }
+
let app = App::new()?;
app.set_macos(platform::MACOS);
@@ -449,6 +455,9 @@ pub fn run() -> Result<(), slint::PlatformError> {
editor.on_library_save_template(on_window!(|state| {
state.save_template();
}));
+ editor.on_library_import_lut(on_window!(|state| {
+ state.import_lut();
+ }));
// ── the inspector's effect stacks ──
editor.on_add_effect(on_window!(|state, _audio: bool| {
diff --git a/engine/crates/concat/src/studio.rs b/engine/crates/concat/src/studio.rs
index 8dcf0f9d..6dd61409 100644
--- a/engine/crates/concat/src/studio.rs
+++ b/engine/crates/concat/src/studio.rs
@@ -699,6 +699,11 @@ pub struct Studio {
/// card is double-clicked or its plus pressed, which lays a filter
/// layer at the playhead.
audition: Option<String>,
+ /// The card stills of the user's own looks, by package id, loaded once
+ /// from the package folder's `preview.png` and kept: the shelves are
+ /// rebuilt on every publish and a picture read from disk each time
+ /// would be the slowest thing in the window.
+ look_art: std::cell::RefCell<HashMap<String, slint::Image>>,
/// The last inspector commit: what it changed and when. A control that
/// is dragged commits on every move, and each of those would be an undo
/// step of its own; a commit that changes the same thing as the last
@@ -783,6 +788,7 @@ fn shelves(
kind: PackageKind,
view: &LibraryView,
favourites: &[String],
+ look_art: &std::cell::RefCell<HashMap<String, slint::Image>>,
) -> (Vec<SharedString>, Vec<CatalogueEntryData>) {
let mut groups: Vec<String> = Vec::new();
let mut entries = Vec::new();
@@ -827,6 +833,18 @@ fn shelves(
if !shown {
continue;
}
+ // A user's look brings its own still, read once from its folder;
+ // a built-in's is compiled into the window and looked up by id there.
+ let art = match &package.folder {
+ Some(folder) => look_art
+ .borrow_mut()
+ .entry(meta.id.clone())
+ .or_insert_with(|| {
+ slint::Image::load_from_path(&folder.join("preview.png")).unwrap_or_default()
+ })
+ .clone(),
+ None => slint::Image::default(),
+ };
entries.push(CatalogueEntryData {
id: meta.id.as_str().into(),
name: name.into(),
@@ -834,6 +852,7 @@ fn shelves(
group: group as i32,
description: description.into(),
favourite: starred,
+ art,
});
}
(
@@ -961,6 +980,81 @@ fn set_slot(
/// The built-in colour package's id; see `adjust_rows` and `Studio::adjust_set`.
const ADJUST_ID: &str = "concat.adjust";
+/// The picture every look's card is rendered from.
+const REFERENCE_STILL: &[u8] = include_bytes!("../ui/assets/effect-previews/sharpen.jpg");
+
+/// Makes a package folder under `dir` from the table at `path`, and
+/// returns the package's id. The id is `user.` and the file's name slugged;
+/// a second import of the same name replaces the first.
+fn import_cube(dir: &std::path::Path, path: &std::path::Path) -> Result<String, String> {
+ let stem = path
+ .file_stem()
+ .map(|stem| stem.to_string_lossy().into_owned())
+ .unwrap_or_default();
+ let mut slug: String = stem
+ .to_lowercase()
+ .chars()
+ .map(|c| if c.is_ascii_alphanumeric() { c } else { '-' })
+ .collect::<String>()
+ .split('-')
+ .filter(|part| !part.is_empty())
+ .collect::<Vec<_>>()
+ .join("-");
+ if slug.is_empty() {
+ slug = "look".to_owned();
+ }
+ let id = format!("user.{slug}");
+ let text = std::fs::read_to_string(path).map_err(|error| error.to_string())?;
+ let lut = concat_effects::cube::parse(&text)?;
+ let folder = dir.join(&id);
+ std::fs::create_dir_all(&folder).map_err(|error| error.to_string())?;
+ let name = stem.trim().to_owned();
+ let manifest = format!(
+ "[effect]\nid = \"{id}\"\nname = {name:?}\nkind = \"filter\"\ncategory = \"Imported\"\n\
+ description = \"A look imported from a .cube table.\"\n\n[lut]\nfile = \"look.cube\"\n\n\
+ [ffmpeg]\nchain = \"lut3d=file={{lut}}\"\n\n[wgsl]\nentry = \"effect.wgsl\"\n"
+ );
+ std::fs::write(folder.join("effect.toml"), manifest).map_err(|error| error.to_string())?;
+ std::fs::write(
+ folder.join("effect.wgsl"),
+ "// The table, and nothing else; the host mixes it by intensity.\n\
+ fn effect(uv: vec2<f32>) -> vec4<f32> {\n let c = sample(uv);\n return vec4<f32>(lut(c.rgb), c.a);\n}\n",
+ )
+ .map_err(|error| error.to_string())?;
+ std::fs::write(folder.join("look.cube"), &text).map_err(|error| error.to_string())?;
+ // The card still: the reference picture through the table, the same
+ // arithmetic the GPU's sampler does. Read through Slint's decoder from
+ // a copy on disk, since the bytes live in the binary.
+ let reference = dir.join("reference.jpg");
+ if !reference.is_file() {
+ std::fs::write(&reference, REFERENCE_STILL).map_err(|error| error.to_string())?;
+ }
+ let image = slint::Image::load_from_path(&reference).map_err(|error| error.to_string())?;
+ let Some(pixels) = image.to_rgba8() else {
+ return Err("the reference picture would not decode".to_owned());
+ };
+ let (width, height) = (pixels.width(), pixels.height());
+ let mut out = Vec::with_capacity((width * height * 4) as usize);
+ for pixel in pixels.as_slice() {
+ let rgb = lut.sample([
+ f32::from(pixel.r) / 255.0,
+ f32::from(pixel.g) / 255.0,
+ f32::from(pixel.b) / 255.0,
+ ]);
+ for channel in rgb {
+ out.push((channel.clamp(0.0, 1.0) * 255.0).round() as u8);
+ }
+ out.push(255);
+ }
+ let file = std::fs::File::create(folder.join("preview.png")).map_err(|error| error.to_string())?;
+ let mut encoder = png::Encoder::new(std::io::BufWriter::new(file), width, height);
+ encoder.set_color(png::ColorType::Rgba);
+ encoder.set_depth(png::BitDepth::Eight);
+ let mut writer = encoder.write_header().map_err(|error| error.to_string())?;
+ writer.write_image_data(&out).map_err(|error| error.to_string())?;
+ Ok(id)
+}
+
/// The ease a key put on at `at` inherits: that of whichever key it joins
/// behind, so laying a run of keys down does not alternate between shapes.
/// The first key on a parameter has nothing to inherit and gets the
@@ -1199,6 +1293,7 @@ impl Studio {
stage_guides: Vec::new(),
inspector_jump: (0, "", ""),
audition: None,
+ look_art: std::cell::RefCell::new(HashMap::new()),
last_commit: None,
title_blocks: HashMap::new(),
drop: None,
@@ -4903,6 +4998,46 @@ impl Studio {
}
/// Packs the open project into the template library.
+ /// Where the user's own looks live: one package folder each.
+ pub fn looks_dir(dirs: &concat_host::dirs::AppDirs) -> std::path::PathBuf {
+ dirs.config.join("effects")
+ }
+
+ /// Imports one or more `.cube` tables as looks: each becomes a package
+ /// folder under `looks_dir` - a manifest that names the table and a
+ /// shader that reads it - with a card still rendered through the table
+ /// here, and the catalogue is rebuilt so the Filters page shows them.
+ pub fn import_lut(&mut self) {
+ let Some(paths) = crate::platform::pick_files(&t("Import LUT"), Some((t("LUT").as_str(), &["cube"])))
+ else {
+ return;
+ };
+ let dir = Self::looks_dir(&self.host.dirs);
+ let mut imported = 0;
+ for path in paths {
+ match import_cube(&dir, &path) {
+ Ok(id) => {
+ self.look_art.borrow_mut().remove(&id);
+ imported += 1;
+ }
+ Err(error) => {
+ self.notify(&tf("Could not import {0}: {1}", &[&path.display(), &error]), true);
+ }
+ }
+ }
+ if imported == 0 {
+ return;
+ }
+ for error in Catalogue::install(&dir) {
+ eprintln!("concat: look: {error}");
+ }
+ self.library[0].query.clear();
+ self.notify(
+ &tf("Imported {0} look(s); find them under Imported", &[&imported]),
+ false,
+ );
+ }
+
pub fn save_template(&mut self) {
let Some(session) = self.session.as_ref() else {
return;
@@ -5610,13 +5745,13 @@ impl Studio {
// through, so they are rebuilt here and `sync` makes an unchanged
// one a no-op.
let starred = &self.prefs.favourites;
- let (groups, entries) = shelves(SHELF_KINDS[0], &self.library[0], starred);
+ let (groups, entries) = shelves(SHELF_KINDS[0], &self.library[0], starred, &self.look_art);
sync(&models.filter_groups, groups);
sync(&models.catalogue_filters, entries);
- let (groups, entries) = shelves(SHELF_KINDS[1], &self.library[1], starred);
+ let (groups, entries) = shelves(SHELF_KINDS[1], &self.library[1], starred, &self.look_art);
sync(&models.effect_groups, groups);
sync(&models.catalogue_effects, entries);
- let (groups, entries) = shelves(SHELF_KINDS[2], &self.library[2], starred);
+ let (groups, entries) = shelves(SHELF_KINDS[2], &self.library[2], starred, &self.look_art);
sync(&models.audio_groups, groups);
sync(&models.catalogue_audio, entries);
app.global::<Library>()
diff --git a/engine/crates/concat/ui/editor.slint b/engine/crates/concat/ui/editor.slint
index 263943d2..066fb4fb 100644
--- a/engine/crates/concat/ui/editor.slint
+++ b/engine/crates/concat/ui/editor.slint
@@ -104,6 +104,8 @@ export global Editor {
in-out property <string> library-audition;
callback library-apply-audio(effect-id: string);
callback library-save-template();
+ /// Filters page: import `.cube` tables as looks of the user's own.
+ callback library-import-lut();
// ── the inspector ──
in-out property <SelectedClipData> selected-clip;
diff --git a/engine/crates/concat/ui/inspector/clip-inspector.slint b/engine/crates/concat/ui/inspector/clip-inspector.slint
index 1d6f79ad..0f319af5 100644
--- a/engine/crates/concat/ui/inspector/clip-inspector.slint
+++ b/engine/crates/concat/ui/inspector/clip-inspector.slint
@@ -54,6 +54,10 @@ export struct CatalogueEntryData {
category: string,
group: int,
description: string,
+ /// The card's still, when the package brings its own - a user's
+ /// imported look does. Empty for a built-in, whose still the pane
+ /// looks up by id.
+ art: image,
}
/// What one effect library is currently showing.
diff --git a/engine/crates/concat/ui/workspace/media-pane.slint b/engine/crates/concat/ui/workspace/media-pane.slint
index 13544881..1bf2768a 100644
--- a/engine/crates/concat/ui/workspace/media-pane.slint
+++ b/engine/crates/concat/ui/workspace/media-pane.slint
@@ -1118,7 +1118,8 @@ component ShelfGrid inherits Rectangle {
property <length> gap: 8px;
property <length> min-card: 88px;
- property <bool> compact: root.entries.length > 0 && root.art(root.entries[0].id).width == 0;
+ property <bool> compact: root.entries.length > 0
+ && root.art(root.entries[0].id).width == 0 && root.entries[0].art.width == 0;
property <int> cols: Math.max(1,
Math.floor((root.width + root.gap) / (root.min-card + root.gap)));
@@ -1138,7 +1139,7 @@ component ShelfGrid inherits Rectangle {
id: entry.id,
label: entry.name,
enabled: true,
- art: root.art(entry.id),
+ art: entry.art.width > 0 ? entry.art : root.art(entry.id),
glyph: root.glyph,
};
compact: root.compact;
@@ -1280,6 +1281,8 @@ export component MediaPane inherits Rectangle {
callback apply-audio(effect-id: string);
/// Templates page: open the save-as-template flow for this project.
callback save-template();
+ /// Filters page: bring in `.cube` tables as looks of the user's own.
+ callback import-lut();
/// The corner button: show something else in this pane's seat.
callback pane-picked(kind: PaneKind);
@@ -1866,6 +1869,14 @@ export component MediaPane inherits Rectangle {
shelf: 0;
placeholder: I18n.t1("Search {0}s", I18n.t("filter"));
}
+ // A table from any grading tool becomes a look here, the
+ // way it does on every desktop editor's Filters page.
+ ImportButton {
+ label: I18n.t("Import a LUT (.cube)");
+ glyph: Glyph.import;
+ clicked => { root.import-lut(); }
+ }
+ Rectangle { height: 8px; }
ShelfGrid {
entries: root.catalogue-filters;
payload-kind: "filter";
diff --git a/engine/crates/concat/ui/workspace/seat.slint b/engine/crates/concat/ui/workspace/seat.slint
index 7345f9b2..cd362afa 100644
--- a/engine/crates/concat/ui/workspace/seat.slint
+++ b/engine/crates/concat/ui/workspace/seat.slint
@@ -130,6 +130,7 @@ export component Seat inherits Rectangle {
audition-filter(id) => { Editor.library-audition-filter(id); }
apply-audio(id) => { Editor.library-apply-audio(id); }
save-template => { Editor.library-save-template(); }
+ import-lut => { Editor.library-import-lut(); }
}
if root.kind == PaneKind.preview: PreviewPane {