#![cfg_attr(not(feature = "std"), no_std)]
use crate::{porter_duff::PorterDuff, rgba::Rgba};
pub(crate) mod math;
pub mod porter_duff;
pub mod rgba;
pub(crate) mod vec4;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlendMode {
Clear,
Source,
Destination,
SourceOver,
DestinationOver,
SourceIn,
DestinationIn,
SourceOut,
DestinationOut,
SourceAtop,
DestinationAtop,
Xor,
Plus,
}
impl BlendMode {
#[must_use]
fn as_rgba_blend_f32(&self) -> impl RgbaBlend<Channel = f32> {
match self {
BlendMode::Clear => PorterDuff::CLEAR,
BlendMode::Source => PorterDuff::SRC,
BlendMode::Destination => PorterDuff::DST,
BlendMode::SourceOver => PorterDuff::SRC_OVER,
BlendMode::DestinationOver => PorterDuff::DST_OVER,
BlendMode::SourceIn => PorterDuff::SRC_IN,
BlendMode::DestinationIn => PorterDuff::DST_IN,
BlendMode::SourceOut => PorterDuff::SRC_OUT,
BlendMode::DestinationOut => PorterDuff::DST_OUT,
BlendMode::SourceAtop => PorterDuff::SRC_ATOP,
BlendMode::DestinationAtop => PorterDuff::DST_ATOP,
BlendMode::Xor => PorterDuff::XOR,
BlendMode::Plus => PorterDuff::PLUS,
}
}
}
impl RgbaBlend for BlendMode {
type Channel = f32;
fn apply(&self, src: Rgba<Self::Channel>, dst: Rgba<Self::Channel>) -> Rgba<Self::Channel> {
self.as_rgba_blend_f32().apply(src, dst)
}
}
pub trait RgbaBlend {
type Channel: Copy;
fn apply(&self, src: Rgba<Self::Channel>, dst: Rgba<Self::Channel>) -> Rgba<Self::Channel>;
}