Tweak brightness

This commit is contained in:
2023-12-19 19:31:08 +01:00
parent 7d9cfe9557
commit 00b3b51b36
4 changed files with 19 additions and 12 deletions

View File

@ -1,7 +1,7 @@
use bytemuck::{cast_slice, Pod, Zeroable};
use core::{
fmt::{self, Debug},
ops::Div,
ops::{Div, Mul},
};
/// An Rgb value that can be safely transmuted to u32 for use with Ws2812.
@ -44,6 +44,19 @@ impl Div<u8> for Rgb {
}
}
impl Mul<f32> for Rgb {
type Output = Rgb;
fn mul(self, factor: f32) -> Self::Output {
let [r, g, b] = self.components();
Rgb::new(
((r as f32) * factor) as u8,
((g as f32) * factor) as u8,
((b as f32) * factor) as u8,
)
}
}
#[cfg(all(target_arch = "x86_64", test))]
mod tests {
use super::*;