use super::{ColorComponentType, ColorDescriptor, ColorLayoutFormat};
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct R8 {
pub r: u8,
}
impl R8 {
pub const fn new(red: u8) -> R8 {
R8 {
r: red,
}
}
pub fn from_f32(red: f32) -> R8 {
R8 {
r: (red * 255.0) as u8,
}
}
}
impl From<R8> for f32 {
fn from(x: R8) -> Self {
(x.r as f32) / 255.0
}
}
impl From<f32> for R8 {
fn from(r: f32) -> Self {
Self::from_f32(r)
}
}
impl Default for R8 {
fn default() -> Self {
Self {
r: 255,
}
}
}
impl ColorDescriptor for R8 {
fn component_type() -> ColorComponentType {
ColorComponentType::U8
}
fn layout() -> ColorLayoutFormat {
ColorLayoutFormat::R
}
}