Add a strength percentage to the 'Make Opaque' node (#5058)

This commit is contained in:
Keavon Chambers authored and GitHub committed 2026-12-02 00:03:39 -08:00
1 parent 19df13ad1d
commit bb2514d816
13 files changed
+188 -28

No files matched your search

@@ -345,8 +345,15 @@ fn gamma_correction(color: vec4<f32>, at: u32) -> vec4<f32> {
return vec4<f32>(rust_powf(color.r, inverse), rust_powf(color.g, inverse), rust_powf(color.b, inverse), color.a);
}
// The strength (x) that alpha moves toward 1 by, keeping the straight color
fn make_opaque(color: vec4<f32>, at: u32) -> vec4<f32> {
return vec4<f32>(color.rgb, 1.);
let strength = step_texel(at).x;
// At full strength, even an alpha that isn't finite becomes opaque
if strength >= 1. {
return vec4<f32>(color.rgb, 1.);
}
return vec4<f32>(color.rgb, color.a * (1. - strength) + strength);
}
fn invert(color: vec4<f32>, at: u32) -> vec4<f32> {
@@ -2604,6 +2604,7 @@ fn cpu_evaluated_effects_match_the_gpu_passes() {
blend_mode: BlendMode::Normal,
opacity: 100.,
};
let make_opaque = |strength| EffectOperation::Adjustment(Adjustment::MakeOpaque { strength });
let mask_cases = [
vec![mask(&mask_image, MaskMode::Luminance, 100., 0., false)],
vec![mask(&mask_image, MaskMode::Alpha, 70., 3., true)],
@@ -2648,6 +2649,16 @@ fn cpu_evaluated_effects_match_the_gpu_passes() {
vec![painted(&checker), masked_radius_blur(&mask_image, 8., true, false)],
// Boxes of each pixel's own fractional width across hard edges, in gamma
vec![painted(&checks), masked_radius_blur(&resampled, 15.5, true, true)],
// Masked content's translucent alpha lifted toward opaque by each strength, with the empty space around it left empty
vec![mask(&mask_image, MaskMode::Luminance, 100., 0., false), make_opaque(0.)],
vec![mask(&mask_image, MaskMode::Luminance, 100., 0., false), make_opaque(50.)],
vec![mask(&mask_image, MaskMode::Luminance, 100., 0., false), make_opaque(100.)],
// No strength still carries out the adjustments after it
vec![
mask(&mask_image, MaskMode::Luminance, 100., 0., false),
make_opaque(0.),
EffectOperation::Adjustment(Adjustment::Invert),
],
];
// Content in a color of its own, so every mode has colors to blend
@@ -3172,7 +3183,8 @@ fn gpu_tone_adjustments_match_the_cpu_kernels() {
),
("Invert", Adjustment::Invert),
("Solarize", Adjustment::Solarize),
("Make Opaque", Adjustment::MakeOpaque),
("Make Opaque", Adjustment::MakeOpaque { strength: 100. }),
("Make Opaque at half strength", Adjustment::MakeOpaque { strength: 50. }),
];
assert_gpu_adjustments_match_the_cpu_kernels(runs.into_iter().map(|(name, adjustment)| (name, vec![adjustment])).collect());
}
@@ -3847,7 +3859,7 @@ fn gpu_runs_of_several_adjustments_match_the_cpu_kernels() {
("Exposure, Vibrance, Invert, then Posterize", vec![exposure.clone(), vibrance.clone(), Adjustment::Invert, posterize]),
(
"Levels fading alpha, Make Opaque, Channel Mixer, then Threshold",
vec![levels.clone(), Adjustment::MakeOpaque, channel_mixer.clone(), threshold],
vec![levels.clone(), Adjustment::MakeOpaque { strength: 100. }, channel_mixer.clone(), threshold],
),
("Vibrance, an unreadable Color Lookup, then Curves", vec![vibrance.clone(), unreadable_lookup.clone(), curves.clone()]),
("an unreadable Color Lookup alone", vec![unreadable_lookup]),
@@ -3860,12 +3872,12 @@ fn gpu_runs_of_several_adjustments_match_the_cpu_kernels() {
("Color Balance, then a Color Burn of black", vec![color_balance, color_burn]),
(
"Curves emptying faint pixels, then Make Opaque",
vec![emptying_curves.clone(), Adjustment::MakeOpaque, Adjustment::Invert],
vec![emptying_curves.clone(), Adjustment::MakeOpaque { strength: 100. }, Adjustment::Invert],
),
// The pass emptying a pixel ends before the Color Lookup's own pass, and the one after it with Make Opaque still leaves the pixel empty
(
"Curves emptying faint pixels, then a Color Lookup and Make Opaque",
vec![emptying_curves, identity_lookup, Adjustment::MakeOpaque],
vec![emptying_curves, identity_lookup, Adjustment::MakeOpaque { strength: 100. }],
),
];
assert_gpu_adjustments_stray_at_most(0.3, runs, &[1., 0.5]);
@@ -3920,7 +3932,7 @@ fn passes_of_a_split_run_hand_on_their_results_unrounded() {
// An alpha too faint for a half float to hold, which Make Opaque then lifts
let faint = levels(identity, record(0., 100., 2e-6));
let lifted = vec![faint, split, Adjustment::MakeOpaque];
let lifted = vec![faint, split, Adjustment::MakeOpaque { strength: 100. }];
// Grays a 4096th apart, hundreds of which land within the stretch
let grays: Vec<core_types::Color> = (0..=4096)
@@ -4214,10 +4226,12 @@ fn adjustments_leave_the_empty_space_around_content_empty() {
alpha: TransferCurve::new(vec![DVec2::ZERO, DVec2::new(1., 0.)]),
..Default::default()
}));
let make_opaque = |strength| Adjustment::MakeOpaque { strength };
let cases = [
("Make Opaque", vec![Adjustment::MakeOpaque], 255),
("Make Opaque", vec![make_opaque(100.)], 255),
("Make Opaque at half strength", vec![make_opaque(50.)], 255),
("Levels with a raised alpha output", vec![raised_alpha], 255),
("Curves emptying alpha, then Make Opaque", vec![emptied, Adjustment::MakeOpaque], 0),
("Curves emptying alpha, then Make Opaque", vec![emptied, make_opaque(100.)], 0),
];
for (name, run, alpha_within) in cases {