diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index e519e6d4fb..c0cef67a5e 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -28,6 +28,7 @@ next to them. | `assets/app-icon/photocraft-nightly.png`, `photocraft-nightly-1024.png`, `photocraft-nightly.ico`, `photocraft-nightly.icns` | PhotoCraft nightly deep-background derivatives | @skylartaylor | Original project-owned256 and padded1024 masters at the revision and hashes in [`nightly-provenance.json`](assets/app-icon/nightly-provenance.json); code-generated background-contribution change only, preserving foreground/alpha; no badge or crescent | MIT OR Apache-2.0, [`assets/app-icon/LICENSE.txt`](assets/app-icon/LICENSE.txt) | | `packaging/nightly-archive-tests.py` (runtime-generated temporary files) | Synthetic flat-archive inventory and exclusive-output fixtures; regular-file payloads, not real image/executable validity | @skylartaylor | Original test-generated strings/files and symlinks from the committed script; no external media or user documents | MIT OR Apache-2.0 | | `packaging/macos/dmg/` (all files) | PhotoCraft DMG window background and layout | @XusBadia, from the PhotoCraft app icon | Original work, see [`packaging/macos/dmg/README.md`](packaging/macos/dmg/README.md) | MIT OR Apache-2.0, like the code | +| `crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs` | Built-in Black & White tonal and filter mixes | PhotoCraft contributors (@Bobderto) | Original weights chosen to produce the named tonal and color-filter effects, from [PhotoCraft `2b1afe637`](https://github.com/storytold/photocraft/commit/2b1afe637cabe3eba622c8edd3e92b279aa8dfe4) | MIT OR Apache-2.0 | | `crates/ui-egui/src/theme.rs` (Solarized Dark palette) | Solarized colour scheme used by the Solarized Dark theme | Ethan Schoonover | | MIT, [`LICENSE-solarized.txt`](crates/ui-egui/src/LICENSE-solarized.txt) | | `crates/ui-egui/src/theme.rs` (Breeze Light and Breeze Dark themes) | The Breeze Light and Breeze Dark themes are original colour values on PhotoCraft's Studio layout, chosen to look close to KDE Plasma's Breeze (cool blue-greys, blue accent, 5 px frame radius) so the app blends into a Plasma desktop. None of Breeze's colour values, files or code are copied; the values are a few levels away from its schemes and tuned for text contrast | PhotoCraft contributors | Inspired by the look of KDE Breeze, (its colour schemes are LGPL-2.0-or-later) | Original work | | `crates/ui-egui/src/theme.rs` (Soft Dark and Soft Light themes) | Original colour values and radii for two low-contrast themes on PhotoCraft's Studio layout; no third-party palette, file or code is used | PhotoCraft contributors | Original | Original work | diff --git a/crates/ui-egui/src/dialogs/adjust_editors.rs b/crates/ui-egui/src/dialogs/adjust_editors.rs index 7558da5ea0..25daf7c2b3 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors.rs @@ -17,9 +17,9 @@ use craft::behavior::{EditEvent, EditEvents, Mixed}; use craft::color_ui::ui::gradient::{ColorStop, GradientStops}; use craft::draw::ui::gradient::{GradientGroup, GradientItem, GradientMap, GradientMapEditor, GradientMapOutput}; use craft::imaging::ui::adjust::{ - AdjustDialogCx, AdjustField, AdjustSliders, AdjustWords, BlackWhite, BlackWhiteEditor, BrightnessContrast, BrightnessContrastEditor, ChannelMixer, - ChannelMixerEditor, ColorBalance, ColorBalanceEditor, ColorBalanceTone, CurvesPanel, HueSaturation, HueSaturationEditor, Levels, LevelsClip, LevelsPanel, - PhotoFilter, PhotoFilterEditor, SelectiveColor, SelectiveColorEditor, ThresholdEditor, ToneChannels, ToneCurves, ToneSpace, + AdjustDialogCx, AdjustField, AdjustSliders, AdjustWords, BlackWhite, BrightnessContrast, BrightnessContrastEditor, ChannelMixer, ChannelMixerEditor, + ColorBalance, ColorBalanceEditor, ColorBalanceTone, CurvesPanel, HueSaturation, HueSaturationEditor, Levels, LevelsClip, LevelsPanel, PhotoFilter, + PhotoFilterEditor, SelectiveColor, SelectiveColorEditor, ThresholdEditor, ToneChannels, ToneCurves, ToneSpace, }; use craft::imaging::ui::histogram::{ChannelColor, HistogramData}; use craft::theme::Srgba; @@ -35,6 +35,7 @@ use serde_json::{Value, json}; use crate::PhotocraftApp; +pub(crate) mod black_white_presets; mod session; pub mod values; @@ -320,11 +321,7 @@ fn show(kind: &str, setup: &EditorSetup, ui: &mut Ui, value: &mut AdjustValue, c let out = editor.show(ui); AdjustOut { tone: Some(out.tone), ..lifted(out.edit.events, |value| AdjustValue::ColorBalance { value }) } } - ("blackWhite", AdjustValue::BlackWhite { value }) => { - let out = BlackWhiteEditor::new("Black & White", Bind::bound(value)).context(context).show(ui); - let ask = if out.auto { Some(AdjustAsk::Auto) } else { out.pick_color.map(AdjustAsk::PickColor) }; - AdjustOut { ask, edit: out.edit.events.map(|value| AdjustValue::BlackWhite { value }), tone: None } - } + ("blackWhite", AdjustValue::BlackWhite { value }) => black_white_presets::show(ui, value, context), ("photoFilter", AdjustValue::PhotoFilter { value }) => { let out = PhotoFilterEditor::new("Photo Filter", Bind::bound(value)).context(context).show(ui); AdjustOut { ask: out.pick_color.map(AdjustAsk::PickColor), edit: out.edit.events.map(|value| AdjustValue::PhotoFilter { value }), tone: None } diff --git a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs new file mode 100644 index 0000000000..ec3456bc83 --- /dev/null +++ b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs @@ -0,0 +1,105 @@ +//! Original Black & White recipes for tonal shifts and the effect of color filters. + +use std::sync::Arc; + +use craft::behavior::{EditEvent, EditEvents, Mixed}; +use craft::imaging::ui::adjust::{AdjustContext, AdjustWords, BlackWhite, BlackWhiteEditor}; +use craft::ui::contract::{Bind, Entry, Show as _, ShowContainer as _}; +use craft::ui::form::Field; +use craft::ui::pickers::Select; +use craft::ui::runtime::env::Env; +use egui::Ui; + +use super::{AdjustAsk, AdjustOut, AdjustValue}; + +type Mix = [f64; 6]; + +/// The presets change the grayscale mix and keep the layer's tint settings. +fn entries() -> [Entry>; 16] { + [ + Entry::new(Some(BlackWhite::DEFAULT_WEIGHTS), tl!("Default")), + Entry::separator(), + Entry::new(Some([22.0, 38.0, 25.0, 36.0, 10.0, 50.0]), tl!("Darker")), + Entry::new(Some([60.0, 77.0, 64.0, 78.0, 47.0, 92.0]), tl!("Lighter")), + Entry::new(Some([8.0; 6]), tl!("Deep Shadows")), + Entry::new(Some([92.0; 6]), tl!("Bright Highlights")), + Entry::new(Some([48.0; 6]), tl!("Even Color Weights")), + Entry::new(Some([86.0, 65.0, 33.0, 23.0, 15.0, 72.0]), tl!("Red Filter")), + Entry::new(Some([64.0, 91.0, 64.0, 41.0, 13.0, 53.0]), tl!("Yellow Filter")), + Entry::new(Some([28.0, 67.0, 91.0, 74.0, 17.0, 45.0]), tl!("Green Filter")), + Entry::new(Some([24.0, 35.0, 45.0, 77.0, 92.0, 53.0]), tl!("Blue Filter")), + Entry::new(Some([100.0, 73.0, 24.0, 7.0, 5.0, 64.0]), tl!("Strong Red Filter")), + Entry::new(Some([4.0, 12.0, 27.0, 71.0, 100.0, 44.0]), tl!("Strong Blue Filter")), + Entry::new(Some([58.0, 89.0, 97.0, 38.0, 8.0, 33.0]), tl!("Infrared Foliage")), + Entry::separator(), + Entry::new(None, tl!("Custom")), + ] +} + +/// A manual edit can land on exactly the weights of a named recipe. Remember that edit locally +/// so its value still shows as Custom. The Properties inspector scopes this memory to its target. +#[derive(Clone, Copy, PartialEq)] +struct ManualValue { + weights: Mix, + tint: Option<[u8; 3]>, +} + +impl From for ManualValue { + fn from(value: BlackWhite) -> Self { + let [r, g, b, _] = value.tint_color.to_rgba().0; + Self { weights: value.weights, tint: value.tint.then_some([r, g, b]) } + } +} + +fn manual_id(ui: &Ui) -> egui::Id { + ui.make_persistent_id("black-white-manual-value") +} + +pub(crate) fn clear_custom(ui: &Ui) { + ui.data_mut(|d| d.remove::(manual_id(ui))); + ui.ctx().request_repaint(); +} + +/// The Properties host applies accepted Color Picker colors and Auto outside the editor's pass. +pub(super) fn mark_custom(ui: &Ui, value: &AdjustValue) { + if let AdjustValue::BlackWhite { value } = value { + ui.data_mut(|d| d.insert_temp(manual_id(ui), ManualValue::from(*value))); + } +} + +pub(super) fn show(ui: &mut Ui, value: &mut BlackWhite, context: AdjustContext) -> AdjustOut { + let id = manual_id(ui); + let mut manual = ui.data(|d| d.get_temp::(id)); + let entries = entries(); + let shown = (manual != Some((*value).into()) && entries.iter().any(|entry| entry.value() == Some(&Some(value.weights)))).then_some(value.weights); + let label = tl!("Preset"); + let picked = Field::new(label).show(ui, |ui, _| Select::new(label, Bind::given(shown), &entries).show(ui).events.committed().copied()).inner.flatten(); + let mut edit = EditEvents::new(); + if let Some(picked) = picked { + manual = picked.is_none().then(|| (*value).into()); + if let Some(weights) = picked + && weights != value.weights + { + let before = *value; + value.weights = weights; + edit.push(EditEvent::set(Mixed::Same(before), *value, Arc::from(label), None)); + } + } + + let out = BlackWhiteEditor::new("Black & White", Bind::bound(&mut *value)).context(context).show(ui); + if let Some(after) = out.edit.events.committed() { + let words = Env::of(ui).words::(); + let reset = matches!(out.edit.events.ended(), Some(EditEvent::Set { label, .. }) if label.as_ref() == words.default_button.as_str()); + manual = (!reset).then(|| (*after).into()); + } + ui.data_mut(|d| match manual { + Some(value) => { + d.insert_temp(id, value); + } + None => d.remove::(id), + }); + + let ask = if out.auto { Some(AdjustAsk::Auto) } else { out.pick_color.map(AdjustAsk::PickColor) }; + edit.extend(out.edit.events); + AdjustOut { ask, edit: edit.map(|value| AdjustValue::BlackWhite { value }), tone: None } +} diff --git a/crates/ui-egui/src/dialogs/adjust_editors/session.rs b/crates/ui-egui/src/dialogs/adjust_editors/session.rs index 6fda7a035e..2739288577 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/session.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/session.rs @@ -13,7 +13,7 @@ use photocraft_engine::adjust_params; use serde_json::{Value, json}; use super::values::{self, ValueCx}; -use super::{AdjustAsk, AdjustValue, EditorSetup, answer_color, black_white_auto, editor, gradient_presets, is_gray, swatches}; +use super::{AdjustAsk, AdjustValue, EditorSetup, answer_color, black_white_auto, black_white_presets, editor, gradient_presets, is_gray, swatches}; use crate::PhotocraftApp; use crate::color_picker_ui::PickWindow; use crate::theme::Tokens; @@ -192,7 +192,7 @@ pub fn layer_editor(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: LayerId, adj // put while it shows this layer, replays included. record.session.track(session_target(doc, id), app.properties_hidden, &committed); } - follow_color_pick(app, id, &mut record, &committed, &vcx); + follow_color_pick(app, ui, id, &mut record, &committed, &vcx); let mut value = match &app.live_adjust { Some((layer, params)) if *layer == id => values::from_params(kind, params, &vcx).unwrap_or_else(|_| committed.clone()), _ => committed.clone(), @@ -246,7 +246,12 @@ pub fn layer_editor(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: LayerId, adj target.extend(weights); } match values::from_params(kind, ¶ms, &vcx) { - Ok(auto) => commit(app, id, &mut record, &committed, &auto, &vcx, None), + Ok(auto) => { + if auto != committed { + black_white_presets::mark_custom(ui, &auto); + } + commit(app, id, &mut record, &committed, &auto, &vcx, None); + } Err(err) => app.ui.status = err, } } @@ -294,7 +299,7 @@ fn commit( /// A colour well's Color Picker while it is open: its colour previews on the layer. Once it /// closed, OK's colour is one edit and Cancel (or OK without a colour) leaves the layer as it was. -fn follow_color_pick(app: &mut PhotocraftApp, id: LayerId, record: &mut PropertiesAdjust, committed: &AdjustValue, vcx: &ValueCx) { +fn follow_color_pick(app: &mut PhotocraftApp, ui: &egui::Ui, id: LayerId, record: &mut PropertiesAdjust, committed: &AdjustValue, vcx: &ValueCx) { let Some(pick) = record.pick.take() else { return }; match app.framework.dialogs.get_by_id::(pick.dialog).map(ColorPickerDialog::current) { Some(current) => { @@ -310,6 +315,9 @@ fn follow_color_pick(app: &mut PhotocraftApp, id: LayerId, record: &mut Properti Some((key, color)) if key == pick.key && Some(color) != pick.opened => { let mut answered = pick.before; if answer_color(&mut answered, &key, color) { + if answered != *committed { + black_white_presets::mark_custom(ui, &answered); + } commit(app, id, record, committed, &answered, vcx, None); } else { app.live_adjust = None; diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index fa23887d65..87493748f5 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -492,3 +492,154 @@ fn black_white_auto_button_sets_the_weights() { assert_ne!(after, before, "the red and blue are told apart"); assert_eq!(history_len(&h), steps + 1); } + +#[track_caller] +fn assert_black_white_preset(h: &Harness<'_, Box>, name: &str) { + assert_eq!(h.get_by_role_and_label(Role::ComboBox, "Preset").accesskit_node().value().as_deref(), Some(name)); +} + +#[test] +fn black_white_presets_apply_the_authored_weights_and_keep_tint() { + let mut h = app_harness("blackWhite", "rgb", 8); + // Leave enough vertical space for the complete dropdown to be visible at once. + h.set_size(vec2(1440.0, 1350.0)); + let (id, _) = layer(&h); + h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "tint": true, "tintColor": "#336699"})).unwrap(); + h.run_steps(4); + let (_, original) = layer(&h); + let Adjustment::BlackWhite { tint: original_tint, .. } = &original else { panic!("{original:?}") }; + + for (name, expected) in [ + ("Darker", [22.0, 38.0, 25.0, 36.0, 10.0, 50.0]), + ("Lighter", [60.0, 77.0, 64.0, 78.0, 47.0, 92.0]), + ("Deep Shadows", [8.0; 6]), + ("Bright Highlights", [92.0; 6]), + ("Even Color Weights", [48.0; 6]), + ("Red Filter", [86.0, 65.0, 33.0, 23.0, 15.0, 72.0]), + ("Yellow Filter", [64.0, 91.0, 64.0, 41.0, 13.0, 53.0]), + ("Green Filter", [28.0, 67.0, 91.0, 74.0, 17.0, 45.0]), + ("Blue Filter", [24.0, 35.0, 45.0, 77.0, 92.0, 53.0]), + ("Strong Red Filter", [100.0, 73.0, 24.0, 7.0, 5.0, 64.0]), + ("Strong Blue Filter", [4.0, 12.0, 27.0, 71.0, 100.0, 44.0]), + ("Infrared Foliage", [58.0, 89.0, 97.0, 38.0, 8.0, 33.0]), + ("Default", [40.0, 60.0, 40.0, 60.0, 20.0, 80.0]), + ] { + let history = history_len(&h); + h.get_by_role_and_label(Role::ComboBox, "Preset").click(); + h.run_steps(3); + h.get_by_role_and_label(Role::ListBoxOption, name).click(); + h.run_steps(4); + + let (_, applied) = layer(&h); + let Adjustment::BlackWhite { weights, tint } = applied else { panic!("{applied:?}") }; + assert_eq!(weights, expected, "{name} applies the authored mix"); + assert_black_white_preset(&h, name); + assert_eq!(&tint, original_tint, "{name} preserves Tint"); + assert_eq!(history_len(&h), history + 1, "{name} is one history step"); + assert!(h.state().live_adjust.is_none(), "{name} finishes the preview"); + } + assert_eq!(layer(&h).1, original, "Default restores the original mix"); +} + +#[test] +fn black_white_presets_apply_through_properties_and_undo() { + let mut h = app_harness("blackWhite", "rgb", 8); + let (id, _) = layer(&h); + h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "tint": true, "tintColor": "#336699"})).unwrap(); + h.run_steps(4); + let (_, before) = layer(&h); + let Adjustment::BlackWhite { weights: original, tint: original_tint } = &before else { panic!("{before:?}") }; + let history = history_len(&h); + let pixel = h.state_mut().run("document.pixel", json!({"x": 10, "y": 10})).unwrap(); + assert_black_white_preset(&h, "Default"); + + h.get_by_role_and_label(Role::ComboBox, "Preset").click(); + h.run_steps(3); + h.get_by_role_and_label(Role::ListBoxOption, "Darker").click(); + h.run_steps(4); + assert_black_white_preset(&h, "Darker"); + let (_, after) = layer(&h); + let Adjustment::BlackWhite { weights, tint } = &after else { panic!("{after:?}") }; + assert!(weights.iter().zip(original).all(|(weight, original)| weight < original)); + assert_eq!(tint, original_tint); + assert_ne!(h.state_mut().run("document.pixel", json!({"x": 10, "y": 10})).unwrap(), pixel); + assert_eq!(history_len(&h), history + 1); + assert!(h.state().live_adjust.is_none()); + + let ctx = h.ctx.clone(); + let picker = open_picker(&mut h, "Tint Color"); + show_in_picker(&mut h, picker, "#ad632a"); + h.state_mut().framework.dialogs.cancel_by_id(&ctx, picker); + h.run_steps(4); + assert_black_white_preset(&h, "Darker"); + assert_eq!(layer(&h).1, after); + assert_eq!(history_len(&h), history + 1); + + let picker = open_picker(&mut h, "Tint Color"); + show_in_picker(&mut h, picker, "#ad632a"); + crate::dialogs::confirm(h.state_mut(), &ctx, picker).expect("OK is enabled"); + h.run_steps(4); + assert_black_white_preset(&h, "Custom"); + assert_eq!(history_len(&h), history + 2); + + h.state_mut().run("edit.undo", json!({})).unwrap(); + h.run_steps(4); + assert_eq!(layer(&h).1, after); + assert_black_white_preset(&h, "Darker"); + h.state_mut().run("edit.undo", json!({})).unwrap(); + h.run_steps(4); + assert_eq!(layer(&h).1, before); + assert_black_white_preset(&h, "Default"); +} + +#[test] +fn black_white_presets_distinguish_manual_edits_from_named_choices() { + let mut h = app_harness("blackWhite", "rgb", 8); + // Opening the dropdown on Custom reveals the last row, so leave room for Default too. + h.set_size(vec2(1440.0, 1350.0)); + let (id, defaults) = layer(&h); + let Adjustment::BlackWhite { weights, .. } = &defaults else { panic!("{defaults:?}") }; + let red = weights[0]; + let type_default = |h: &mut Harness<'_, Box>| { + h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "reds": red + 7.0})).unwrap(); + h.run_steps(4); + assert_black_white_preset(h, "Custom"); + h.get_by_role_and_label(Role::SpinButton, "Reds").click(); + h.run_steps(1); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text(red.to_string())); + h.run_steps(1); + h.key_press(egui::Key::Tab); + h.run_steps(4); + assert_eq!(layer(h).1, defaults); + assert_black_white_preset(h, "Custom"); + }; + + type_default(&mut h); + + h.state_mut().run("layer.newAdjustmentLayer.blackWhite", json!({})).unwrap(); + h.run_steps(4); + assert_black_white_preset(&h, "Default"); + h.state_mut().run("layer.select", json!({"layer": id.0})).unwrap(); + // Layer selection can keep the mask targeted. Return to the adjustment's controls. + h.state_mut().run("channel.target.composite", json!({})).unwrap(); + h.run_steps(4); + assert_black_white_preset(&h, "Custom"); + + let history = history_len(&h); + h.get_by_role_and_label(Role::ComboBox, "Preset").click(); + h.run_steps(3); + h.get_by_role_and_label(Role::ListBoxOption, "Default").click(); + h.run_steps(4); + assert_black_white_preset(&h, "Default"); + assert_eq!(layer(&h).1, defaults); + assert_eq!(history_len(&h), history); + + type_default(&mut h); + h.get_by_role_and_label(Role::Button, "Reset to defaults").scroll_to_me(); + h.run_steps(2); + h.get_by_role_and_label(Role::Button, "Reset to defaults").click(); + h.run_steps(4); + assert_black_white_preset(&h, "Default"); + assert_eq!(layer(&h).1, defaults); +} diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index e49b0666d8..c883be58aa 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -159,6 +159,9 @@ fn adjustment_controls(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: LayerId, let params = crate::adjust_editors::layer_reset(app, id, adj); let _ = app.run("layer.setAdjustment", params); app.live_adjust = None; + if matches!(adj, photocraft_doc::Adjustment::BlackWhite { .. }) { + crate::adjust_editors::black_white_presets::clear_custom(ui); + } } }