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
use image::{imageops, GenericImage, ImageBuffer, Pixel};

use super::{Image, ResizableImage, RGB};

impl<I, P> Image for I
where
    I: GenericImage<Pixel = P> + 'static,
    P: Pixel<Subpixel = u8> + 'static,
{
    fn width(&self) -> u32 {
        self.width()
    }

    fn height(&self) -> u32 {
        self.height()
    }

    fn get(&self, x: u32, y: u32) -> RGB {
        let px = self.get_pixel(x, y).to_rgb();

        let r = px[0];
        let g = px[1];
        let b = px[2];
        RGB { r, g, b }
    }
}

impl<I, P> ResizableImage<ImageBuffer<P, std::vec::Vec<u8>>> for I
where
    I: GenericImage<Pixel = P> + 'static,
    P: Pixel<Subpixel = u8> + 'static,
{
    fn resize(&self, width: u32, height: u32) -> ImageBuffer<P, std::vec::Vec<u8>> {
        imageops::resize(self, width, height, imageops::FilterType::Lanczos3)
    }
}