From 606bea666df16679b432090aaa88f5cdeb83a564 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sat, 28 Nov 2026 10:49:10 +0100 Subject: [PATCH] Color Lookup: show the orders for .cube text given with no file name The command reads data with no file name as lut.cube, so under Auto or an explicit Cube format it applies Data Order and Table Order. The dialog hid both rows and dropped the orders in that state, as the empty fileName made it look for a .cube extension. lut_is_cube now names such text lut.cube and, under Auto, also checks the text the way the command's format detection does. --- .../dialogs/color_lookup_order_ui_tests.rs | 31 +++++++++++++++++++ .../ui-egui/src/dialogs/filter_dialog/rows.rs | 23 +++++++++----- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/dialogs/color_lookup_order_ui_tests.rs b/crates/ui-egui/src/dialogs/color_lookup_order_ui_tests.rs index 51887ca2b6..172ccc9953 100644 --- a/crates/ui-egui/src/dialogs/color_lookup_order_ui_tests.rs +++ b/crates/ui-egui/src/dialogs/color_lookup_order_ui_tests.rs @@ -243,3 +243,34 @@ fn an_explicit_other_format_hides_the_orders_of_a_cube_name() { } } } + +/// `.cube` text given as `data` with no file name is read as `lut.cube` under Auto and under an explicit Cube format, +/// so the orders show and OK applies them; an explicit `.3dl` or `.look` format still hides them (CodeRabbit on +/// #16628). +#[test] +fn inline_cube_data_without_a_file_name_shows_and_applies_the_orders() { + for (format, data_order, want) in + [("auto", "rgb", [50, 50, 200]), ("auto", "bgr", [200, 50, 50]), ("cube", "rgb", [50, 50, 200]), ("cube", "bgr", [200, 50, 50])] + { + let mut app = app_with_doc(); + let id = open(&mut app, COLOR_LOOKUP).unwrap(); + passes(&mut app, 2); + try_set(&mut app, id, "data", json!(SWAP2)).unwrap(); + try_set(&mut app, id, "lutFormat", json!(format)).unwrap(); + passes(&mut app, 2); + assert!(shown(&app, id), "{format}: inline .cube text"); + try_set(&mut app, id, "dataOrder", json!(data_order)).unwrap(); + try_set(&mut app, id, "dither", json!(false)).unwrap(); + ok(&mut app, id); + assert_eq!(pixel(&app), want, "{format}: data order {data_order}"); + } + for format in ["3dl", "look"] { + let mut app = app_with_doc(); + let id = open(&mut app, COLOR_LOOKUP).unwrap(); + passes(&mut app, 2); + try_set(&mut app, id, "data", json!(SWAP2)).unwrap(); + try_set(&mut app, id, "lutFormat", json!(format)).unwrap(); + passes(&mut app, 2); + assert!(!shown(&app, id), "{format}: an explicit other format"); + } +} diff --git a/crates/ui-egui/src/dialogs/filter_dialog/rows.rs b/crates/ui-egui/src/dialogs/filter_dialog/rows.rs index ff297d166d..dda20b709c 100644 --- a/crates/ui-egui/src/dialogs/filter_dialog/rows.rs +++ b/crates/ui-egui/src/dialogs/filter_dialog/rows.rs @@ -302,18 +302,27 @@ fn lut_choice(fields: &DialogFields) -> LutChoice { /// Whether the chosen LUT is a `.cube` file, which Data Order and Table Order apply to: a LUT folder file or given /// text that the command reads as Cube. An explicit LUT Format decides that, as it does for the command; under Auto -/// the file name does. Built-in looks are no files and have no orders, and a LUT Load 3D LUT… read has no known -/// format ([`LUT_PICKED`]). +/// the file name does, and given text with no file name is read as `lut.cube`, as the command reads it. Built-in +/// looks are no files and have no orders, and a LUT Load 3D LUT… read has no known format ([`LUT_PICKED`]). pub(crate) fn lut_is_cube(fields: &DialogFields) -> bool { - let named_cube = |name: &str| match fields.text("lutFormat") { + let named_cube = |name: &str, bytes: &[u8]| match fields.text("lutFormat") { Some("cube") => true, Some("3dl" | "look") => false, - _ => std::path::Path::new(name).extension().is_some_and(|ext| ext.eq_ignore_ascii_case("cube")), + _ => { + matches!(craft::cms::lutfile::Format::detect(name, bytes), craft::cms::lutfile::Format::Cube) + && std::path::Path::new(name).extension().is_some_and(|ext| ext.eq_ignore_ascii_case("cube")) + } + }; + // Given text, which the command reads before a built-in look, under its file name or, with none, as `lut.cube`; + // under Auto the command still tells a `.look` by its text. + let given = || { + let data = fields.text("data").filter(|data| !data.is_empty())?; + let name = fields.text("fileName").filter(|name| !name.is_empty()).unwrap_or("lut.cube"); + Some(named_cube(name, data.as_bytes())) }; match lut_choice(fields) { - LutChoice::Loaded { .. } => fields.bool(LUT_PICKED) != Some(true) && fields.text("fileName").is_some_and(named_cube), - LutChoice::Folder(path) => named_cube(&path.to_string_lossy()), - _ => false, + LutChoice::Folder(path) => named_cube(&path.to_string_lossy(), b""), + _ => fields.bool(LUT_PICKED) != Some(true) && given().unwrap_or(false), } }