use crate::pixel::premultiply_rgba;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct Rgba32(pub u32);
impl Rgba32 {
#[inline]
pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
Self(((a as u32) << 24) | ((r as u32) << 16) | ((g as u32) << 8) | (b as u32))
}
#[inline]
pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
Self::new(r, g, b, 255)
}
#[inline]
pub const fn r(self) -> u8 {
((self.0 >> 16) & 0xFF) as u8
}
#[inline]
pub const fn g(self) -> u8 {
((self.0 >> 8) & 0xFF) as u8
}
#[inline]
pub const fn b(self) -> u8 {
(self.0 & 0xFF) as u8
}
#[inline]
pub const fn a(self) -> u8 {
((self.0 >> 24) & 0xFF) as u8
}
#[inline]
pub const fn is_opaque(self) -> bool {
self.0 >= 0xFF00_0000
}
#[inline]
pub const fn is_transparent(self) -> bool {
self.0 <= 0x00FF_FFFF
}
#[inline]
pub const fn to_prgb32(self) -> u32 {
premultiply_rgba(self.r(), self.g(), self.b(), self.a())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[repr(u8)]
pub enum StrokeCap {
#[default]
Butt = 0,
Square = 1,
Round = 2,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[repr(u8)]
pub enum StrokeJoin {
#[default]
MiterClip = 0,
MiterBevel = 1,
MiterRound = 2,
Bevel = 3,
Round = 4,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[repr(u8)]
pub enum FillRule {
#[default]
NonZero = 0,
EvenOdd = 1,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[repr(u8)]
pub enum CompOp {
#[default]
SrcOver = 0,
SrcCopy = 1,
SrcIn = 2,
SrcOut = 3,
SrcAtop = 4,
DstOver = 5,
DstCopy = 6,
DstIn = 7,
DstOut = 8,
DstAtop = 9,
Xor = 10,
Clear = 11,
Plus = 12,
Minus = 13,
Modulate = 14,
Multiply = 15,
Screen = 16,
Overlay = 17,
Darken = 18,
Lighten = 19,
ColorDodge = 20,
ColorBurn = 21,
LinearBurn = 22,
LinearLight = 23,
PinLight = 24,
HardLight = 25,
SoftLight = 26,
Difference = 27,
Exclusion = 28,
}