mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30: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:
@@ -1,4 +1,6 @@
|
||||
use crate::{gamma_u8_from_linear_f32, linear_f32_from_gamma_u8, linear_f32_from_linear_u8, Rgba};
|
||||
use crate::{
|
||||
fast_round, gamma_u8_from_linear_f32, linear_f32_from_gamma_u8, linear_f32_from_linear_u8, Rgba,
|
||||
};
|
||||
|
||||
/// This format is used for space-efficient color representation (32 bits).
|
||||
///
|
||||
@@ -235,4 +237,16 @@ impl Color32 {
|
||||
a as f32 / 255.0,
|
||||
]
|
||||
}
|
||||
|
||||
/// Lerp this color towards `other` by `t` in gamma space.
|
||||
pub fn lerp_to_gamma(&self, other: Self, t: f32) -> Self {
|
||||
use emath::lerp;
|
||||
|
||||
Self::from_rgba_premultiplied(
|
||||
fast_round(lerp((self[0] as f32)..=(other[0] as f32), t)),
|
||||
fast_round(lerp((self[1] as f32)..=(other[1] as f32), t)),
|
||||
fast_round(lerp((self[2] as f32)..=(other[2] as f32), t)),
|
||||
fast_round(lerp((self[3] as f32)..=(other[3] as f32), t)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user