1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// blend.rs     Pixel blend ops.
//
// Copyright (c) 2018-2019  Douglas P Lau
//
use pix::Format;

/// Pixel format which can be blended.
pub trait Blend: Format {
    /// Blend pixels with `over` operation.
    ///
    /// * `dst` Destination pixels.
    /// * `src` Source pixels.
    /// * `clr` Mask color.
    fn over_slice<B: Blend>(dst: &mut [Self], src: &[B], clr: Self)
    where
        Self: From<B>,
    {
        Self::over_fallback(dst, src, clr);
    }

    /// Blend pixels with `over` operation (slow fallback).
    ///
    /// * `dst` Destination pixels.
    /// * `src` Source pixels.
    /// * `clr` Mask color.
    fn over_fallback<B: Blend>(dst: &mut [Self], src: &[B], clr: Self)
    where
        Self: From<B>;

    /// Blend pixel on top of another, using `over`.
    fn over(dst: Self, src: Self) -> Self;
}