diff --git a/crates/engine/src/layer_style.rs b/crates/engine/src/layer_style.rs index 37317609d5..377867a7d1 100644 --- a/crates/engine/src/layer_style.rs +++ b/crates/engine/src/layer_style.rs @@ -157,7 +157,7 @@ pub fn effect_defaults(kind: &str) -> Value { json!({"blend": "Screen", "opacity": 35, "color": "#ffffff", "technique": "softer", "spread": 0, "size": 7, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0}) } "innerGlow" => { - json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "technique": "softer", "source": "edge", "choke": 0, "size": 5, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0}) + json!({"blend": "Screen", "opacity": 35, "color": "#ffffff", "technique": "softer", "source": "edge", "choke": 0, "size": 7, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0}) } "stroke" => json!({"size": 1, "position": "inside", "blend": "Normal", "opacity": 100, "overprint": false, "color": "#000000"}), "colorOverlay" => json!({"blend": "Normal", "color": "#ff0000", "opacity": 100}), @@ -566,15 +566,13 @@ fn fresh_effect(kind: &str) -> Option { noise: 0.0, knocks_out: !inner, }; - // The two glows share their shape, but not their factory values: the Outer Glow starts at - // the reference application's white 35 % Size 7 (#14944), the Inner Glow at today's values - // until #14917 measures its own. - let glow = |inner: bool| Glow { - common: FxCommon::new(BlendMode::Screen, if inner { 0.75 } else { 0.35 }), - paint: FxPaint::Color(if inner { Color::rgb(1.0, 1.0, 190.0 / 255.0) } else { Color::WHITE }), + // Both glows start at the reference application's white 35 % Size 7 (#14944, #14917). + let glow = || Glow { + common: FxCommon::new(BlendMode::Screen, 0.35), + paint: FxPaint::Color(Color::WHITE), technique: GlowTechnique::Softer, spread: 0.0, - size: if inner { 5.0 } else { 7.0 }, + size: 7.0, contour: Contour::Linear, anti_alias: false, range: 0.5, @@ -585,8 +583,8 @@ fn fresh_effect(kind: &str) -> Option { Some(match kind { "dropShadow" => Effect::DropShadow(shadow(false)), "innerShadow" => Effect::InnerShadow(shadow(true)), - "outerGlow" => Effect::OuterGlow(glow(false)), - "innerGlow" => Effect::InnerGlow(glow(true)), + "outerGlow" => Effect::OuterGlow(glow()), + "innerGlow" => Effect::InnerGlow(glow()), "stroke" => Effect::Stroke(StrokeFx { common: FxCommon::new(BlendMode::Normal, 1.0), size: 1.0, @@ -1176,7 +1174,7 @@ pub fn specs() -> Vec { style_cmd!( "innerGlow", "Inner Glow…", - r##"{"color":"#rrggbb","opacity":0..100=75,"blend":str="screen","technique":"softer|precise","source":"edge|center","choke":0..100,"size":px,"range":1..100=50,"contour":name|curve,"antiAlias":bool,"noise":0..100,"add":bool}"## + r##"{"color":"#rrggbb","opacity":0..100=35,"blend":str="screen","technique":"softer|precise","source":"edge|center","choke":0..100,"size":px,"range":1..100=50,"contour":name|curve,"antiAlias":bool,"noise":0..100,"add":bool}"## ), style_cmd!( "stroke", @@ -1287,6 +1285,9 @@ fn delete_effect(s: &mut Session, p: &Value, effect: &Value) -> Result { #[cfg(test)] mod outer_glow_defaults_tests; +#[cfg(test)] +mod inner_glow_defaults_tests; + #[cfg(test)] mod inner_shadow_ranges_tests; #[cfg(test)] diff --git a/crates/engine/src/layer_style/inner_glow_defaults_tests.rs b/crates/engine/src/layer_style/inner_glow_defaults_tests.rs new file mode 100644 index 0000000000..0d98a49a88 --- /dev/null +++ b/crates/engine/src/layer_style/inner_glow_defaults_tests.rs @@ -0,0 +1,121 @@ +//! #14917: the Inner Glow page's factory values (Screen, 35 %, Noise 0, white, Softer, Edge, +//! Choke 0, Size 7, Linear, Anti-aliased off, Range 50) and the rule that a glow already stored +//! keeps its own values. The measured pixels of the factory glow sit within 1 level of the +//! reference application's on the white test document. + +use super::*; +use crate::Session; +use serde_json::json; + +/// The issue's test document: 400 x 300 px at 72 ppi, RGB 8 bit, a white Background and a pixel +/// layer with an orange (255,128,0) rectangle at x 100..299, y 75..224. +fn test_document() -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 400, "height": 300, "resolution": 72, "background": "#ffffff"})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + s.execute("select.rect", json!({"x": 100, "y": 75, "width": 200, "height": 150})).unwrap(); + s.execute("edit.fill", json!({"contents": "color", "color": "#ff8000"})).unwrap(); + s.execute("select.deselect", json!({})).unwrap(); + s +} + +fn session() -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + s +} + +/// The one glow the active layer carries, as an inner glow. +fn inner_glow(s: &Session) -> Glow { + let d = s.active().unwrap(); + let l = d.doc.layer(d.active_layer.unwrap()).unwrap(); + match l.effects.items.as_slice() { + [Effect::InnerGlow(g)] => g.clone(), + other => panic!("no inner glow: {other:?}"), + } +} + +/// #14917: Layer > Layer Style > Inner Glow... on a layer without one starts from the reference +/// application's factory values; the dialog seeds a new instance from `effect_defaults`. +#[test] +fn a_new_inner_glow_starts_at_the_factory_values() { + let d = effect_defaults("innerGlow"); + assert_eq!(d["blend"], json!("Screen"), "blend"); + assert_eq!(d["opacity"], json!(35), "opacity"); + assert_eq!(d["noise"], json!(0), "noise"); + assert_eq!(d["color"], json!("#ffffff"), "colour"); + assert_eq!(d["technique"], json!("softer"), "technique"); + assert_eq!(d["source"], json!("edge"), "source"); + assert_eq!(d["choke"], json!(0), "choke"); + assert_eq!(d["size"], json!(7), "size"); + assert_eq!(d["contour"], json!("Linear"), "contour"); + assert_eq!(d["antiAlias"], json!(false), "anti-aliased"); + assert_eq!(d["range"], json!(50), "range"); +} + +/// #14917: `layer.layerStyle.innerGlow` without params makes the same effect the page starts at. +#[test] +fn an_inner_glow_command_without_params_makes_the_factory_effect() { + let mut s = session(); + s.execute("layer.layerStyle.innerGlow", json!({})).unwrap(); + let g = inner_glow(&s); + assert_eq!(g.common.blend, BlendMode::Screen, "blend mode"); + assert!((g.common.opacity * 100.0 - 35.0).abs() < 1e-4, "opacity {} %", g.common.opacity * 100.0); + let FxPaint::Color(c) = g.paint else { panic!("not a plain colour: {:?}", g.paint) }; + let rgb = c.to_rgb(); + assert!(rgb.iter().all(|v| (v - 1.0).abs() < 1e-4), "colour {rgb:?} is not white"); + assert_eq!((g.technique, g.source, g.spread, g.size), (GlowTechnique::Softer, GlowSource::Edge, 0.0, 7.0)); + assert!(matches!(g.contour, Contour::Linear), "contour {:?}", g.contour); + assert!(!g.anti_alias, "anti-aliased"); + assert!((g.range - 0.5).abs() < 1e-4, "range {}", g.range); + assert_eq!(g.noise, 0.0, "noise"); +} + +/// #14917: Reset to Default reads these factory values through `layer.layerStyle.defaultFor` +/// until a Make Default stores other ones; the saved values keep winning (the Make Default path +/// is not measured, so it keeps today's behaviour). +#[test] +fn reset_to_default_restores_the_inner_glow_factory_values() { + let mut s = session(); + let d = s.execute("layer.layerStyle.defaultFor", json!({"kind": "innerGlow"})).unwrap(); + assert_eq!(d["user"], json!(false)); + assert_eq!((d["params"]["opacity"].as_f64(), d["params"]["color"].as_str(), d["params"]["size"].as_f64()), (Some(35.0), Some("#ffffff"), Some(7.0))); + s.execute("layer.layerStyle.makeDefault", json!({"kind": "innerGlow", "params": {"opacity": 12, "size": 3}})).unwrap(); + let saved = s.execute("layer.layerStyle.defaultFor", json!({"kind": "innerGlow"})).unwrap(); + assert_eq!(saved["user"], json!(true)); + assert_eq!((saved["params"]["opacity"].as_f64(), saved["params"]["size"].as_f64()), (Some(12.0), Some(3.0)), "a saved default still wins"); +} + +/// #14917 measured: OK on the factory values over the white test document. Top edge of the +/// flattened image at x 200, y 75 inwards to 81, R.G.B; the reference application's are +/// 255.166.76 255.155.54 255.146.36 255.139.22 255.133.11 255.129.3 255.128.0, within 1 level. +#[test] +fn the_factory_inner_glow_paints_the_measured_edge() { + let mut s = test_document(); + s.execute("layer.layerStyle.innerGlow", json!({})).unwrap(); + let d = s.active().unwrap(); + let px = photocraft_compose::render(&d.doc, d.doc.bounds()).into_px(); + let rgb = |x: usize, y: usize| px[y * 400 + x].map(|v| (v * 255.0).round() as i32); + for (y, want) in + [(75, [255, 166, 76]), (76, [255, 155, 54]), (77, [255, 146, 36]), (78, [255, 139, 22]), (79, [255, 133, 11]), (80, [255, 129, 3]), (81, [255, 128, 0])] + { + let got = rgb(200, y); + assert!(got[..3].iter().zip(want).all(|(g, w)| (g - w).abs() <= 1), "top edge at (200, {y}): {:?}, the reference gives {want:?}", &got[..3]); + } +} + +/// #14917: an Inner Glow the document already carries keeps the values it was read with. The +/// Layer Style dialog's OK (and so a PSD or `.pcraft` effect edited in it) goes through +/// `layer.layerStyle.replace` with the effect's own snapshot: absent params leave it alone. +#[test] +fn a_stored_inner_glow_keeps_its_own_values_through_replace() { + let mut s = session(); + s.execute("layer.layerStyle.innerGlow", json!({"opacity": 75, "color": "#ffffbe", "size": 5})).unwrap(); + let stored = inner_glow(&s); + let snapshot = serde_json::to_value(Effect::InnerGlow(stored.clone())).unwrap(); + s.execute("layer.layerStyle.replace", json!({"effects": [{"kind": "innerGlow", "params": {}, "fx": snapshot}]})).unwrap(); + let kept = inner_glow(&s); + assert_eq!(kept, stored, "an edited effect list left the glow's values alone"); + assert!((kept.common.opacity * 100.0 - 75.0).abs() < 1e-4 && (kept.size - 5.0).abs() < 1e-4, "kept {kept:?}"); +} diff --git a/crates/engine/src/layer_style/outer_glow_defaults_tests.rs b/crates/engine/src/layer_style/outer_glow_defaults_tests.rs index 3fdac39f7e..4e1a74a4bb 100644 --- a/crates/engine/src/layer_style/outer_glow_defaults_tests.rs +++ b/crates/engine/src/layer_style/outer_glow_defaults_tests.rs @@ -119,22 +119,3 @@ fn a_stored_outer_glow_keeps_its_own_values_through_replace() { assert_eq!(kept, stored, "an edited effect list left the glow's values alone"); assert!((kept.common.opacity * 100.0 - 75.0).abs() < 1e-4 && (kept.size - 5.0).abs() < 1e-4, "kept {kept:?}"); } - -/// #14944 is only about the Outer Glow page; the Inner Glow's factory values are #14917 and stay -/// as they are today (the two glows share their fresh effect in the engine). -#[test] -fn an_inner_glow_still_starts_at_todays_values() { - let d = effect_defaults("innerGlow"); - assert_eq!((d["opacity"].as_f64(), d["color"].as_str(), d["size"].as_f64()), (Some(75.0), Some("#ffffbe"), Some(5.0))); - let mut s = session(); - s.execute("layer.layerStyle.innerGlow", json!({})).unwrap(); - let g = match &s.active().unwrap().doc.layer(s.active().unwrap().active_layer.unwrap()).unwrap().effects.items[0] { - Effect::InnerGlow(g) => g.clone(), - other => panic!("{other:?}"), - }; - assert!((g.common.opacity * 100.0 - 75.0).abs() < 1e-4, "opacity {}", g.common.opacity); - assert_eq!(g.size, 5.0, "size"); - let FxPaint::Color(c) = g.paint else { panic!("{:?}", g.paint) }; - let rgb = c.to_rgb(); - assert!((rgb[0] - 1.0).abs() < 1e-3 && (rgb[1] - 1.0).abs() < 1e-3 && (rgb[2] - 190.0 / 255.0).abs() < 1e-3, "colour {rgb:?}"); -} diff --git a/crates/ui-egui/src/dialogs/layer_style.rs b/crates/ui-egui/src/dialogs/layer_style.rs index de856173ae..d49f62d30d 100644 --- a/crates/ui-egui/src/dialogs/layer_style.rs +++ b/crates/ui-egui/src/dialogs/layer_style.rs @@ -546,8 +546,8 @@ fn specs(keys: &HashMap, user: &Map, light: f32) .filter_map(|(key, _)| { let kind = EffectKind::from_key(key)?; let mut spec = EffectSpec::photoshop(kind).with_blend_keys(keys); - if kind == EffectKind::OuterGlow { - // #14944: Photoshop groups the Outer Glow rows Structure / Elements / Quality and + if matches!(kind, EffectKind::OuterGlow | EffectKind::InnerGlow) { + // #14944, #14917: Photoshop groups the glow rows Structure / Elements / Quality and // puts Noise right under Opacity. The hosted page draws the spec's rows in order, // so the host moves the row; the group titles belong to the framework's page. if let Some(noise) = spec.fields.iter().position(|f| f.key == "noise") { diff --git a/crates/ui-egui/src/dialogs/layer_style/tests.rs b/crates/ui-egui/src/dialogs/layer_style/tests.rs index 7d83620208..7a457092c8 100644 --- a/crates/ui-egui/src/dialogs/layer_style/tests.rs +++ b/crates/ui-egui/src/dialogs/layer_style/tests.rs @@ -720,10 +720,10 @@ fn style_click_does_not_mutate_document_until_confirm() { /// #14944: the Outer Glow page is grouped Photoshop-style - Noise right under Opacity, the rows of /// the Structure, Elements and Quality blocks. The hosted page draws `specs()` rows in order, so /// the page order is pinned here; the group TITLES belong to the framework's page (craft-libs has -/// no header row on an effect page yet) and the other pages keep the framework's order (#14917 is -/// the Inner Glow's own ticket). +/// no header row on an effect page yet). #14917 groups the Inner Glow page the same way; the +/// other pages keep the framework's order. #[test] -fn the_outer_glow_page_rows_group_noise_under_opacity() { +fn the_glow_page_rows_group_noise_under_opacity() { let row_keys = |want: &str| { specs(&blend_keys(), &Map::new(), 120.0) .into_iter() @@ -735,11 +735,7 @@ fn the_outer_glow_page_rows_group_noise_under_opacity() { .collect::>() }; assert_eq!(row_keys("outerGlow"), ["blend", "opacity", "noise", "color", "technique", "spread", "size", "contour", "range"]); - assert_eq!( - row_keys("innerGlow"), - ["blend", "opacity", "color", "technique", "source", "choke", "size", "contour", "range", "noise"], - "the Inner Glow page stays as it is" - ); + assert_eq!(row_keys("innerGlow"), ["blend", "opacity", "noise", "color", "technique", "source", "choke", "size", "contour", "range"]); assert_eq!( row_keys("dropShadow"), ["blend", "color", "opacity", "angle", "useGlobalLight", "distance", "spread", "size", "contour", "noise", "knocksOut"], @@ -772,6 +768,33 @@ fn a_new_outer_glow_opens_at_the_factory_values_and_ok_keeps_them() { assert_eq!(hex(c), "#ffffff", "OK stored the colour"); } +/// #14917: a new Inner Glow opens at the reference application's factory values, and OK stores +/// exactly those. +#[test] +fn a_new_inner_glow_opens_at_the_factory_values_and_ok_keeps_them() { + let mut app = app_with_layer(32); + let id = open(&mut app, Some(EffectKind::InnerGlow.key())).unwrap(); + let glow = first_of(&app, id, EffectKind::InnerGlow); + let style = &draft(&app, id).style; + assert_eq!( + (text(style, glow, "blend").as_deref(), text(style, glow, "technique").as_deref(), text(style, glow, "source").as_deref()), + (Some("Screen"), Some("softer"), Some("edge")) + ); + assert_eq!( + (num(style, glow, "opacity"), num(style, glow, "noise"), num(style, glow, "choke"), num(style, glow, "size"), num(style, glow, "range")), + (Some(35.0), Some(0.0), Some(0.0), Some(7.0), Some(50.0)), + "the page's own seed" + ); + assert_eq!(style.effect(glow).and_then(|e| e.params.bool("antiAlias")), Some(false)); + let Some(StyleValue::Color(c)) = param(style, glow, "color") else { panic!("the colour row loads as a colour") }; + assert_eq!(color_picker_ui::hex(c.to_rgb_array()), "#ffffff", "the page's own colour"); + ok(&mut app, id); + let Effect::InnerGlow(g) = &layer_effects(&app.session)[0] else { panic!("{:?}", layer_effects(&app.session)) }; + assert!((g.common.opacity * 100.0 - 35.0).abs() < 1e-4 && (g.size - 7.0).abs() < 1e-4, "OK stored {g:?}"); + let FxPaint::Color(c) = &g.paint else { panic!("{:?}", g.paint) }; + assert_eq!(hex(c), "#ffffff", "OK stored the colour"); +} + /// #14944: the factory values never reach an Outer Glow the layer already carries: the page shows /// its own values and OK keeps them, as it does for a glow read from a PSD or `.pcraft`. #[test]