mod formats;
mod impl_rgb_alpha_wrappers;
mod macros;
mod traits;
pub use formats::*;
pub use traits::*;
pub use traits::{HasBlue as _, HasGreen as _, HasRed as _, RgbColor as _, RgbaColor as _};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", allow(clippy::unsafe_derive_deserialize))]
#[repr(C)]
pub struct Rgb<T> {
r: T,
g: T,
b: T,
}
impl<T> Rgb<T> {
#[must_use]
pub const fn from_rgb(red: T, green: T, blue: T) -> Self {
Self {
r: red,
g: green,
b: blue,
}
}
}
#[cfg(feature = "bytemuck")]
#[allow(unsafe_code)]
unsafe impl<T: bytemuck::Zeroable> bytemuck::Zeroable for Rgb<T> {}
#[cfg(feature = "bytemuck")]
#[allow(unsafe_code)]
unsafe impl<T: bytemuck::Pod> bytemuck::Pod for Rgb<T> {}
macros::impl_rgb_with_fields!(Rgb<T>);
impl<T> crate::space::RgbChannelScale for Rgb<T>
where
T: crate::space::NativeMax,
{
const RED_MAX: f32 = T::MAX;
const GREEN_MAX: f32 = T::MAX;
const BLUE_MAX: f32 = T::MAX;
}
impl<T> From<crate::space::Srgb> for Rgb<T>
where
T: crate::space::NativeMax,
{
fn from(c: crate::space::Srgb) -> Self {
crate::space::FromSrgb::from_srgb(c)
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", allow(clippy::unsafe_derive_deserialize))]
#[repr(C)]
pub struct Bgr<T> {
b: T,
g: T,
r: T,
}
impl<T> Bgr<T> {
#[must_use]
pub const fn from_bgr(blue: T, green: T, red: T) -> Self {
Self {
b: blue,
g: green,
r: red,
}
}
}
#[cfg(feature = "bytemuck")]
#[allow(unsafe_code)]
unsafe impl<T: bytemuck::Zeroable> bytemuck::Zeroable for Bgr<T> {}
#[cfg(feature = "bytemuck")]
#[allow(unsafe_code)]
unsafe impl<T: bytemuck::Pod> bytemuck::Pod for Bgr<T> {}
macros::impl_rgb_with_fields!(Bgr<T>);
impl<T> crate::space::RgbChannelScale for Bgr<T>
where
T: crate::space::NativeMax,
{
const RED_MAX: f32 = T::MAX;
const GREEN_MAX: f32 = T::MAX;
const BLUE_MAX: f32 = T::MAX;
}
impl<T> From<crate::space::Srgb> for Bgr<T>
where
T: crate::space::NativeMax,
{
fn from(c: crate::space::Srgb) -> Self {
crate::space::FromSrgb::from_srgb(c)
}
}