Effects: EXtractoR picks layers and channels of multi-layer EXRs (#295)

EXtractoR's Red, Green, Blue and Alpha are text parameters naming
channels, and Effect Controls drew nothing for text parameters: there
was no way to choose a layer or channel. And a multi-layer OpenEXR file
whose colour is only in named layers (`diffuse.R`, Blender's
`ViewLayer.Combined.R`) didn't import at all: the image decoder wants an
unnamed RGB layer ("does not contain non-deep rgb channels").

- Effect Controls: EXtractoR gets a Layer popup listing the footage's
  OpenEXR layers. Picking one sets red, green, blue and alpha to its
  channels in one undo step, as After Effects' EXtractoR dialog does (a
  one-channel layer such as depth goes in all three colours). Red /
  Green / Blue / Alpha are popups of the layer's own R, G, B, A, every
  channel of the file, and (none). The lists are read only while open,
  so playing an EXR sequence doesn't parse files on the UI thread.
- `layer.channels {layer}` lists a layer's EXR layers and channels and
  what each layer shows in red, green, blue and alpha, for agents.
- Media: an EXR without an unnamed RGB layer imports and shows its
  colour layer (one named combined, beauty or rgba first); its channels
  stay available to EXtractoR and the 3D Channel effects.
- Raster: AuxChannels::layers / layer_rgba and split_channel.

