librashader/librashader-common/src/image.rs

23 lines
453 B
Rust
Raw Normal View History

2022-11-17 16:08:11 +11:00
use std::path::Path;
pub struct Image {
pub bytes: Vec<u8>,
pub height: u32,
pub width: u32,
}
impl Image {
2022-11-22 08:21:50 +11:00
pub fn load(path: impl AsRef<Path>) -> Result<Self, image::ImageError> {
2022-11-21 18:13:22 +11:00
let image = image::open(path.as_ref())?.flipv().to_rgba8();
2022-11-17 16:08:11 +11:00
let height = image.height();
let width = image.width();
2022-11-22 08:21:50 +11:00
2022-11-17 16:08:11 +11:00
Ok(Image {
bytes: image.to_vec(),
height,
2022-11-22 08:21:50 +11:00
width,
2022-11-17 16:08:11 +11:00
})
}
2022-11-22 08:21:50 +11:00
}