Merge remote-tracking branch 'upstream/main' into footage-cache-3271

# Conflicts:
#	crates/effects/src/lib.rs
This commit is contained in:
vangel76 committed 2026-11-08 16:16:21 +01:00
commit cbaa68321c
48 files changed
+1816 -99

No files matched your search

+46 -13
View File
@@ -98,7 +98,13 @@ pub fn aux_needs(id: &str, params: &crate::Params) -> Option<Vec<AuxLookup>> {
"ec.3d.cryptomatte" => vec![AuxLookup::Crypto { name: params.s("layerName").to_string(), index: params.e("layer") as usize }],
// (an empty name reads the layer's own channel)
"ec.3d.extractor" => {
["red", "green", "blue", "alpha"].iter().map(|k| params.s(k).trim()).filter(|n| !n.is_empty()).map(|n| AuxLookup::Name(n.to_string())).collect()
// (`(copy)` reads the input's own channel, no footage channel)
["red", "green", "blue", "alpha"]
.iter()
.map(|k| params.s(k).trim())
.filter(|n| !n.is_empty() && !is_extractor_copy(n))
.map(|n| AuxLookup::Name(n.to_string()))
.collect()
}
_ => return None,
})
@@ -636,6 +642,39 @@ fn cryptomatte(ctx: &EffectCtx, mut b: Buf) -> Buf {
// ---------------------------------------------------------------- EXtractoR
/// EXtractoR's channel name for After Effects' `(copy)`: the effect input's own channel of the
/// same position (red's red ... alpha's alpha), as the earlier effects left it, never a footage
/// channel of some name (an OpenEXR's `A` is the file's alpha, not the input's).
pub const EXTRACTOR_COPY: &str = "(copy)";
/// Whether an EXtractoR channel name is [`EXTRACTOR_COPY`].
pub fn is_extractor_copy(name: &str) -> bool {
name.trim().eq_ignore_ascii_case(EXTRACTOR_COPY)
}
/// The layer's own channel an EXtractoR output channel at position `k` reads when no footage
/// channel of that name exists: `R`/`G`/`B`/`A` (or the long names) by name, [`EXTRACTOR_COPY`]
/// its own position.
pub fn extractor_own_channel(k: usize, name: &str) -> Option<usize> {
if is_extractor_copy(name) {
return (k < 4).then_some(k);
}
match name.trim().to_ascii_uppercase().as_str() {
"R" | "RED" => Some(0),
"G" | "GREEN" => Some(1),
"B" | "BLUE" => Some(2),
"A" | "ALPHA" => Some(3),
_ => None,
}
}
/// The footage channel an EXtractoR output channel reads by name: none for an empty name or
/// [`EXTRACTOR_COPY`] (the input's own channel).
pub fn extractor_aux_channel<'a>(a: &'a AuxChannels, name: &str) -> Option<&'a [f32]> {
let n = name.trim();
if n.is_empty() || is_extractor_copy(n) { None } else { a.get(n) }
}
fn extractor(ctx: &EffectCtx, mut b: Buf) -> Buf {
let a = aux(ctx);
let names = [ctx.params.s("red"), ctx.params.s("green"), ctx.params.s("blue"), ctx.params.s("alpha")];
@@ -643,17 +682,11 @@ fn extractor(ctx: &EffectCtx, mut b: Buf) -> Buf {
let unmult = ctx.params.b("unMult");
let clip = ctx.params.b("clip");
let idx = a.as_ref().map(|a| index_map(&b, a));
// Each output channel: an aux channel by name, or the layer's own R/G/B/A.
let own = |n: &str| match n.trim().to_ascii_uppercase().as_str() {
"R" | "RED" => Some(0),
"G" | "GREEN" => Some(1),
"B" | "BLUE" => Some(2),
"A" | "ALPHA" => Some(3),
"" => None,
_ => None,
};
let src_ch: Vec<Option<&[f32]>> = names.iter().map(|n| a.as_ref().and_then(|a| if n.trim().is_empty() { None } else { a.get(n.trim()) })).collect();
if src_ch.iter().all(Option::is_none) && bp == 0.0 && wp == 1.0 && !unmult && names.iter().enumerate().all(|(k, n)| own(n) == Some(k)) {
// Each output channel: an aux channel by name, or the layer's own R/G/B/A (`(copy)`: its
// own position, never an aux channel).
let own = |k: usize, n: &str| extractor_own_channel(k, n);
let src_ch: Vec<Option<&[f32]>> = names.iter().map(|n| a.as_ref().and_then(|a| extractor_aux_channel(a, n))).collect();
if src_ch.iter().all(Option::is_none) && bp == 0.0 && wp == 1.0 && !unmult && names.iter().enumerate().all(|(k, n)| own(k, n) == Some(k)) {
return b;
}
let src = b.img.clone();
@@ -669,7 +702,7 @@ fn extractor(ctx: &EffectCtx, mut b: Buf) -> Buf {
o[k] = match (src_ch[k], idx.as_ref().and_then(|m| m[i])) {
(Some(ch), Some(j)) => ch[j],
(Some(_), None) => 0.0,
(None, _) => match own(names[k]) {
(None, _) => match own(k, names[k]) {
Some(c) => straight[c],
None => {
if k == 3 {
+32
View File
@@ -457,6 +457,38 @@ fn extractor_maps_named_channels() {
assert_eq!(s.img.get(0, 0), [1.0, 0.3, 0.4, 1.0]);
}
/// `(copy)` (After Effects' EXtractoR choice, imported from .aep) is the effect input's own
/// channel as earlier effects left it, never the OpenEXR's plane of the same name: here the input
/// buffer differs from the footage's R, G, B and A planes, as after an earlier effect.
#[test]
fn extractor_copy_reads_the_current_input_not_the_footage_plane() {
let (w, h) = (4usize, 3usize);
let mut a = AuxChannels::new(w as u32, h as u32, 1.0);
// The file's own planes (what the footage held before any effect) and a depth channel.
a.channels = ["R", "G", "B", "A"].iter().map(|n| (n.to_string(), vec![0.9; w * h])).collect();
a.channels.push(("Z".into(), vec![0.7; w * h]));
let host = AuxHost(Arc::new(a));
let env = || EffectEnv { host: Some(&host), ..Default::default() };
// The input after an earlier effect: straight (0.2, 0.3, 0.4) at alpha 0.5, premultiplied.
let input = Image::filled(w as u32, h as u32, [0.1, 0.15, 0.2, 0.5]);
let copy = || Value::Str(EXTRACTOR_COPY.into());
// All four `(copy)`: the input unchanged.
let all = [("red", copy()), ("green", copy()), ("blue", copy()), ("alpha", copy())];
let o = run_fx("ec.3d.extractor", &all, input.clone(), 0.0, env()).img;
assert_eq!(o.data, input.data);
// Mixed with a named channel (no pass-through): red from Z, green and alpha copied, blue the
// footage's B plane.
let vals = [("red", Value::Str("Z".into())), ("green", copy()), ("blue", Value::Str("B".into())), ("alpha", copy())];
let px = run_fx("ec.3d.extractor", &vals, input.clone(), 0.0, env()).img.get(1, 1);
let want = [0.7 * 0.5, 0.3 * 0.5, 0.9 * 0.5, 0.5];
for (c, (got, want)) in px.iter().zip(want).enumerate() {
assert!((got - want).abs() < 1e-6, "channel {c}: {got} != {want} ({px:?})");
}
// `A` by name is the footage's alpha plane (0.9), not the input's alpha (0.5).
let named = [("alpha", Value::Str("A".into())), ("red", Value::Str("Z".into()))];
assert!((run_fx("ec.3d.extractor", &named, input, 0.0, env()).img.get(1, 1)[3] - 0.9).abs() < 1e-6);
}
#[test]
fn channel_extract_antialias_averages_sub_pixels() {
// Depth at twice the layer resolution, alternating 0 / 1000 per aux column.
+3 -2
View File
@@ -116,8 +116,9 @@ pub use time_fx::{PixelMotion, TimewarpPlan, TwStep, pmb_plan, posterized_time,
pub use ocio::color_stabilizer_maps;
// GPU effects, part B (3D Channel, Immersive Video, colour management, simulation render passes).
pub use channel3d::{
CRYPTO_LAYERS, CryptoAux, MATTE_ONLY_IN_ALPHA, aux_need, aux_needs, aux_point, crypto_aux_image, crypto_aux_image_with, crypto_layer_choices,
crypto_layer_menu, crypto_layer_name, crypto_layer_named, id_color, matte_only_px, pixel_margin, reads_aux, selection_hashes,
CRYPTO_LAYERS, CryptoAux, EXTRACTOR_COPY, MATTE_ONLY_IN_ALPHA, aux_need, aux_needs, aux_point, crypto_aux_image, crypto_aux_image_with,
crypto_layer_choices, crypto_layer_menu, crypto_layer_name, crypto_layer_named, extractor_aux_channel, extractor_own_channel, id_color,
is_extractor_copy, matte_only_px, pixel_margin, reads_aux, selection_hashes,
};
pub use ocio::{ColorOp, Straight, Tf, color_program};
pub use sim::{Acc, Blob, Bubble, Post, Shape, Sprite, SpritePlan, Tint, bubble_list, bubble_sample_bounds, drizzle_drops, mercury_blobs, sprite_plan};