library: core: color: add image::Rgbconversion

This commit is contained in:
Bruno BELANYI 2020-03-17 23:28:24 +01:00
parent e9eaabcd0a
commit 58f9a508dc

View file

@ -67,6 +67,26 @@ impl DivAssign for LinearColor {
}
}
impl From<LinearColor> for image::Rgb<u8> {
fn from(color: LinearColor) -> Self {
fn clamp(v: f32) -> f32 {
// FIXME: use clamp from nightly
if v > 1. {
1.
} else if v < 0. {
0.
} else {
v
}
};
image::Rgb([
(clamp(color.r) * 255.) as u8,
(clamp(color.g) * 255.) as u8,
(clamp(color.b) * 255.) as u8,
])
}
}
#[cfg(test)]
mod test {
use super::*;