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
use super::Image;
use crate::image_crate::imageops::FilterType;
use crate::modifier::Modifier;

#[derive(Debug, Clone, Copy)]
/// Resize Modifier for `Image`
pub struct Resize {
    /// The resized width of the new Image
    pub width: u32,
    /// The resized heigt of the new Image
    pub height: u32,
}

impl Modifier<Image> for Resize {
    fn modify(self, image: &mut Image) {
        image.value = image
            .value
            .resize(self.width, self.height, FilterType::Triangle)
    }
}

#[derive(Debug, Clone, Copy)]
/// Crop Modifier for `Image`
pub struct Crop {
    /// The x value from where the new Image should start
    pub x: u32,
    /// The y value from where the new Image should start
    pub y: u32,
    /// The width for the new Image
    pub width: u32,
    /// The height for the new Image
    pub height: u32,
}

impl Modifier<Image> for Crop {
    fn modify(self, image: &mut Image) {
        image.value = image.value.crop(self.x, self.y, self.width, self.height)
    }
}

#[derive(Debug, Clone, Copy)]
/// Grayscale Modifier for `Image`
pub struct Grayscale;

impl Modifier<Image> for Grayscale {
    fn modify(self, image: &mut Image) {
        image.value = image.value.grayscale();
    }
}