Skip to content

Commit 9e9ae5b

Browse files
payloadjames7132
andauthored
Fix Color::as_rgba_linear for Color::Lcha (#8040)
Co-authored-by: James Liu <[email protected]>
1 parent ee0e6f4 commit 9e9ae5b

File tree

1 file changed

+19
-1
lines changed
  • crates/bevy_render/src/color

1 file changed

+19
-1
lines changed

crates/bevy_render/src/color/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl Color {
525525
let [red, green, blue] =
526526
LchRepresentation::lch_to_nonlinear_srgb(*lightness, *chroma, *hue);
527527

528-
Color::Rgba {
528+
Color::RgbaLinear {
529529
red: red.nonlinear_to_linear_srgb(),
530530
green: green.nonlinear_to_linear_srgb(),
531531
blue: blue.nonlinear_to_linear_srgb(),
@@ -1858,4 +1858,22 @@ mod tests {
18581858

18591859
assert_eq!(starting_color * transformation, mutated_color,);
18601860
}
1861+
1862+
// regression test for https://github.com/bevyengine/bevy/pull/8040
1863+
#[test]
1864+
fn convert_to_rgba_linear() {
1865+
let rgba = Color::rgba(0., 0., 0., 0.);
1866+
let rgba_l = Color::rgba_linear(0., 0., 0., 0.);
1867+
let hsla = Color::hsla(0., 0., 0., 0.);
1868+
let lcha = Color::Lcha {
1869+
lightness: 0.0,
1870+
chroma: 0.0,
1871+
hue: 0.0,
1872+
alpha: 0.0,
1873+
};
1874+
assert_eq!(rgba_l, rgba_l.as_rgba_linear());
1875+
let Color::RgbaLinear { .. } = rgba.as_rgba_linear() else { panic!("from Rgba") };
1876+
let Color::RgbaLinear { .. } = hsla.as_rgba_linear() else { panic!("from Hsla") };
1877+
let Color::RgbaLinear { .. } = lcha.as_rgba_linear() else { panic!("from Lcha") };
1878+
}
18611879
}

0 commit comments

Comments
 (0)