add color interpolation for ARGBu8x4
This commit is contained in:
parent
0112e99fc7
commit
448ce11dbc
|
@ -610,6 +610,10 @@ impl ARGBu8x4 {
|
||||||
self.0.to_array()
|
self.0.to_array()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn lerp(&self, other: Self, t: f32) -> Self {
|
||||||
|
ARGBu8x4((self.0.cast() + (other.0 - self.0).cast() * simd::f32x4::splat(t)).cast())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mul for ARGBu8x4 {
|
impl Mul for ARGBu8x4 {
|
||||||
|
@ -923,6 +927,22 @@ mod tests {
|
||||||
assert_eq!([0x7f, 0x03, 0x00, 0x14], color.to_array());
|
assert_eq!([0x7f, 0x03, 0x00, 0x14], color.to_array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn argbu8x4_lerping() {
|
||||||
|
assert_eq!(
|
||||||
|
[0x7f, 0x11, 0x22, 0x33],
|
||||||
|
(ARGBu8x4::from(0x7f112233).lerp(ARGBu8x4::from(0xffaabbcc), 0.0).to_array())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
[0xbf, 0x5d, 0x6e, 0x7f],
|
||||||
|
(ARGBu8x4::from(0x7f112233).lerp(ARGBu8x4::from(0xffaabbcc), 0.5).to_array())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
[0xff, 0xaa, 0xbb, 0xcc],
|
||||||
|
(ARGBu8x4::from(0x7f112233).lerp(ARGBu8x4::from(0xffaabbcc), 1.0).to_array())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn argbf32x4() {
|
fn argbf32x4() {
|
||||||
let mut color = ARGBf32x4(simd::f32x4::from_array([0.5, 0.1, 0.2, 0.3]));
|
let mut color = ARGBf32x4(simd::f32x4::from_array([0.5, 0.1, 0.2, 0.3]));
|
||||||
|
|
Loading…
Reference in a new issue