From 3bf397652d093c1700952258b297e3e05285f08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilbert=20R=C3=B6hrbein?= Date: Sat, 11 Mar 2023 13:12:31 +0100 Subject: [PATCH] Fix Color::as_rgba_linear for Color::Lcha (#8040) Co-authored-by: James Liu --- crates/bevy_render/src/color/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/color/mod.rs b/crates/bevy_render/src/color/mod.rs index 770a7bee9c7d5..a5fa2c2b0889c 100644 --- a/crates/bevy_render/src/color/mod.rs +++ b/crates/bevy_render/src/color/mod.rs @@ -525,7 +525,7 @@ impl Color { let [red, green, blue] = LchRepresentation::lch_to_nonlinear_srgb(*lightness, *chroma, *hue); - Color::Rgba { + Color::RgbaLinear { red: red.nonlinear_to_linear_srgb(), green: green.nonlinear_to_linear_srgb(), blue: blue.nonlinear_to_linear_srgb(), @@ -1858,4 +1858,22 @@ mod tests { assert_eq!(starting_color * transformation, mutated_color,); } + + // regression test for https://github.com/bevyengine/bevy/pull/8040 + #[test] + fn convert_to_rgba_linear() { + let rgba = Color::rgba(0., 0., 0., 0.); + let rgba_l = Color::rgba_linear(0., 0., 0., 0.); + let hsla = Color::hsla(0., 0., 0., 0.); + let lcha = Color::Lcha { + lightness: 0.0, + chroma: 0.0, + hue: 0.0, + alpha: 0.0, + }; + assert_eq!(rgba_l, rgba_l.as_rgba_linear()); + let Color::RgbaLinear { .. } = rgba.as_rgba_linear() else { panic!("from Rgba") }; + let Color::RgbaLinear { .. } = hsla.as_rgba_linear() else { panic!("from Hsla") }; + let Color::RgbaLinear { .. } = lcha.as_rgba_linear() else { panic!("from Lcha") }; + } }