1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 14:50:03 -04:00

Add Color32::lerp_to_gamma (#4627)

Add `lerp_to_gamma` utility function to `Color32`

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Antoine Beyeler
2024-06-06 15:41:10 +02:00
committed by GitHub
parent 1f008fb730
commit 2545939c15
4 changed files with 19 additions and 11 deletions

View File

@@ -342,7 +342,7 @@ impl Gradient {
(0..=n)
.map(|i| {
let t = i as f32 / n as f32;
lerp_color_gamma(left, right, t)
left.lerp_to_gamma(right, t)
})
.collect(),
)
@@ -634,12 +634,3 @@ fn mul_color_gamma(left: Color32, right: Color32) -> Color32 {
(left.a() as f32 * right.a() as f32 / 255.0).round() as u8,
)
}
fn lerp_color_gamma(left: Color32, right: Color32, t: f32) -> Color32 {
Color32::from_rgba_premultiplied(
lerp((left[0] as f32)..=(right[0] as f32), t).round() as u8,
lerp((left[1] as f32)..=(right[1] as f32), t).round() as u8,
lerp((left[2] as f32)..=(right[2] as f32), t).round() as u8,
lerp((left[3] as f32)..=(right[3] as f32), t).round() as u8,
)
}