use crate::color::BlendMode;
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash)]
pub enum RasterOp {
#[default]
Copy = 0,
And = 1,
Or = 2,
Xor = 3,
NotSrc = 4,
NotDst = 5,
Clear = 6,
Set = 7,
Nand = 8,
Nor = 9,
}
impl RasterOp {
#[inline]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Copy),
1 => Some(Self::And),
2 => Some(Self::Or),
3 => Some(Self::Xor),
4 => Some(Self::NotSrc),
5 => Some(Self::NotDst),
6 => Some(Self::Clear),
7 => Some(Self::Set),
8 => Some(Self::Nand),
9 => Some(Self::Nor),
_ => None,
}
}
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Copy => "Copy",
Self::And => "And",
Self::Or => "Or",
Self::Xor => "Xor",
Self::NotSrc => "Not Src",
Self::NotDst => "Not Dst",
Self::Clear => "Clear",
Self::Set => "Set",
Self::Nand => "Nand",
Self::Nor => "Nor",
}
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct PipelineState {
pub blend_mode: BlendMode,
pub raster_op: RasterOp,
pub global_alpha: u8,
pub antialias: bool,
pub dither: bool,
}
impl PipelineState {
pub const DEFAULT: Self = Self {
blend_mode: BlendMode::Normal,
raster_op: RasterOp::Copy,
global_alpha: 255,
antialias: false,
dither: false,
};
#[inline]
pub const fn new() -> Self {
Self::DEFAULT
}
#[inline]
pub const fn with_blend(mut self, blend: BlendMode) -> Self {
self.blend_mode = blend;
self
}
#[inline]
pub const fn with_alpha(mut self, alpha: u8) -> Self {
self.global_alpha = alpha;
self
}
#[inline]
pub const fn with_antialias(mut self, aa: bool) -> Self {
self.antialias = aa;
self
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash)]
pub enum InterpolationQuality {
#[default]
Nearest = 0,
Bilinear = 1,
Bicubic = 2,
Lanczos = 3,
}
impl InterpolationQuality {
#[inline]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Nearest),
1 => Some(Self::Bilinear),
2 => Some(Self::Bicubic),
3 => Some(Self::Lanczos),
_ => None,
}
}
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Nearest => "Nearest",
Self::Bilinear => "Bilinear",
Self::Bicubic => "Bicubic",
Self::Lanczos => "Lanczos",
}
}
}