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
use crate::filters::Filter;
impl Filter {
/// Creates a sepia filter effect with the specified intensity.
///
/// # Arguments
/// - `amount`: The sepia intensity where `0.0` leaves the image unchanged
/// and `1.0` applies a full sepia tone.
///
/// # Returns
/// - [`Filter`] applying a sepia tone effect.
///
/// # Reference
///
/// https://www.w3.org/TR/filter-effects-1/#sepiaEquivalent
pub fn sepia(amount: f32) -> Self {
let x = 1.0 - amount.clamp(0.0, 1.0);
Self::new(|ctx| {
ctx.color_matrix()
.matrix([
[
0.393 + 0.607 * x,
0.769 - 0.769 * x,
0.189 - 0.189 * x,
0.0,
0.0,
],
[
0.349 - 0.349 * x,
0.686 + 0.314 * x,
0.168 - 0.168 * x,
0.0,
0.0,
],
[
0.272 - 0.272 * x,
0.534 - 0.534 * x,
0.131 + 0.869 * x,
0.0,
0.0,
],
[0.0, 0.0, 0.0, 1.0, 0.0],
])
.finish();
})
}
}