use super::{rgb_u8_to_u32, u32_to_rgba_u8};
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "wincode",
derive(wincode::SchemaWrite, wincode::SchemaRead)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct Pixel {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
pub color: u32,
}
impl Pixel {
#[must_use]
pub const fn new_rgb(r: u8, g: u8, b: u8, a: u8) -> Self {
Self {
r,
g,
b,
a,
color: rgb_u8_to_u32(r, g, b),
}
}
#[must_use]
pub const fn new_32(color: u32) -> Self {
let (r, g, b, a) = u32_to_rgba_u8(color);
Self {
r,
g,
b,
a,
color,
}
}
}
impl From<Pixel> for u32 {
fn from(p: Pixel) -> Self {
p.color
}
}