Address CodeRabbit review; follow main's colour state accessors

- Curves at 8 bit: evaluate the channel and composite curves at the 256
  exact levels instead of between two entries of the 4096-entry table, so
  a pencil step between levels 128 and 129 no longer gives level 128 a
  fraction that rounds to level 4.
- Color Settings: a later Monitor Profile change keeps "Monitor Color"
  only while the values still are what Monitor Color would set.
- Color Settings dialog: a control changed by ui.dialog.set before the
  first pass shows Custom instead of becoming the baseline.
- Stored-channel edits (Lab/CMYK, CMYK Channel Mixer) mix through the
  selection as v*(1-k) + o*k, exact at full coverage over huge 32-bit
  values.
- Action playback: a Channel Mixer step the editor refuses reports the
  refusal instead of opening the generic step editor.
- Shortcut set test: assert Cancel closes the confirmation.
- Merge follow-up: Session's colour state is reached through
  ColorExt::color()/color_mut() on main now.
This commit is contained in:
David Mann committed 2026-11-23 13:31:11 +01:00
1 parent a461a65ceb
commit 81cc69f17e
12 files changed
+162 -38

No files matched your search

@@ -135,3 +135,19 @@ fn the_point_order_of_each_curve_does_not_change_the_result() {
assert_eq!(gray8(&adj, g), gray8(&measured(), g), "gray {g} with the points listed in reverse");
}
}
/// A pencil channel step between levels 128 and 129 leaves level 128 at exactly zero on its way to
/// the composite curve: read between two table entries it came out as a fraction that rounded to
/// level 4, where the composite's own step turned it into 255.
#[test]
fn a_pencil_channel_step_reaches_the_composite_at_its_exact_level() {
let adj = Adjustment::Curves {
master: pts(&[(0, 0), (3, 0), (4, 255), (5, 0), (255, 0)]),
per_channel: [pts(&[(0, 0), (128, 0), (129, 255), (255, 255)]), pts(STRAIGHT), pts(STRAIGHT)],
space: ToneSpace::Rgb,
black: Vec::new(),
pencil: true,
};
assert_eq!(gray8(&adj, 128)[0], 0);
assert_eq!(gray8(&adj, 4)[0], 0, "level 4 maps to 0 through the channel, then 0 through the composite");
}
+28 -6
View File
@@ -62,11 +62,20 @@ fn tone_luts_qc(adj: &Adjustment, quantum: Option<f32>, curve_levels: bool) -> [
// document sample - the way [`levels_q`] is exact at every level. 16-bit and float
// documents were not measured, nor CMYK and Lab curves, so only the 8-bit quantum.
let level = (curve_levels && *space == ToneSpace::Rgb && quantum == Some(EIGHT_BIT_LEVELS)).then_some(EIGHT_BIT_LEVELS);
// Both curves are evaluated at the 256 exact levels, not read between two entries of
// the 4096-entry table: a pencil step between levels 128 and 129 would otherwise give
// level 128 a small fraction that rounds up to level 4 and wakes a composite step there.
let master_levels = if *space == ToneSpace::Lab { curve_samples::<LEVELS>(&[]) } else { curve_samples_mode::<LEVELS>(master, *pencil) };
let row = |c: &[CurvePoint], level: Option<f32>| match level {
Some(q) => {
let channel = curve_lut_mode(c, *pencil);
let at_level = |v: f32| whole_levels(v, Some(q));
(0..LUT_SIZE).map(|k| lut(&m, at_level(lut(&channel, at_level(x(k)))))).collect()
let channel = curve_samples_mode::<LEVELS>(c, *pencil);
let index = |v: f32| (whole_levels(v, Some(q)) * q).round().clamp(0.0, q) as usize;
(0..LUT_SIZE)
.map(|k| {
let ch = channel.get(index(x(k))).copied().unwrap_or(0.0);
master_levels.get(index(ch)).copied().unwrap_or(0.0)
})
.collect()
}
None => curve_lut_mode(c, *pencil).iter().map(|&v| lut(&m, v)).collect(),
};
@@ -420,13 +429,26 @@ pub fn curve_lut_mode(points: &[CurvePoint], pencil: bool) -> Vec<f32> {
/// A pencil-drawn Curves map (see [`photocraft_doc::adjust::curve_map`]): straight segments
/// between its entries, constant outside the first/last, clamped to 0..=1, sampled into a LUT.
pub fn curve_map_lut(points: &[CurvePoint]) -> Vec<f32> {
curve_map_samples::<LUT_SIZE>(points)
}
/// Whole 8-bit levels: the sample count [`tone_luts_qc`] evaluates an 8-bit RGB Curves at.
const LEVELS: usize = 256;
/// [`curve_lut_mode`] sampled at `N` evenly spaced inputs including both end points.
fn curve_samples_mode<const N: usize>(points: &[CurvePoint], pencil: bool) -> Vec<f32> {
if pencil { curve_map_samples::<N>(points) } else { curve_samples::<N>(points) }
}
/// [`curve_map_lut`] sampled at `N` evenly spaced inputs including both end points.
fn curve_map_samples<const N: usize>(points: &[CurvePoint]) -> Vec<f32> {
let mut pts: Vec<(f32, f32)> = points.iter().filter(|p| p.input.is_finite() && p.output.is_finite()).map(|p| (p.input, p.output)).collect();
pts.sort_by(|a, b| a.0.total_cmp(&b.0));
pts.dedup_by(|a, b| (a.0 - b.0).abs() < 1e-6);
let ident = |k: usize| k as f32 / (LUT_SIZE - 1) as f32;
let (Some(&first), Some(&last)) = (pts.first(), pts.last()) else { return (0..LUT_SIZE).map(ident).collect() };
let ident = |k: usize| k as f32 / N.saturating_sub(1).max(1) as f32;
let (Some(&first), Some(&last)) = (pts.first(), pts.last()) else { return (0..N).map(ident).collect() };
let mut seg = 0;
(0..LUT_SIZE)
(0..N)
.map(|k| {
let xv = ident(k);
if xv <= first.0 {
+9 -3
View File
@@ -191,6 +191,9 @@ pub const COLOR_SETTINGS_PRESETS: [&str; 13] = [
"North America Web/Internet",
];
/// The named setup whose working RGB follows the monitor profile.
const MONITOR_COLOR: &str = "Monitor Color";
/// The RGB entry of "Monitor Color": the monitor profile (see [`ColorState::monitor_rgb_for`]).
const MONITOR_RGB: &str = "monitor";
@@ -1445,7 +1448,7 @@ fn color_settings(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(m) = p.get("monitorProfile").and_then(Value::as_str) {
from.monitor_profile = m.to_string();
}
s.color.preset_settings(&from, name)
s.color().preset_settings(&from, name)
}
_ => None,
};
@@ -1509,9 +1512,12 @@ fn color_settings(s: &mut Session, p: &Value) -> Result<Value> {
(Some(_), _) => CUSTOM_SETTINGS.into(),
// No preset given: any change but the monitor profile makes the values Custom.
(None, _) => {
let old = &s.color.settings;
let old = &s.color().settings;
let unchanged = ColorSettings { monitor_profile: old.monitor_profile.clone(), preset: old.preset.clone(), ..next.clone() } == *old;
if unchanged && is_settings_preset(&old.preset) { old.preset.clone() } else { CUSTOM_SETTINGS.into() }
// "Monitor Color" takes its working RGB from the monitor profile, so a new monitor
// profile keeps the name only while the setup still is what it would set now.
let still_monitor_color = old.preset != MONITOR_COLOR || s.color().preset_settings(&next, MONITOR_COLOR).is_some_and(|m| same_setup(&next, &m));
if unchanged && still_monitor_color && is_settings_preset(&old.preset) { old.preset.clone() } else { CUSTOM_SETTINGS.into() }
}
};
validate_settings(&next).map_err(|msg| EngineError::BadParams { cmd: cmd.into(), msg })?;
@@ -12,7 +12,7 @@ const CMD: &str = "edit.colorSettings";
fn setup(name: &str) -> ColorSettings {
let s = crate::session();
s.color.preset_settings(&s.color.settings, name).unwrap()
s.color().preset_settings(&s.color().settings, name).unwrap()
}
#[test]
@@ -69,8 +69,8 @@ fn each_setup_sets_the_measured_values() {
#[test]
fn monitor_color_takes_a_named_monitor_profile() {
let mut s = crate::session();
s.color.settings.monitor_profile = "display-p3".into();
let c = s.color.preset_settings(&s.color.settings, "Monitor Color").unwrap();
s.color_mut().settings.monitor_profile = "display-p3".into();
let c = s.color().preset_settings(&s.color().settings, "Monitor Color").unwrap();
assert_eq!(c.working_rgb, "display-p3");
// The monitor profile itself is not part of the setup.
assert_eq!(c.monitor_profile, "display-p3");
@@ -83,6 +83,25 @@ fn monitor_color_takes_a_named_monitor_profile() {
assert_eq!((&r["preset"], &r["settings"]["workingRgb"]), (&json!("Monitor Color"), &json!("srgb")));
}
#[test]
fn a_later_monitor_profile_change_makes_monitor_color_custom() {
let mut s = crate::session();
let r = s.execute(CMD, json!({"preset": "Monitor Color", "monitorProfile": "srgb"})).unwrap();
assert_eq!((&r["preset"], &r["settings"]["workingRgb"]), (&json!("Monitor Color"), &json!("srgb")));
// Monitor Color would now set Display P3, so the sRGB values left behind are Custom.
let r = s.execute(CMD, json!({"monitorProfile": "display-p3"})).unwrap();
assert_eq!((&r["preset"], &r["settings"]["workingRgb"]), (&json!(CUSTOM_SETTINGS), &json!("srgb")));
// A monitor change that leaves the setup as Monitor Color would set it keeps the name.
let r = s.execute(CMD, json!({"preset": "Monitor Color", "monitorProfile": "srgb"})).unwrap();
assert_eq!(r["preset"], "Monitor Color");
let r = s.execute(CMD, json!({"monitorProfile": "auto"})).unwrap();
assert_eq!(r["preset"], "Monitor Color");
// Other setups don't follow the monitor profile.
s.execute(CMD, json!({"preset": "North America Prepress 2"})).unwrap();
let r = s.execute(CMD, json!({"monitorProfile": "display-p3"})).unwrap();
assert_eq!(r["preset"], "North America Prepress 2");
}
#[test]
fn fresh_settings_are_custom() {
let mut s = crate::session();
@@ -96,10 +115,10 @@ fn fresh_settings_are_custom() {
fn a_scripted_setup_is_stored_and_reported() {
let mut s = crate::session();
// Blend Text Colors Using Gamma off: a scripted setup turns it back on at 1.45.
s.color.settings.blend_text_gamma = 1.0;
s.color_mut().settings.blend_text_gamma = 1.0;
let r = s.execute(CMD, json!({"preset": "North America Prepress 2"})).unwrap();
assert_eq!(r["preset"], "North America Prepress 2");
let c = &s.color.settings;
let c = &s.color().settings;
assert_eq!(c.preset, "North America Prepress 2");
assert_eq!((c.working_rgb.as_str(), c.policy_rgb, c.ask_on_missing), ("adobe-rgb-compat", Policy::Preserve, true));
assert_eq!(c.blend_text_gamma, photocraft_compose::psblend::TEXT_GAMMA);
@@ -144,7 +163,7 @@ fn the_dialogs_ok_keeps_the_name_with_its_own_text_gamma() {
params["bpc"] = json!(false);
let r = s.execute(CMD, params).unwrap();
assert_eq!(r["preset"], CUSTOM_SETTINGS);
assert!(!s.color.settings.bpc);
assert!(!s.color().settings.bpc);
}
#[test]
@@ -153,7 +172,7 @@ fn a_setup_with_a_differing_value_is_custom() {
let r = s.execute(CMD, json!({"preset": "Monitor Color", "policyRgb": "preserve"})).unwrap();
assert_eq!(r["preset"], CUSTOM_SETTINGS);
// The setup's other values still apply.
let c = &s.color.settings;
let c = &s.color().settings;
assert_eq!((c.policy_rgb, c.policy_cmyk, c.working_gray.as_str()), (Policy::Preserve, Policy::Off, "gray-gamma-2.2"));
}
@@ -163,18 +182,18 @@ fn custom_keeps_the_values() {
s.execute(CMD, json!({"preset": "North America General Purpose 2"})).unwrap();
let r = s.execute(CMD, json!({"preset": CUSTOM_SETTINGS})).unwrap();
assert_eq!(r["preset"], CUSTOM_SETTINGS);
assert!(!s.color.settings.ask_on_mismatch, "the setup's values stay");
assert!(!s.color().settings.ask_on_mismatch, "the setup's values stay");
}
#[test]
fn a_bad_preset_is_an_error_and_changes_nothing() {
let mut s = crate::session();
s.execute(CMD, json!({"preset": "North America General Purpose 2"})).unwrap();
let before = s.color.settings.clone();
let before = s.color().settings.clone();
for bad in [json!(null), json!("Europe"), json!(""), json!("custom"), json!(3), json!(true), json!(["Monitor Color"]), json!({"name": "Monitor Color"})] {
let e = s.execute(CMD, json!({"preset": bad.clone(), "bpc": false})).unwrap_err();
assert!(matches!(e, EngineError::BadParams { .. }), "{bad}: {e}");
assert_eq!(s.color.settings, before, "{bad}");
assert_eq!(s.color().settings, before, "{bad}");
}
// A stored name the menu doesn't have (a hand-edited preferences file) is refused too.
let mut c = before.clone();
+3 -1
View File
@@ -283,8 +283,10 @@ fn adjusted_channels(s: &Surface, r: Rect, selection: Option<&Surface>, op: impl
let Some(out) = out.get_mut(..colors) else { continue };
out.copy_from_slice(ch);
op(out);
// `v·(1−k) + o·k`, as in [`mix_through_selection`]: exact at full coverage, even over
// huge 32-bit values whose difference from the result would round it away (#9483).
for (v, o) in ch.iter_mut().zip(out.iter()) {
*v += (o - *v) * k;
*v = *v * (1.0 - k) + o * k;
}
}
}
+12
View File
@@ -518,6 +518,18 @@ fn full_coverage_keeps_the_edit_over_huge_hdr_values() {
}
}
/// The same for an edit of a CMYK layer's own channels: a result of 0.5 over a stored cyan of
/// 2^26 came out as 0, the difference rounding the stored value away.
#[test]
fn full_coverage_keeps_a_stored_channel_edit_over_huge_hdr_values() {
let fmt = PixelFormat::new(ColorMode::Cmyk, SampleType::F32, true);
let mut s = Surface::new(fmt);
let big = 67_108_864.0_f32;
s.write_pixel(0, 0, &[big, 0.25, 0.25, 0.25, 1.0]);
let out = adjusted_channels(&s, Rect::new(0, 0, 1, 1), None, |ch| ch.iter_mut().for_each(|v| *v = 0.5));
assert_eq!(out[..4], [0.5, 0.5, 0.5, 0.5]);
}
/// Remapping walks the stored tiles, not the dense rectangle around them: two pixels a million
/// pixels apart (a ~4 TB rectangle) flip to their mirrored places.
#[test]
+2 -2
View File
@@ -397,7 +397,7 @@ fn refusal(app: &PhotocraftApp, command: &str) -> String {
/// Why a dialog did not open: `Some` is the editor's refusal of these parameters, to show the user (a CMYK Channel
/// Mixer, #8047); `None` means there is no dialog for them.
type Refused = Option<String>;
pub(crate) type Refused = Option<String>;
/// Opens a neutral adjustment dialog using the current edit target.
pub fn open_neutral(app: &mut PhotocraftApp, command: &str) -> Option<DialogId> {
@@ -411,7 +411,7 @@ pub(crate) fn open_with_params(app: &mut PhotocraftApp, command: &str, params: &
}
/// [`open_with_params`], with the reason it did not open.
fn open_with_params_checked(app: &mut PhotocraftApp, command: &str, params: &Value) -> Result<DialogId, Refused> {
pub(crate) fn open_with_params_checked(app: &mut PhotocraftApp, command: &str, params: &Value) -> Result<DialogId, Refused> {
let params = if params.is_null() { json!({}) } else { Value::Object(params.as_object().ok_or(None)?.clone()) };
let params = complete_params(app, command, &params).unwrap_or(params);
let mut params = app.with_mask_target(command, params);
@@ -11,7 +11,7 @@ use crate::new_layer_ui::testing::top;
/// An app whose Color Settings hold `settings`.
fn app_with(settings: ColorSettings) -> Box<PhotocraftApp> {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
app.session.color.settings = settings;
app.session.color_mut().settings = settings;
app
}
@@ -121,7 +121,7 @@ fn monitor_color_takes_the_monitor_profile_the_dialog_shows() {
show(&mut app, 2);
let f = fields(&app, id);
assert_eq!(f["preset"], "Monitor Color");
assert_eq!(f["workingRgb"], app.session.color.monitor_rgb_for("display-p3"));
assert_eq!(f["workingRgb"], app.session.color().monitor_rgb_for("display-p3"));
assert_eq!((&f["policyRgb"], &f["policyCmyk"], &f["policyGray"]), (&json!("off"), &json!("off"), &json!("off")));
}
@@ -144,13 +144,13 @@ fn ok_stores_the_setup_and_cancel_discards_it() {
dialog_set(&mut app, id, "preset", json!("North America General Purpose 2"));
show(&mut app, 2);
crate::dialogs::testing::cancel(&mut app, id).unwrap();
assert_eq!(app.session.color.settings, ColorSettings::default());
assert_eq!(app.session.color().settings, ColorSettings::default());
// OK: the setup's name and values.
let id = open_dialog(&mut app, 1);
dialog_set(&mut app, id, "preset", json!("North America General Purpose 2"));
show(&mut app, 2);
crate::dialogs::testing::confirm(&mut app, id).unwrap();
let c = &app.session.color.settings;
let c = &app.session.color().settings;
assert_eq!(c.preset, "North America General Purpose 2");
assert_eq!((c.ask_on_mismatch, c.ask_on_paste, c.ask_on_missing), (false, false, false));
// Opened again, it shows that setup; an edit then OK stores Custom.
@@ -159,8 +159,8 @@ fn ok_stores_the_setup_and_cancel_discards_it() {
dialog_set(&mut app, id, "dither", json!(false));
assert_eq!(fields(&app, id)["preset"], CUSTOM_SETTINGS);
crate::dialogs::testing::confirm(&mut app, id).unwrap();
assert_eq!(app.session.color.settings.preset, CUSTOM_SETTINGS);
assert!(!app.session.color.settings.dither);
assert_eq!(app.session.color().settings.preset, CUSTOM_SETTINGS);
assert!(!app.session.color().settings.dither);
}
#[test]
@@ -170,7 +170,7 @@ fn a_setup_set_by_script_loads_before_the_next_draw() {
let id = open_dialog(&mut app, 1);
dialog_set(&mut app, id, "preset", json!("Europe Prepress 3"));
crate::dialogs::testing::confirm(&mut app, id).unwrap();
let c = &app.session.color.settings;
let c = &app.session.color().settings;
assert_eq!(c.preset, "Europe Prepress 3");
assert_eq!((&c.working_rgb, &c.working_cmyk), (&expected.working_rgb, &expected.working_cmyk));
assert_eq!((c.ask_on_mismatch, c.ask_on_paste, c.ask_on_missing), (true, true, true));
@@ -192,7 +192,25 @@ fn a_control_set_by_script_shows_custom_before_the_next_draw() {
dialog_set(&mut app, id, key, value.clone());
assert_eq!(fields(&app, id)["preset"], expected, "{key} {value}");
crate::dialogs::testing::confirm(&mut app, id).unwrap();
assert_eq!(app.session.color.settings.preset, expected, "{key} {value}");
assert_eq!(app.session.color().settings.preset, expected, "{key} {value}");
}
}
#[test]
fn a_control_set_before_the_first_pass_shows_custom() {
let name = "North America General Purpose 2";
let stored = preset_setup(&ColorSettings::default(), name, "srgb").unwrap();
// Before the first pass the dialog has no baseline yet: a changed control is still an edit,
// and setting the value it already shows is none.
for (value, expected) in [(json!(1.8), CUSTOM_SETTINGS), (json!(1.45), name)] {
let mut app = app_with(stored.clone());
let id = open_dialog(&mut app, 0);
dialog_set(&mut app, id, "blendTextGamma", value.clone());
assert_eq!(fields(&app, id)["preset"], expected, "{value}");
show(&mut app, 2);
assert_eq!(fields(&app, id)["preset"], expected, "{value} after a draw");
crate::dialogs::testing::confirm(&mut app, id).unwrap();
assert_eq!(app.session.color().settings.preset, expected, "{value}");
}
}
@@ -205,7 +223,7 @@ fn a_setup_set_before_the_first_pass_loads_too() {
let f = fields(&app, id);
assert_eq!((&f["workingRgb"], &f["workingCmyk"]), (&json!(expected.working_rgb), &json!(expected.working_cmyk)), "loaded at once");
crate::dialogs::testing::confirm(&mut app, id).unwrap();
let c = &app.session.color.settings;
let c = &app.session.color().settings;
assert_eq!(c.preset, "Europe Prepress 3");
assert_eq!((&c.working_rgb, &c.working_cmyk), (&expected.working_rgb, &expected.working_cmyk));
assert_eq!((c.ask_on_mismatch, c.ask_on_paste, c.ask_on_missing), (true, true, true));
@@ -224,6 +242,6 @@ fn monitor_color_follows_a_monitor_profile_change() {
assert_eq!(f["workingRgb"], "display-p3", "the working RGB follows the monitor profile");
show(&mut app, 2);
crate::dialogs::testing::confirm(&mut app, id).unwrap();
let c = &app.session.color.settings;
let c = &app.session.color().settings;
assert_eq!((c.preset.as_str(), c.working_rgb.as_str(), c.monitor_profile.as_str()), ("Monitor Color", "display-p3", "display-p3"));
}
@@ -11,7 +11,7 @@ use craft::ui::dialog::dialog_id;
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param};
use craft::ui::pickers::Select;
use craft::ui::runtime::env::Label;
use photocraft_engine::color_cmds::{COLOR_SETTINGS_PRESETS, CUSTOM_SETTINGS, ColorSettings, is_settings_preset, preset_setup};
use photocraft_engine::color_cmds::{COLOR_SETTINGS_PRESETS, CUSTOM_SETTINGS, ColorExt, ColorSettings, is_settings_preset, preset_setup};
use serde_json::{Map, Value, json};
use crate::PhotocraftApp;
@@ -70,10 +70,16 @@ pub(crate) fn reconcile(app: &mut PhotocraftApp, ctx: &egui::Context) {
let Some(applied) = f.get(APPLIED).and_then(Value::as_str).map(str::to_string) else {
// Opening: the controls hold the stored setup's values. A `ui.dialog.set` that picked
// another entry before the first pass loads it.
if shown != entry_of(Some(&app.session.color.settings.preset)) {
if shown != entry_of(Some(&app.session.color().settings.preset)) {
load(app, ctx, &f, &shown);
return;
}
// A control a `ui.dialog.set` changed before the first pass is an edit, not the baseline.
if shown != CUSTOM_SETTINGS && differs_from_stored(app, &f) {
set_hidden(app, KEY, json!(CUSTOM_SETTINGS));
set_hidden(app, APPLIED, json!(CUSTOM_SETTINGS));
return;
}
set_hidden(app, APPLIED, json!(shown));
set_hidden(app, BASE, Value::Object(tracked(&f)));
return;
@@ -115,7 +121,7 @@ pub(crate) fn reconcile(app: &mut PhotocraftApp, ctx: &egui::Context) {
/// "Monitor Color" takes the monitor profile the dialog shows as its working RGB.
fn load(app: &mut PhotocraftApp, ctx: &egui::Context, f: &Map<String, Value>, name: &str) {
let monitor = f.get("monitorProfile").and_then(Value::as_str).unwrap_or("auto");
let monitor_rgb = app.session.color.monitor_rgb_for(monitor);
let monitor_rgb = app.session.color().monitor_rgb_for(monitor);
let id = dialog_id(COMMAND);
if let Some(Value::Object(setup)) = preset_setup(&ColorSettings::default(), name, &monitor_rgb).and_then(|c| serde_json::to_value(c).ok()) {
for (k, v) in setup {
@@ -131,10 +137,16 @@ fn load(app: &mut PhotocraftApp, ctx: &egui::Context, f: &Map<String, Value>, na
set_hidden(app, BASE, Value::Object(base));
}
/// A tracked control no longer shows the stored Color Settings' value.
fn differs_from_stored(app: &PhotocraftApp, f: &Map<String, Value>) -> bool {
let Ok(Value::Object(stored)) = serde_json::to_value(&app.session.color().settings) else { return false };
tracked(f).iter().any(|(k, v)| stored.get(k).is_some_and(|s| !same(s, v)))
}
/// The working RGB Monitor Color gave (in `base`) is no longer the one the shown monitor profile gives.
fn monitor_rgb_moved(app: &PhotocraftApp, f: &Map<String, Value>, base: &Map<String, Value>) -> bool {
let monitor = f.get("monitorProfile").and_then(Value::as_str).unwrap_or("auto");
base.get("workingRgb").and_then(Value::as_str) != Some(app.session.color.monitor_rgb_for(monitor).as_str())
base.get("workingRgb").and_then(Value::as_str) != Some(app.session.color().monitor_rgb_for(monitor).as_str())
}
/// Writes `value` under `key` of the open dialog: the menu's entry as text, the bookkeeping as JSON.
+6 -2
View File
@@ -191,10 +191,14 @@ pub(crate) fn open_recorded_editor(app: &mut PhotocraftApp, id: &str, params: &V
// Private keys belong to the dialog, not the recorded Action step.
object.retain(|key, _| !key.starts_with("__"));
}
if let Some(dialog) = crate::adjust_dialog::open_with_params(app, id, &values) {
match crate::adjust_dialog::open_with_params_checked(app, id, &values) {
// Adjustment dialogs normalized their effective target already. Raw parameters here
// would restore discarded Lab/CMYK records or override the normalized tone controls.
return Ok(dialog);
Ok(dialog) => return Ok(dialog),
// The editor refuses these parameters (a CMYK Channel Mixer, #8047): say why instead of
// opening the generic step editor over them.
Err(Some(reason)) => return Err(reason),
Err(None) => {}
}
let dialog = open_step_editor(app, id, &values)?;
if !crate::sizing::is_sizing(id) {
@@ -2157,3 +2157,15 @@ fn save_hook_closing_the_target_stops_an_imported_close_with_save() {
assert!(app.session.recording.playback_stack.is_empty());
}
}
/// #8047: a recorded Channel Mixer step with ink outputs reopened in an RGB document is refused by
/// the RGB-only editor. Playback must say why, not fall back to the generic step editor over it.
#[test]
fn a_recorded_cmyk_channel_mixer_step_reports_the_editors_refusal() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 4, "height": 4})).unwrap();
let open = app.framework.dialogs.open_dialogs().len();
let result = open_recorded_editor(&mut app, "image.adjustments.channelMixer", &json!({"cyan": [80, 0, 0, 0, 0]}));
assert_eq!(result, Err(crate::adjust_editors::values::CMYK_MIXER_UNAVAILABLE.to_string()));
assert_eq!(app.framework.dialogs.open_dialogs().len(), open, "no editor opened");
}
@@ -163,5 +163,6 @@ fn deleting_a_custom_set_waits_for_confirmation_and_dialog_ok() {
.expect("the confirmation offers Cancel");
cancel.click();
h.run_steps(3);
assert!(h.query_by_label("Delete the set “Painting”?").is_none(), "Cancel closes the confirmation");
assert!(h.state().prefs_rt.shortcuts.as_ref().unwrap().profiles.sets().contains_key("Painting"));
}