Skip to content

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

Give every filter an intensity

Jareer02455da1d410
diff --git a/engine/crates/concat-effects/src/catalogue.rs b/engine/crates/concat-effects/src/catalogue.rs
index d781bddd..a3966d23 100644
--- a/engine/crates/concat-effects/src/catalogue.rs
+++ b/engine/crates/concat-effects/src/catalogue.rs
@@ -27,6 +27,40 @@ struct Chain {
template: Template,
}
+/// The key every filter answers to without declaring it: how much of the
+/// look is applied, as a percent. Absent means all of it.
+pub const INTENSITY: &str = "intensity";
+
+/// A filter's fragment, mixed back with the untouched picture by its
+/// intensity. At a hundred the fragment is returned as it was; below it the
+/// picture is split, the look runs on one copy, and the two are blended by
+/// the fraction - which is what one intensity slider means on every look
+/// there is, and why no package has to implement it. The labels carry the
+/// fragment's index so two mixed links in one chain never share a name.
+fn mixed(
+ package: &Package,
+ params: &BTreeMap<String, f64>,
+ fragment: String,
+ index: usize,
+) -> String {
+ if package.kind() != Kind::Filter {
+ return fragment;
+ }
+ let mix = params
+ .get(INTENSITY)
+ .copied()
+ .unwrap_or(100.0)
+ .clamp(0.0, 100.0)
+ / 100.0;
+ if mix >= 1.0 {
+ return fragment;
+ }
+ format!(
+ "split[m{index}a][m{index}b];[m{index}b]{fragment}[m{index}c];\
+ [m{index}a][m{index}c]blend=all_mode=normal:all_opacity={mix:.3}"
+ )
+}
+
/// One effect, ready to use.
#[derive(Clone, Debug)]
pub struct Package {
@@ -437,7 +471,10 @@ impl Catalogue {
continue;
}
match package.ffmpeg_fragment(&applied.params, fragments.len()) {
- Ok(Some(fragment)) => fragments.push(fragment),
+ Ok(Some(fragment)) => {
+ let index = fragments.len();
+ fragments.push(mixed(package, &applied.params, fragment, index));
+ }
Ok(None) => {}
// Every template was rendered at load; a failure here is a
// package whose expression only breaks for some value. Drop
diff --git a/engine/crates/concat-effects/src/lib.rs b/engine/crates/concat-effects/src/lib.rs
index dbec4bdf..02ccc8a6 100644
--- a/engine/crates/concat-effects/src/lib.rs
+++ b/engine/crates/concat-effects/src/lib.rs
@@ -71,6 +71,30 @@ mod tests {
}
}
+ /// A filter below full intensity is split, looked at on one copy and
+ /// blended back; at full intensity it is the bare fragment. An effect
+ /// never mixes: intensity is a filter's word.
+ #[test]
+ fn a_filter_mixes_by_its_intensity_and_an_effect_does_not() {
+ let catalogue = Catalogue::builtin();
+ let full = catalogue.video_chain(&[applied("concat.warm", &[])]);
+ assert_eq!(full, "colortemperature=temperature=4600");
+ let half = catalogue.video_chain(&[
+ applied("concat.sepia", &[]),
+ applied("concat.warm", &[("intensity", 50.0)]),
+ ]);
+ assert!(half.starts_with("colorchannelmixer"), "{half}");
+ assert!(
+ half.ends_with(
+ "split[m1a][m1b];[m1b]colortemperature=temperature=4600[m1c];\
+ [m1a][m1c]blend=all_mode=normal:all_opacity=0.500"
+ ),
+ "{half}"
+ );
+ let effect = catalogue.video_chain(&[applied("concat.sepia", &[("intensity", 50.0)])]);
+ assert!(!effect.contains("blend"), "{effect}");
+ }
+
#[test]
fn every_built_in_package_loads_and_its_fixtures_pass() {
let catalogue = Catalogue::builtin();
diff --git a/engine/crates/concat/src/studio.rs b/engine/crates/concat/src/studio.rs
index c87be8df..b6544f48 100644
--- a/engine/crates/concat/src/studio.rs
+++ b/engine/crates/concat/src/studio.rs
@@ -703,6 +703,25 @@ fn chain_rows(chain: &[AppliedFilter]) -> (Vec<AppliedEntryData>, Vec<AppliedPar
if package.id() == ADJUST_ID {
continue;
}
+ // Every filter has an intensity whether or not it says so: the one
+ // slider a look is expected to have. First, above the look's own.
+ if package.kind() == PackageKind::Filter {
+ knobs.push(AppliedParamData {
+ entry: index as i32,
+ key: concat_effects::catalogue::INTENSITY.into(),
+ label: "Intensity".into(),
+ min: 0.0,
+ max: 100.0,
+ step: 1.0,
+ default_value: 100.0,
+ value: entry
+ .params
+ .get(concat_effects::catalogue::INTENSITY)
+ .copied()
+ .unwrap_or(100.0) as f32,
+ fmt: ParamFormat::Percent,
+ });
+ }
for param in &package.manifest.params {
let step = if param.step > 0.0 {
param.step