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
extern crate image;
use util::{Result, Error};
pub use self::image::DynamicImage as Image;
pub use self::image::*;
use std::path::Path;

pub fn load<P: AsRef<Path>>(path: P) -> Result<image::DynamicImage>{
    image::open(path.as_ref())
        .map_err(|err| Error::with_cause(&format!("Error loading image from {:?}", path.as_ref()), err))
}

pub fn load_from_memory(buffer: &[u8]) -> Result<image::DynamicImage>{
    image::load_from_memory(buffer)
        .map_err(|err| Error::with_cause(&format!("Error loading image from memory"), err))
}

pub fn supports(format: Format) -> bool{
    match format{
        Format::Bmp | Format::Ico | Format::Jpeg | Format::Gif |
        Format::Png | Format::Tiff | Format::WebP | Format::Pbm |
        Format::Pgm | Format::Ppm => true,
        _ => false,
    }
}

pub enum Format{
    Bmp,
    Cut,
    Dds,
    Exr,
    G3,
    Gif,
    Hdr,
    Ico,
    Iff,
    JBig,
    Jng,
    Jpeg,
    Jpeg2000,
    JpegXR,
    Koala,
    Kodak,
    Mng,
    Pcx,
    Pbm,
    Pgm,
    Ppm,
    Pfm,
    Png,
    Pict,
    Psd,
    Raw,
    Ras,
    Sgi,
    Targa,
    Tiff,
    WBMP,
    WebP,
    Xbm,
    Xpm,
}