PhotoCraft: An open-source, photo editor written by scratch in pure Rust
File > Export > Color Lookup Tables: export selected adjustment layers (#1493)
Nigel Ihza Firdausyd402631411e4
diff --git a/book/src/automation/cli.md b/book/src/automation/cli.mdindex 6538c14a1..05a7c3da2 100644--- a/book/src/automation/cli.md+++ b/book/src/automation/cli.md@@ -35,6 +35,32 @@ Warnings do not change the saved document's font declarations and do not stopthe operation. To list or replace the missing families intentionally, use`type.resolveMissingFonts` on the document.+### Export selected adjustment layers as a .cube LUT++The engine command `file.export.colorLookupTables` creates a 3D LUT from an+identity RGB lattice. It can export all visible top-level adjustment layers+(the default), the current Layers panel selection, or a supplied list of+adjustment layer IDs. The `scope` and `layers` parameters are mutually+exclusive when `scope` is `selected`:++```json+{"size": 33, "scope": "selected", "path": "chosen-look.cube"}+```++For automation that does not use the Layers panel, supply `"layers": [10, 14]`+instead. Input ID order does not change the final color look: adjustments are+always baked in **document stacking order**, bottom to top. When `path` is+omitted, the command returns the .cube text in `cube`; both forms return+`size` and `layerCount`.++Valid LUT dimensions are 2–129 (same maximum as PhotoCraft's LUT reader).+Selected IDs must exist, be visible top-level adjustment layers, and contain+no duplicates; invalid selections report an error rather than silently+exporting a different look. Masks, vector masks and clipping are spatial+operations and cannot be represented faithfully by a color-only LUT, so the+baker omits them. Group-contained adjustments are not exported as independent+layers because that would lose their group's blending semantics.+Paths supplied to the current CLI are ordinary operating-system paths. The CLI does not restrict them to a workspace root. Batch output creates the requested output directory, and save operations may create parent directories. `batch` refuses an output directory that is its input directory (the results would replace the originals) unless `--in-place` is given. Run untrusted action files only in an appropriately isolated account or environment.CLI parsing reports malformed flags and JSON as errors, and a flag the subcommand doesn't take (a typo such as `--fromat`) is a usage error (exit status 2) rather than being ignored. It is not a security policy layer. Engine commands remain responsible for validating their own parameters.diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rsindex 590f534e4..49aa5b32a 100644--- a/crates/engine/src/file_cmds.rs+++ b/crates/engine/src/file_cmds.rs@@ -935,10 +935,53 @@ fn layers_to_files(s: &mut Session, p: &Value) -> Result<Value> {Ok(json!({"files": files}))}-/// The document's visible top-level adjustment layers applied to an identity lattice, as a-/// `.cube` 3D LUT (red fastest, values 0–1).-pub fn bake_cube(doc: &Document, size: usize, title: &str) -> String {- let n = size.clamp(2, 256);+/// Adjustment layers that can be represented as an RGB-only LUT, in document stack order.+/// A LUT has no spatial coordinates, so masks and clipping geometry are deliberately stripped+/// at bake time. Group adjustments need their enclosing group's compositing semantics and are+/// not silently flattened as independent layers.+fn lut_layers<'a>(doc: &'a Document, ids: Option<&[LayerId]>) -> Result<Vec<&'a Layer>> {+ const CMD: &str = "file.export.colorLookupTables";+ let mut selected = Vec::new();+ if let Some(ids) = ids {+ if ids.is_empty() {+ return Err(EngineError::BadParams { cmd: CMD.into(), msg: "select at least one adjustment layer".into() });+ }+ for id in ids {+ if selected.contains(id) {+ return Err(EngineError::BadParams { cmd: CMD.into(), msg: format!("duplicate layer id {}", id.0) });+ }+ let Some(layer) = doc.layer(*id) else { return Err(EngineError::NoLayer(*id)) };+ if !matches!(layer.content, LayerContent::Adjustment(_)) {+ return Err(EngineError::BadParams { cmd: CMD.into(), msg: format!("layer {} is not an adjustment layer", id.0) });+ }+ if !layer.visible {+ return Err(EngineError::BadParams { cmd: CMD.into(), msg: format!("layer {} is hidden", id.0) });+ }+ if !doc.layers.iter().any(|root| root.id == *id) {+ return Err(EngineError::BadParams {+ cmd: CMD.into(),+ msg: format!("layer {} is nested in a group; export top-level adjustment layers", id.0),+ });+ }+ selected.push(*id);+ }+ }+ let mut layers = Vec::new();+ for l in &doc.layers {+ if l.visible && matches!(l.content, LayerContent::Adjustment(_)) && (ids.is_none() || selected.contains(&l.id)) {+ layers.push(l);+ }+ }+ if layers.is_empty() {+ return Err(EngineError::BadParams { cmd: CMD.into(), msg: "no visible adjustment layers to export".into() });+ }+ Ok(layers)+}++/// Bake the chosen adjustment stack against an identity RGB lattice.+/// Source order always follows the document stack, even if an explicit list is reversed.+fn bake_cube_layers(size: usize, title: &str, layers: &[&Layer]) -> String {+ let n = size;let (w, h) = ((n * n) as u32, n as u32);let mut lattice = Document::new("lut", photocraft_doc::Size::new(w, h), ColorMode::Rgb, photocraft_color::SampleType::F32);let fmt = lattice.pixel_format();@@ -956,8 +999,8 @@ pub fn bake_cube(doc: &Document, size: usize, title: &str) -> String {let mut surf = Surface::new(fmt);surf.write_region(Rect::new(0, 0, w as i32, h as i32), &data);lattice.layers.push(Layer::new("Lattice", LayerContent::Raster(surf)));- for l in doc.layers.iter().filter(|l| l.visible && matches!(l.content, LayerContent::Adjustment(_))) {- let mut a = l.clone();+ for l in layers {+ let mut a = (*l).clone();// Masks and clipping are spatial; a LUT is the adjustment stack's colour mapping.a.mask = None;a.vector_mask = None;@@ -979,17 +1022,58 @@ pub fn bake_cube(doc: &Document, size: usize, title: &str) -> String {s}+/// Backwards-compatible helper for exporting all visible top-level adjustments.+pub fn bake_cube(doc: &Document, size: usize, title: &str) -> String {+ let layers: Vec<&Layer> = doc.layers.iter().filter(|l| l.visible && matches!(l.content, LayerContent::Adjustment(_))).collect();+ bake_cube_layers(size.clamp(2, photocraft_cms::lutfile::MAX_SIZE), title, &layers)+}++/// Export either the whole visible stack (backward-compatible default), the Layers panel's+/// current selection, or an explicit list supplied by scripts/CLI/automation.fn color_lookup_tables(s: &mut Session, p: &Value) -> Result<Value> {+ const CMD: &str = "file.export.colorLookupTables";let d = s.active().ok_or(EngineError::NoDocument)?;- let size = p.get("size").and_then(Value::as_u64).unwrap_or(33) as usize;+ let size = match p.get("size") {+ None | Some(Value::Null) => 33,+ Some(v) => v.as_u64().ok_or_else(|| EngineError::BadParams { cmd: CMD.into(), msg: "size must be an integer".into() })?,+ };+ if !(2..=photocraft_cms::lutfile::MAX_SIZE as u64).contains(&size) {+ return Err(EngineError::BadParams { cmd: CMD.into(), msg: format!("size must be 2..={}", photocraft_cms::lutfile::MAX_SIZE) });+ }+ let scope = match p.get("scope") {+ None | Some(Value::Null) => "all",+ Some(Value::String(s)) => s.as_str(),+ Some(_) => return Err(EngineError::BadParams { cmd: CMD.into(), msg: "scope must be all or selected".into() }),+ };+ if !matches!(scope, "all" | "selected") {+ return Err(EngineError::BadParams { cmd: CMD.into(), msg: "scope must be all or selected".into() });+ }+ if p.get("layers").is_some() && scope == "selected" {+ return Err(EngineError::BadParams { cmd: CMD.into(), msg: "use either layers or scope=selected, not both".into() });+ }+ let explicit: Option<Vec<LayerId>> = if let Some(v) = p.get("layers") {+ let Some(a) = v.as_array() else { return Err(EngineError::BadParams { cmd: CMD.into(), msg: "layers must be an array of layer IDs".into() }) };+ let mut out = Vec::with_capacity(a.len());+ for id in a {+ let Some(id) = id.as_u64() else { return Err(EngineError::BadParams { cmd: CMD.into(), msg: "layer IDs must be unsigned integers".into() }) };+ out.push(LayerId(id));+ }+ Some(out)+ } else if scope == "selected" {+ Some(d.selected_layers())+ } else {+ None+ };+ let layers = lut_layers(&d.doc, explicit.as_deref())?;+ let count = layers.len();let title = p.get("title").and_then(Value::as_str).map(str::to_string).unwrap_or_else(|| stem(&d.doc.name));- let cube = bake_cube(&d.doc, size, &title);+ let cube = bake_cube_layers(size as usize, &title, &layers);match p.get("path").and_then(Value::as_str) {Some(path) => {write_file(path, cube.as_bytes())?;- Ok(json!({"path": path, "size": size.clamp(2, 256)}))+ Ok(json!({"path": path, "size": size, "layerCount": count}))}- None => Ok(json!({"cube": cube, "size": size.clamp(2, 256)})),+ None => Ok(json!({"cube": cube, "size": size, "layerCount": count})),}}@@ -1258,7 +1342,7 @@ pub fn specs() -> Vec<CommandSpec> {"Color Lookup Tables…",&["File", "Export"],None,- r##"{"path":str? (.cube; omit to return the text),"size":2..256=33,"title":str?}"##,+ r##"{"path":str? (.cube; omit to return the text),"size":2..129=33,"title":str?,"scope":"all|selected"="all","layers":[id,…]?} (selected layer IDs use original document stacking; masks are spatial and omitted)"##,has_adjustments,color_lookup_tables),diff --git a/crates/engine/src/file_cmds/tests.rs b/crates/engine/src/file_cmds/tests.rsindex 00449fcaf..47a0749b2 100644--- a/crates/engine/src/file_cmds/tests.rs+++ b/crates/engine/src/file_cmds/tests.rs@@ -367,6 +367,87 @@ fn color_lookup_table_bakes_the_adjustment_stack() {assert!(std::fs::read_to_string(&path).unwrap().contains("LUT_3D_SIZE 17"));}+#[test]+fn cube_export_uses_only_selected_adjustments_in_document_order() {+ let mut s = session(8, 8, 8);+ let first = s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap()["layer"].as_u64().unwrap();+ let second = s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap()["layer"].as_u64().unwrap();+ let both = s.execute("file.export.colorLookupTables", json!({"size": 3})).unwrap();+ let all = photocraft_cms::lutfile::parse_cube(both["cube"].as_str().unwrap()).unwrap();+ assert_eq!(both["layerCount"], 2);+ assert!(all.data[0] < 0.001, "two Invert adjustments produce identity");++ // Selection comes from the Layers panel rather than the active layer alone.+ s.execute("layer.select", json!({"layer": first})).unwrap();+ let selected = s.execute("file.export.colorLookupTables", json!({"size": 3, "scope": "selected"})).unwrap();+ let one = photocraft_cms::lutfile::parse_cube(selected["cube"].as_str().unwrap()).unwrap();+ assert_eq!(selected["layerCount"], 1);+ assert!(one.data[0] > 0.999, "one invert maps black to white");+ assert_eq!(all.size, one.size);+ assert_eq!(s.execute("file.export.colorLookupTables", json!({"size": 3, "layers": [first]})).unwrap()["cube"], selected["cube"]);++ // Reversing the caller's ID list must not reverse document stack order.+ let normal = s.execute("file.export.colorLookupTables", json!({"size": 3, "layers": [first, second]})).unwrap();+ let reversed = s.execute("file.export.colorLookupTables", json!({"size": 3, "layers": [second, first]})).unwrap();+ assert_eq!(normal["cube"], reversed["cube"]);+ assert_eq!(normal["cube"], both["cube"]);++ // Additional non-adjustment layers must not affect the LUT export.+ s.execute("layer.new.layer", json!({"name": "Raster"})).unwrap();+ assert_eq!(s.execute("file.export.colorLookupTables", json!({"size": 3})).unwrap()["cube"], both["cube"]);+}++#[test]+fn selected_cube_validation_is_explicit_and_never_mutates_the_document() {+ let mut s = session(8, 8, 8);+ let a = s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap()["layer"].as_u64().unwrap();+ let raster = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap();+ let rev = s.active().unwrap().revision;+ let history = s.active().unwrap().history.past_len();+ let valid = s.execute("file.export.colorLookupTables", json!({"size": 3, "layers": [a]})).unwrap();+ assert_eq!(valid["layerCount"], 1);+ for params in [+ json!({"size": 1}),+ json!({"size": 130}),+ json!({"size": 1.5}),+ json!({"size": -3}),+ json!({"scope": "unknown"}),+ json!({"scope": 42}),+ json!({"scope": "selected", "layers": [a]}),+ json!({"layers": []}),+ json!({"layers": 42}),+ json!({"layers": [a, a]}),+ json!({"layers": [a, "oops"]}),+ json!({"layers": [u64::MAX]}),+ json!({"layers": [raster]}),+ ] {+ assert!(s.execute("file.export.colorLookupTables", params.clone()).is_err(), "{params}");+ assert_eq!(s.active().unwrap().revision, rev, "{params}: export must be read-only");+ assert_eq!(s.active().unwrap().history.past_len(), history);+ }+ s.execute("layer.select", json!({"layer": raster})).unwrap();+ assert!(s.execute("file.export.colorLookupTables", json!({"size": 3, "scope": "selected"})).is_err());+}++#[test]+fn exported_selected_cube_round_trips_through_lookup_importer() {+ let dir = tmp("selected_cube");+ let mut s = session(8, 8, 8);+ let a = s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap()["layer"].as_u64().unwrap();+ let path = join(&dir, "chosen.cube");+ let r = s.execute("file.export.colorLookupTables", json!({"size": 17, "title": "Chosen", "layers": [a], "path": path})).unwrap();+ assert_eq!(r["size"], 17);+ assert_eq!(r["layerCount"], 1);+ let text = std::fs::read_to_string(&path).unwrap();+ let parsed = photocraft_cms::lutfile::parse_cube(&text).unwrap();+ assert_eq!(parsed.size, 17);+ assert_eq!(parsed.data.len(), 17 * 17 * 17 * 3);+ assert!(parsed.data[..3].iter().all(|v| *v > 0.999));+ assert!(parsed.data[parsed.data.len() - 3..].iter().all(|v| *v < 0.001));+ s.execute("layer.newAdjustmentLayer.colorLookup", json!({"file": path})).unwrap();+ assert_eq!(s.active().unwrap().doc.layers.len(), 3);+}+#[test]fn guide_layouts() {let mut s = session(100, 50, 8);diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 9766b259b..2d5b7f773 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -25,6 +25,8 @@Layer VrstvaType TextSelect Výběr+ Selected Vybrané+ Scope RozsahTop Left Vlevo nahořeTop Right Vpravo nahořeBottom Left Vlevo dolediff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex e64c8c626..dd622b1ed 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -21,6 +21,8 @@Layer EbeneType TextSelect Auswahl+ Selected Ausgewählt+ Scope UmfangTop Left Oben linksTop Right Oben rechtsBottom Left Unten linksdiff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex 290c42c4c..d90cd42ef 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -8,6 +8,7 @@Layer ΕπίπεδοType ΚείμενοSelect Επιλογή+ Scope ΕύροςFilter ΦίλτροView ΠροβολήWindow Παράθυροdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex d865e249c..e566ad4e1 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -17,6 +17,8 @@Layer CapaType TextoSelect Selección+ Selected Seleccionadas+ Scope AlcanceTop Left Superior izquierdaTop Right Superior derechaBottom Left Inferior izquierdadiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex b23cffd70..a6a7f6183 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -24,6 +24,8 @@Layer CalqueType TexteSelect Sélection+ Selected Sélectionnés+ Scope PortéeTop Left En haut à gaucheTop Right En haut à droiteBottom Left En bas à gauchediff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 804ff5451..0fba8ab46 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -17,6 +17,8 @@Layer LayerType TeksSelect Seleksi+ Selected Terpilih+ Scope CakupanTop Left Kiri atasTop Right Kanan atasBottom Left Kiri bawahdiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex c855f4616..96a261b4c 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -17,6 +17,8 @@Layer LivelloType TestoSelect Selezione+ Selected Selezionati+ Scope AmbitoTop Left In alto a sinistraTop Right In alto a destraBottom Left In basso a sinistradiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 9d5e28b0f..fef8cf56c 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -21,6 +21,8 @@Layer レイヤーType 文字Select 選択+ Selected 選択済み+ Scope 範囲Top Left 左上Top Right 右上Bottom Left 左下diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex bb4a0409d..4f108e0f1 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -13,6 +13,8 @@Layer 레이어Type 문자Select 선택+ Selected 선택됨+ Scope 범위Filter 필터View 보기Window 창diff --git a/crates/ui-egui/src/i18n/mod.rs b/crates/ui-egui/src/i18n/mod.rsindex 6bed93641..bd40695c1 100644--- a/crates/ui-egui/src/i18n/mod.rs+++ b/crates/ui-egui/src/i18n/mod.rs@@ -777,6 +777,17 @@ mod tests {}}+ // Dynamic dialog labels generated by label_of() are not seen by the tl! scanner.+ #[test]+ fn color_lookup_export_scope_labels_are_translated() {+ for lang in Lang::all().filter(|l| *l != Lang::EN) {+ for source in ["Scope", "Selected"] {+ assert!(lang.catalog().plain(source).is_some(), "{}: missing LUT export label {source:?}", lang.code());+ assert_ne!(tr(lang, source), source, "{}: untranslated LUT export label {source:?}", lang.code());+ }+ }+ }+#[test]fn mixer_brush_ui_strings_have_translations_in_every_registered_language() {const STRINGS: &[&str] = &["Mixer Brush", "Mixer Brush Tool", "Wet", "Load", "Mix", "Flow", "Sample All Layers"];diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex 943f50b85..e0d62ac0d 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -14,6 +14,7 @@Layer LaagType TekstSelect Selecteren+ Scope BereikTop Left LinksbovenTop Right RechtsbovenBottom Left Linksonderdiff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 5349fe91d..7a09d748b 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -24,6 +24,8 @@Layer WarstwaType TekstSelect Zaznaczenie+ Selected Zaznaczone+ Scope ZakresFilter FiltrView WidokWindow Oknodiff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 8765a4cc3..6c57db9b4 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -21,6 +21,8 @@Layer CamadaType TipoSelect Selecionar+ Selected Selecionadas+ Scope EscopoTop Left Superior esquerdoTop Right Superior direitoBottom Left Inferior esquerdodiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex ab173750e..92f4d56be 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -24,6 +24,8 @@Layer СлойType ТекстSelect Выделение+ Selected Выбранные+ Scope ОбластьTop Left Верхний левыйTop Right Верхний правыйBottom Left Нижний левыйdiff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex 216f39b12..a478cf632 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -15,6 +15,8 @@Layer ШарType ТекстSelect Виділення+ Selected Вибрані+ Scope ОбластьTop Left Зверху ліворучTop Right Зверху праворучBottom Left Знизу ліворучdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex c78379484..b05c97096 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -17,6 +17,8 @@Layer 图层Type 文字Select 选择+ Selected 已选+ Scope 范围Top Left 左上Top Right 右上Bottom Left 左下diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex b6045adde..7968d0d5d 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -25,6 +25,8 @@Layer 圖層Type 文字Select 選取+ Selected 已選取+ Scope 範圍Top Left 左上Top Right 右上Bottom Left 左下diff --git a/crates/ui-egui/src/view_cmds.rs b/crates/ui-egui/src/view_cmds.rsindex 9e2091d8a..f286775b1 100644--- a/crates/ui-egui/src/view_cmds.rs+++ b/crates/ui-egui/src/view_cmds.rs@@ -919,7 +919,18 @@ fn front(app: &mut PhotocraftApp, id: &str, params: &Value) -> Option<Result<Val"file.export.colorLookupTables" => {let (_, _, name) = doc?;let stem = name.rsplit_once('.').map_or(name.as_str(), |(a, _)| a).to_string();- dialog(app, json!({"path": format!("{dir}/{stem}.cube"), "size": 33, "title": stem}), json!({}))+ // A selected adjustment is a common use case, but existing no-selection exports+ // continue to bake the entire visible stack. The scope remains explicit in the UI.+ let selected_adjustments = app.session.active().is_some_and(|st| {+ let chosen = st.selected_layers();+ !chosen.is_empty()+ && chosen.iter().all(|id| {+ st.doc.layers.iter().any(|root| root.id == *id)+ && st.doc.layer(*id).is_some_and(|layer| layer.visible && matches!(layer.content, photocraft_doc::LayerContent::Adjustment(_)))+ })+ });+ let scope = if selected_adjustments { "selected" } else { "all" };+ dialog(app, json!({"path": format!("{dir}/{stem}.cube"), "size": 33, "title": stem, "scope": scope}), json!({"scope": ["all", "selected"]}))}"file.scripts.loadFilesIntoStack" => dialog(app, json!({"paths": dir}), json!({})),// Photography automation (photo_cmds / lens_cmds): a folder (or the open documents).diff --git a/crates/ui-egui/src/view_cmds/tests.rs b/crates/ui-egui/src/view_cmds/tests.rsindex cbf8bd05a..82f50d7e7 100644--- a/crates/ui-egui/src/view_cmds/tests.rs+++ b/crates/ui-egui/src/view_cmds/tests.rs@@ -241,3 +241,28 @@ fn new_guide_layout_does_not_remember_a_failed_command() {assert!(crate::dialogs::confirm(&mut app, id).is_err());assert_eq!(app.ui.view.guide_layout["columns"], 8);}++#[test]+fn lookup_export_dialog_uses_the_current_adjustment_selection() {+ let (mut app, _ctx) = app_with(1);+ app.run("layer.newAdjustmentLayer.invert", json!({})).unwrap();+ let current = app.session.active().unwrap().active_layer.unwrap();+ let opened = front(&mut app, "file.export.colorLookupTables", &json!({})).unwrap().unwrap();+ let id = opened["dialog"].as_u64().unwrap();+ let dialog = &app.ui.dialogs.last().unwrap().fields;+ assert_eq!(dialog["scope"], "selected");+ assert_eq!(dialog["size"], 33);+ assert_eq!(dialog["__choices"]["scope"], json!(["all", "selected"]));+ app.ui.close_dialog(id);++ app.run("layer.new.layer", json!({"name": "Unrelated pixels"})).unwrap();+ let opened = front(&mut app, "file.export.colorLookupTables", &json!({})).unwrap().unwrap();+ let id = opened["dialog"].as_u64().unwrap();+ assert_eq!(app.ui.dialogs.last().unwrap().fields["scope"], "all");+ app.ui.close_dialog(id);++ app.run("layer.select", json!({"layer": current})).unwrap();+ let direct = app.run("file.export.colorLookupTables", json!({"size": 3, "scope": "selected"})).unwrap();+ assert_eq!(direct["layerCount"], 1);+ assert!(direct["cube"].as_str().unwrap().contains("LUT_3D_SIZE 3"));+}