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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use crate::chan::Channel;
pub trait Blend: Copy + Clone {
fn composite<C: Channel>(dst: &mut C, da1: C, src: &C, sa1: C);
}
#[derive(Clone, Copy)]
pub struct Src;
#[derive(Clone, Copy)]
pub struct Dest;
#[derive(Clone, Copy)]
pub struct SrcOver;
#[derive(Clone, Copy)]
pub struct DestOver;
#[derive(Clone, Copy)]
pub struct SrcOut;
#[derive(Clone, Copy)]
pub struct DestOut;
#[derive(Clone, Copy)]
pub struct SrcIn;
#[derive(Clone, Copy)]
pub struct DestIn;
#[derive(Clone, Copy)]
pub struct SrcAtop;
#[derive(Clone, Copy)]
pub struct DestAtop;
#[derive(Clone, Copy)]
pub struct Xor;
#[derive(Clone, Copy)]
pub struct Clear;
#[derive(Clone, Copy)]
pub struct Plus;
impl Blend for Src {
fn composite<C: Channel>(dst: &mut C, _da1: C, src: &C, _sa1: C) {
*dst = *src;
}
}
impl Blend for Dest {
fn composite<C: Channel>(_dst: &mut C, _da1: C, _src: &C, _sa1: C) {
}
}
impl Blend for SrcOver {
fn composite<C: Channel>(dst: &mut C, _da1: C, src: &C, sa1: C) {
*dst = *src + *dst * sa1;
}
}
impl Blend for DestOver {
fn composite<C: Channel>(dst: &mut C, da1: C, src: &C, _sa1: C) {
*dst = *src * da1 + *dst;
}
}
impl Blend for SrcOut {
fn composite<C: Channel>(dst: &mut C, da1: C, src: &C, _sa1: C) {
*dst = *src * da1;
}
}
impl Blend for DestOut {
fn composite<C: Channel>(dst: &mut C, _da1: C, _src: &C, sa1: C) {
*dst = *dst * sa1;
}
}
impl Blend for SrcIn {
fn composite<C: Channel>(dst: &mut C, da1: C, src: &C, _sa1: C) {
let da = C::MAX - da1;
*dst = *src * da;
}
}
impl Blend for DestIn {
fn composite<C: Channel>(dst: &mut C, _da1: C, _src: &C, sa1: C) {
let sa = C::MAX - sa1;
*dst = *dst * sa;
}
}
impl Blend for SrcAtop {
fn composite<C: Channel>(dst: &mut C, da1: C, src: &C, sa1: C) {
let da = C::MAX - da1;
*dst = *src * da + *dst * sa1;
}
}
impl Blend for DestAtop {
fn composite<C: Channel>(dst: &mut C, da1: C, src: &C, sa1: C) {
let sa = C::MAX - sa1;
*dst = *src * da1 + *dst * sa;
}
}
impl Blend for Xor {
fn composite<C: Channel>(dst: &mut C, da1: C, src: &C, sa1: C) {
*dst = *src * da1 + *dst * sa1;
}
}
impl Blend for Clear {
fn composite<C: Channel>(dst: &mut C, _da1: C, _src: &C, _sa1: C) {
*dst = C::default();
}
}
impl Blend for Plus {
fn composite<C: Channel>(dst: &mut C, _da1: C, src: &C, _sa1: C) {
*dst = *src + *dst;
}
}