Channel Mixer: never regenerate a monochrome CMYK mixr; mixer track colours from tokens

PSD export no longer writes a monochrome CMYK Channel Mixer it would have to infer (an edited imported one, or an RGB monochrome mixer reshaped for a CMYK document); it warns that the layer's mixer was not written. Unedited imported blocks are still saved back verbatim.

The Channel Mixer source track colours come from new Tokens fields (mixer_rgb, mixer_ink) set in every theme, and the source and Constant sliders are disabled while an imported monochrome CMYK mixer has Monochrome on, the state the engine refuses to edit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Higgs32584andClaude Opus 5.5 committed 2026-11-16 09:32:36 -05:00
1 parent 72c769b036
commit 64fa0cd36e
5 files changed
+94 -13

No files matched your search

+11 -1
View File
@@ -461,11 +461,21 @@ impl Ex<'_> {
// A Channel Mixer whose outputs don't match the document's mode has no
// PSD encoding that reads back as it is: save its nearest equivalent.
let reshaped = adjust_map::mixer_for(a, channels);
let target = reshaped.as_ref().unwrap_or(a);
// No Photoshop sample shows a monochrome CMYK `mixr` yet (#8047), so its layout would
// be a guess: such a mixer is saved only as the imported block it came from (kept
// above), never regenerated, whether it was a CMYK mixer or an RGB one reshaped here.
let unconfirmed = matches!(target, photocraft_doc::Adjustment::ChannelMixer { cmyk: Some(_), monochrome: true, .. });
if unconfirmed {
self.warnings
.push(format!("layer \"{}\": monochrome CMYK Channel Mixer is not written to PSD (its Photoshop layout is not confirmed yet)", l.name));
return;
}
if reshaped.is_some() {
let shape = if channels == adjust_map::Channels::Cmyk { "cyan, magenta, yellow and black" } else { "red, green and blue" };
self.warnings.push(format!("layer \"{}\": Channel Mixer saved with {shape} outputs, the document mode's own", l.name));
}
let w = adjust_map::write(reshaped.as_ref().unwrap_or(a));
let w = adjust_map::write(target);
if w.is_empty() {
self.warnings.push(format!("layer \"{}\": {} adjustment is not yet written to PSD", l.name, a.label()));
}
+38 -5
View File
@@ -1,6 +1,7 @@
//! A CMYK document's Channel Mixer (`mixr` with four ink records, #8047) through PSD: an imported
//! block nobody edited is saved back exactly as it was read, whatever its layout; an edited one
//! is written in Photoshop's own 44-byte layout. With the `corpus` feature, Photoshop's own CMYK
//! is written in Photoshop's own 44-byte layout, except a monochrome one, whose layout no
//! Photoshop sample confirms yet: that is not written. With the `corpus` feature, Photoshop's own CMYK
//! mixers (photoshop corpus cmyk8 and cmyk16 channel-mixer.psd) are read, rendered on their inks
//! against the files' merged images, and saved back byte for byte.
@@ -50,7 +51,8 @@ fn psd_with_mixr(block: &[u8]) -> Vec<u8> {
/// A monochrome block carrying its first record alone (padded), and a four-record block followed
/// by bytes our writer never emits: both import as CMYK mixers (the monochrome one with a
/// warning, as no Photoshop sample confirms how it renders), are saved back unchanged while
/// unedited, and are rewritten as Photoshop's 44 bytes once edited.
/// unedited; once edited, the four-record one is rewritten as Photoshop's 44 bytes and the
/// monochrome one is not written (its layout is unconfirmed).
#[test]
fn unedited_cmyk_mixer_blocks_are_saved_back_as_read() {
let mut mono = i16s(&[1, 1, 30, 30, 30, 100, 0]);
@@ -71,9 +73,40 @@ fn unedited_cmyk_mixer_blocks_are_saved_back_as_read() {
rows[1][4] = 0.1;
}
}
let edited = mixr(&exported(&doc)).unwrap();
assert_eq!(edited.len(), 44, "monochrome {monochrome}: edited");
assert_ne!(edited, block);
let r = export(&doc, "x.psd", &ExportOptions::default()).unwrap();
let edited = mixr(&PsdFile::from_bytes(&r.bytes).unwrap());
let skipped = r.warnings.iter().any(|w| w.contains("monochrome CMYK Channel Mixer is not written"));
assert_eq!(skipped, monochrome, "{:?}", r.warnings);
if monochrome {
// No Photoshop sample confirms the layout: an edited one is not regenerated.
assert_eq!(edited, None, "monochrome: edited");
} else {
let edited = edited.unwrap();
assert_eq!(edited.len(), 44, "edited");
assert_ne!(edited, block);
}
}
}
/// An RGB monochrome mixer in a CMYK document (from a `.pcraft` or a mode change) would be
/// reshaped into a monochrome CMYK mixer, whose `mixr` layout no Photoshop sample confirms yet
/// (#8047): it is not written, with a warning naming the layer; without Monochrome it is
/// reshaped and written as before.
#[test]
fn rgb_monochrome_mixer_in_a_cmyk_document_is_not_written_as_cmyk() {
for monochrome in [true, false] {
let mut d = Document::with_background("mixer", Size::new(4, 4), ColorMode::Cmyk, SampleType::U8, Color::WHITE);
let matrix = [[0.4, 0.4, 0.2, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0]];
d.layers.push(Layer::new("Gray Mix", LayerContent::Adjustment(Adjustment::ChannelMixer { matrix, monochrome, cmyk: None })));
let r = export(&d, "x.psd", &ExportOptions::default()).unwrap();
let block = mixr(&PsdFile::from_bytes(&r.bytes).unwrap());
let skipped = r.warnings.iter().any(|w| w.contains("\"Gray Mix\"") && w.contains("monochrome CMYK Channel Mixer is not written"));
assert_eq!(skipped, monochrome, "{:?}", r.warnings);
if monochrome {
assert_eq!(block, None, "no inferred monochrome CMYK block");
} else {
assert_eq!(block.map(|b| b.len()), Some(44), "reshaped to Photoshop's CMYK layout");
}
}
}
@@ -293,11 +293,10 @@ pub(super) fn channel_mixer(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) ->
});
ui.data_mut(|d| d.insert_temp(out_id, out));
// Source sliders: label and the colour at the track's far end.
let sources: &[(&str, [u8; 3])] = if cmyk {
&[(tl!("Cyan"), [0, 174, 239]), (tl!("Magenta"), [236, 0, 140]), (tl!("Yellow"), [255, 222, 0]), (tl!("Black"), [35, 31, 32])]
} else {
&[(tl!("Red"), [225, 50, 50]), (tl!("Green"), [50, 190, 70]), (tl!("Blue"), [60, 100, 235])]
};
let (ink, rgb) = (t.mixer_ink, t.mixer_rgb);
let ink_sources = [(tl!("Cyan"), ink[0]), (tl!("Magenta"), ink[1]), (tl!("Yellow"), ink[2]), (tl!("Black"), ink[3])];
let rgb_sources = [(tl!("Red"), rgb[0]), (tl!("Green"), rgb[1]), (tl!("Blue"), rgb[2])];
let sources: &[(&str, Color32)] = if cmyk { &ink_sources } else { &rgb_sources };
let track_start = if cmyk { Color32::WHITE } else { Color32::BLACK };
let keys: &[&str] = if cmyk { &adjust_params::MIXER_INKS } else { &["red", "green", "blue"] };
let n = sources.len();
@@ -308,8 +307,11 @@ pub(super) fn channel_mixer(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) ->
let mut row = row_of(v, key, &fallback);
let mut e = Edit::default();
let mut changed = false;
// An imported monochrome CMYK mixer is edited only by turning Monochrome off (#8047): the
// engine refuses any other edit while it is on.
let editable = !(cmyk && mono);
for (value, (text, c)) in row.iter_mut().zip(sources) {
let r = gradient_slider(ui, text, value, -200.0..=200.0, "%", [track_start, Color32::from_rgb(c[0], c[1], c[2])], cx.dynamic_color_sliders);
let r = ui.add_enabled_ui(editable, |ui| gradient_slider(ui, text, value, -200.0..=200.0, "%", [track_start, *c], cx.dynamic_color_sliders)).inner;
changed |= r.changed;
e.add(r);
}
@@ -320,7 +322,7 @@ pub(super) fn channel_mixer(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) ->
ui.label(RichText::new(format!("{total:+.0}%")).font(crate::theme::mono(12.0)).color(if warn { t.warning } else { t.text }));
});
if let Some(constant) = row.get_mut(n) {
let r = widgets::slider_row(ui, tl!("Constant"), constant, -200.0..=200.0, "%", None);
let r = ui.add_enabled_ui(editable, |ui| widgets::slider_row(ui, tl!("Constant"), constant, -200.0..=200.0, "%", None)).inner;
changed |= r.changed();
e.add(Edit::of(&r));
}
@@ -986,9 +986,17 @@ fn channel_mixer_monochrome_is_disabled_for_cmyk_mixers() {
imported["gray"] = json!([30, 30, 30, 100, 0]);
let mut h = editor_harness("channelMixer", imported);
assert!(!h.get_by_label("Monochrome").accesskit_node().is_disabled(), "imported monochrome CMYK: can turn it off");
// The engine refuses any other edit of it, so the source and Constant fields are disabled.
let fields = |h: &Harness<'static, serde_json::Value>| {
h.query_all_by_role(egui::accesskit::Role::SpinButton).map(|n| n.accesskit_node().is_disabled()).collect::<Vec<_>>()
};
let locked = fields(&h);
assert!(!locked.is_empty() && locked.iter().all(|d| *d), "the source and Constant fields are disabled while Monochrome is on: {locked:?}");
h.get_by_label("Monochrome").click();
h.run_steps(3);
assert_eq!(h.state()["monochrome"], json!(false), "{}", h.state());
let open = fields(&h);
assert!(!open.is_empty() && open.iter().all(|d| !*d), "turning Monochrome off enables them again: {open:?}");
let mut h = editor_harness("channelMixer", json!({"red": [100, 0, 0, 0], "green": [0, 100, 0, 0], "blue": [0, 0, 100, 0], "monochrome": false}));
assert!(!h.get_by_label("Monochrome").accesskit_node().is_disabled(), "RGB: enabled");
+28
View File
@@ -211,6 +211,12 @@ pub struct Tokens {
pub caption_close_text: Color32,
/// Dims the main window behind a modal that takes all input (Camera Raw).
pub scrim: Color32,
/// Channel Mixer source tracks: the colour at the far end of the red, green and blue
/// sliders (each starts at black, no light).
pub mixer_rgb: [Color32; 3],
/// Channel Mixer source tracks in a CMYK document: cyan, magenta, yellow and black ink
/// (each starts at white, no ink).
pub mixer_ink: [Color32; 4],
}
impl Tokens {
@@ -331,6 +337,8 @@ impl Tokens {
caption_close: Color32::from_rgb(196, 43, 28),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
ThemeKind::Studio => Tokens {
kind,
@@ -373,6 +381,8 @@ impl Tokens {
caption_close: Color32::from_rgb(196, 43, 28),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
ThemeKind::StudioLight => Tokens {
kind,
@@ -413,6 +423,8 @@ impl Tokens {
caption_close: Color32::from_rgb(196, 43, 28),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
ThemeKind::Classic => Tokens {
kind,
@@ -453,6 +465,8 @@ impl Tokens {
caption_close: Color32::from_rgb(196, 43, 28),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
// libadwaita's named colours (window, sidebar, card, view, accent, destructive) and
// radii (6 px buttons, 12 px cards), mapped onto the Studio layout. GNOME's close
@@ -496,6 +510,8 @@ impl Tokens {
caption_close: Color32::from_rgb(212, 212, 216),
caption_close_text: Color32::from_rgb(50, 50, 54),
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
ThemeKind::AdwaitaDark => Tokens {
kind,
@@ -536,6 +552,8 @@ impl Tokens {
caption_close: Color32::from_rgb(72, 72, 76),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
// The light counterpart, adapted the same way: our own values, chosen a few levels
// from Breeze Light's surfaces so the app blends into a Plasma desktop without being a
@@ -582,6 +600,8 @@ impl Tokens {
caption_close: Color32::from_rgb(213, 51, 60),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
// An adaptation of KDE Plasma's Breeze Dark look on the Studio layout, not a copy: our
// own values, chosen a few levels from Breeze Dark's surfaces (the darkest canvas, then
@@ -632,6 +652,8 @@ impl Tokens {
caption_close: Color32::from_rgb(213, 51, 60),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
// Soft Dark: our own low-contrast palette on the Studio layout. Muted violet-grey
// surfaces (never near-black), softened off-white text and a periwinkle accent; the
@@ -675,6 +697,8 @@ impl Tokens {
caption_close: Color32::from_rgb(200, 72, 86),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(100),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
// Soft Light: pale violet-grey surfaces, softened dark-violet text (not black) and a
// periwinkle accent, with the same generous radii as Soft Dark.
@@ -717,6 +741,8 @@ impl Tokens {
caption_close: Color32::from_rgb(200, 60, 72),
caption_close_text: Color32::WHITE,
scrim: Color32::from_black_alpha(90),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
// Ethan Schoonover's Solarized Dark palette: base03 canvas, base02 surfaces, base0
// body text and the Solarized blue accent. https://ethanschoonover.com/solarized/
@@ -760,6 +786,8 @@ impl Tokens {
caption_close: Color32::from_rgb(220, 50, 47),
caption_close_text: Color32::from_rgb(253, 246, 227),
scrim: Color32::from_black_alpha(110),
mixer_rgb: [Color32::from_rgb(225, 50, 50), Color32::from_rgb(50, 190, 70), Color32::from_rgb(60, 100, 235)],
mixer_ink: [Color32::from_rgb(0, 174, 239), Color32::from_rgb(236, 0, 140), Color32::from_rgb(255, 222, 0), Color32::from_rgb(35, 31, 32)],
},
}
}