Test: extractor_shows_the_chosen_layer_and_channels_of_a_layered_exr
(host: a layered EXR written with the exr crate imports, layer.channels,
EXtractoR renders spec and depth; it failed to import before),
extractor_offers_the_exr_layers_and_channels (UI: Layer popup, one undo
step, channel popup), layered_exr_without_an_unnamed_rgb_layer_imports
(media).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-09 17:32:09 +07:00
co-authored by Claude Opus 5.5
parent a6c72acf94
commit 27cabcb36b
14 changed files with 406 additions and 9 deletions
+7 -2
View File
@@ -380,6 +380,11 @@ fn prop_row(
}
}
}
// EXtractoR's red / green / blue / alpha: a popup of the footage's OpenEXR channels (#295).
Value::Str(s) if super::fx_editors::is_extractor_channel(group, prop) => {
let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((r.max.x - vx - 56.0).clamp(80.0, 200.0), 18.0));
super::fx_editors::channel_popup(app, ui, layer, prop, s, dr, actions);
}
Value::Gradient(g) => {
let gr = Rect::from_min_size(pos2(vx, cy - 7.0), vec2((r.max.x - vx - 56.0).clamp(60.0, 180.0), 14.0));
let n = 48;
@@ -652,7 +657,7 @@ fn roto_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, l
/// Height of the custom editor shown under an effect's header (0 when none).
fn editor_height(effect: &str, g: &PropGroup, width: f32) -> f32 {
match effect {
super::fx_editors::GLOW | super::fx_editors::RESHAPE => super::fx_editors::header_height(effect, g, width),
super::fx_editors::GLOW | super::fx_editors::RESHAPE | super::fx_editors::EXTRACTOR => super::fx_editors::header_height(effect, g, width),
"ec.color.curves" => 34.0 + curves_size(width) + 26.0,
effectcraft_engine::effects::warp_stab::ID => 50.0,
effectcraft_engine::effects::camera_tracker::ID => super::camera_tracker_ui::EDITOR_HEIGHT,
@@ -1050,7 +1055,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
effectcraft_engine::effects::camera_tracker::ID => super::camera_tracker_ui::editor(app, ui, &bp, &layer, g, er, &mut actions),
effectcraft_engine::effects::roto::ID => roto_editor(app, ui, &bp, &layer, g, er, &mut actions),
"ec.color.levels" | "ec.color.levelsic" => levels_editor(app, ui, &bp, &layer, g, effect, &ectx, er, &mut actions),
super::fx_editors::GLOW | super::fx_editors::RESHAPE => {
super::fx_editors::GLOW | super::fx_editors::RESHAPE | super::fx_editors::EXTRACTOR => {
super::fx_editors::header_editor(app, ui, &bp, &layer, g, effect, &ectx, er, &mut actions)
}
_ => histogram_only(app, ui, &bp, g, er),
+116 -2
View File
@@ -9,7 +9,9 @@
//! - Glow: the colour map (A & B Colors: a preview strip of the gradient over glow brightness;
//! Arbitrary Map: red / green / blue curve graphs and the resulting strip);
//! - Reshape: correspondence point list buttons here, and on the Composition viewer the source
//! and destination mask outlines with draggable correspondence handles ([`reshape_overlay`]).
//! and destination mask outlines with draggable correspondence handles ([`reshape_overlay`]);
//! - EXtractoR: a Layer popup of the footage's OpenEXR layers, and Red / Green / Blue / Alpha
//! popups of its channels ([`channel_popup`]).
//!
//! Every edit is a `prop.set` engine command (undoable; one drag = one undo step) and every
//! handle registers an automation id.
@@ -17,7 +19,7 @@
use effectcraft_engine::effects::{ColoramaPalette, OffsetCurve};
use effectcraft_engine::geom::Mat3;
use effectcraft_engine::keyframe::Value;
use effectcraft_engine::project::{Layer, PropGroup};
use effectcraft_engine::project::{GroupKind, Layer, PropGroup};
use effectcraft_engine::render::EvalCtx;
use egui::{Align2, Color32, Pos2, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
use serde_json::json;
@@ -33,6 +35,7 @@ pub const LUMETRI: &str = "ec.color.lumetri";
pub const COLORAMA: &str = "ec.color.colorama";
pub const GLOW: &str = "ec.stylize.glow";
pub const RESHAPE: &str = "ec.distort.reshape";
pub const EXTRACTOR: &str = "ec.3d.extractor";
fn str_value(layer: &Layer, ectx: &EvalCtx, g: &PropGroup, id: &str) -> String {
match g.get(id).map(|p| ectx.value(layer, p)) {
@@ -609,6 +612,7 @@ pub fn header_height(effect: &str, g: &PropGroup, width: f32) -> f32 {
_ => 0.0,
},
RESHAPE => 50.0,
EXTRACTOR => 30.0,
_ => 0.0,
}
}
@@ -628,6 +632,7 @@ pub fn header_editor(
match effect {
GLOW => glow_map(app, ui, p, layer, g, ectx, r, actions),
RESHAPE => reshape_buttons(app, ui, p, layer, g, ectx, r, actions),
EXTRACTOR => extractor_layers(app, ui, p, layer, g, ectx, r, actions),
_ => {}
}
}
@@ -795,6 +800,115 @@ fn reshape_buttons(
p.text(pos2(r.min.x + 24.0, r.min.y + 38.0), Align2::LEFT_CENTER, status, Tokens::ui(11.5), t.text_dim);
}
// ---------------------------------------------------------------------------------------------
// EXtractoR: the layer's OpenEXR layers and channels
/// EXtractoR's channel parameters, shown in red, green, blue and alpha.
const EXTRACTOR_CHANNELS: [&str; 4] = ["red", "green", "blue", "alpha"];
/// What an empty channel name shows.
const NO_CHANNEL: &str = "(none)";
/// Whether `prop` (in group `g`) is one of EXtractoR's channel parameters.
pub fn is_extractor_channel(g: &PropGroup, prop: &effectcraft_engine::project::Property) -> bool {
matches!(&g.kind, GroupKind::Effect { effect } if effect == EXTRACTOR) && EXTRACTOR_CHANNELS.contains(&prop.match_id.as_str())
}
/// The OpenEXR layer EXtractoR's red, green and blue come from (`""`: the unnamed layer), or
/// `None` when they mix layers.
fn extractor_layer(vals: &[String; 4]) -> Option<&str> {
let mut layers = vals[..3].iter().filter(|v| !v.trim().is_empty()).map(|v| effectcraft_engine::raster::channels3d::split_channel(v.trim()).0);
let first = layers.next()?;
layers.all(|l| l == first).then_some(first)
}
/// EXtractoR's Layer popup (above its channels): picking an OpenEXR layer of the footage
/// (`diffuse`, `ViewLayer.Combined`, …) shows its channels in red, green, blue and alpha in one
/// undo step, as After Effects' EXtractoR dialog does.
#[allow(clippy::too_many_arguments)]
fn extractor_layers(
app: &mut EffectcraftApp,
ui: &mut egui::Ui,
p: &egui::Painter,
layer: &Layer,
g: &PropGroup,
ectx: &EvalCtx,
r: Rect,
actions: &mut Actions,
) {
let t = app.tokens;
let euid = g.uid;
let vals = EXTRACTOR_CHANNELS.map(|id| str_value(layer, ectx, g, id));
let label = match extractor_layer(&vals) {
Some("") => "RGBA".to_string(),
Some(l) => l.to_string(),
None => "Custom".to_string(),
};
// Lined up with the parameter names and value popups below (Effect Controls' row layout).
p.text(pos2(r.min.x + 37.0, r.center().y), Align2::LEFT_CENTER, "Layer", Tokens::ui(12.0), t.text);
let vx = (r.min.x + r.width() * 0.48).max(r.min.x + 161.0);
let dr = Rect::from_min_size(pos2(vx, r.center().y - 9.0), vec2((r.max.x - vx - 56.0).clamp(80.0, 200.0), 18.0));
let pop = egui::Id::new(("extractor-layers", euid));
if widgets::dropdown(ui, dr, &label, &t, egui::Id::new(("extractor-layer", euid)))
.on_hover_text("The OpenEXR layer shown in red, green, blue and alpha")
.clicked()
{
widgets::open_popup(ui, pop);
}
app.auto.add(&format!("effectControls.effect.{euid}.extractor.layer"), dr, "Layer");
// The footage's layers, read only while the list is open (each frame of a sequence is a file).
if !widgets::popup_is_open(ui, pop) {
return;
}
let aux = app.session.layer_channels(layer.id);
let layers: Vec<&str> = aux.as_ref().map(|a| a.layers()).unwrap_or_default();
let names: Vec<String> = match layers.as_slice() {
[] => vec!["No layers: not a multi-layer OpenEXR file".into()],
_ => layers.iter().map(|l| if l.is_empty() { "RGBA".to_string() } else { l.to_string() }).collect(),
};
let cur = names.iter().position(|n| *n == label);
if let (Some(i), Some(aux)) = (widgets::popup_menu(ui, pop, dr.left_bottom(), &names, cur), aux.as_ref()) {
let Some(l) = layers.get(i) else { return };
let merge = format!("extractor-layer-{euid}-{}", ui.ctx().cumulative_pass_nr());
for (id, v) in EXTRACTOR_CHANNELS.iter().zip(aux.layer_rgba(l)) {
set_str(actions, layer, g, id, v, Some(merge.clone()));
}
}
}
/// An EXtractoR channel popup (in place of a text field): the layer's own R, G, B and A, then
/// every channel of its OpenEXR footage, and (none).
pub fn channel_popup(
app: &mut EffectcraftApp,
ui: &mut egui::Ui,
layer: &Layer,
prop: &effectcraft_engine::project::Property,
cur: &str,
r: Rect,
actions: &mut Actions,
) {
let t = app.tokens;
let uid = prop.uid;
let label = if cur.trim().is_empty() { NO_CHANNEL } else { cur };
let pop = egui::Id::new(("ec-chpop", uid));
if widgets::dropdown(ui, r, label, &t, egui::Id::new(("ec-ch", uid))).clicked() {
widgets::open_popup(ui, pop);
}
app.auto.add(&format!("effectControls.prop.{uid}.value"), r, &prop.name);
if !widgets::popup_is_open(ui, pop) {
return;
}
let mut opts: Vec<String> = ["R", "G", "B", "A"].map(String::from).to_vec();
if let Some(aux) = app.session.layer_channels(layer.id) {
opts.extend(aux.names().into_iter().filter(|n| !opts.iter().any(|o| o.eq_ignore_ascii_case(n))).map(String::from).collect::<Vec<_>>());
}
opts.push(NO_CHANNEL.into());
let sel = opts.iter().position(|o| o.eq_ignore_ascii_case(label));
if let Some(i) = widgets::popup_menu(ui, pop, r.left_bottom(), &opts, sel) {
let v = opts.get(i).filter(|o| *o != NO_CHANNEL).cloned().unwrap_or_default();
actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": v})));
}
}
/// Arc-length fraction (0..1) of the point of a polyline nearest to `q`.
pub fn nearest_fraction(pts: &[[f64; 2]], closed: bool, q: [f64; 2]) -> f64 {
let n = pts.len();