modelassetlib_native/util/
image.rs

1extern crate image;
2extern crate anyhow;
3extern crate thiserror;
4
5use image::ImageFormat;
6use anyhow::Result;
7use thiserror::Error;
8
9#[derive(Error, Debug)]
10pub enum ImageUtilError {
11    #[error("The image format id {0} is wrong.")]
12    WrongImageFormatId(i32)
13}
14
15pub fn image_format_from_id(id: i32) -> Result<ImageFormat> {
16    match id {
17        0 => Ok(ImageFormat::Png),
18        1 => Ok(ImageFormat::Jpeg),
19        2 => Ok(ImageFormat::Gif),
20        3 => Ok(ImageFormat::WebP),
21        4 => Ok(ImageFormat::Pnm),
22        5 => Ok(ImageFormat::Tiff),
23        6 => Ok(ImageFormat::Tga),
24        7 => Ok(ImageFormat::Dds),
25        8 => Ok(ImageFormat::Bmp),
26        9 => Ok(ImageFormat::Ico),
27        10 => Ok(ImageFormat::Hdr),
28        11 => Ok(ImageFormat::OpenExr),
29        12 => Ok(ImageFormat::Farbfeld),
30        13 => Ok(ImageFormat::Avif),
31        14 => Ok(ImageFormat::Qoi),
32        _ => Err(ImageUtilError::WrongImageFormatId(id).into())
33    }
34}