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.
This commit is contained in:
qvest-ssels committed 2026-11-28 10:49:10 +01:00
1 parent 05429b7510
commit 606bea666d
2 files changed
+47 -7

No files matched your search

@@ -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");
}
}
@@ -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),
}
}