Only load images as PNG

This commit is contained in:
Benoît du Garreau
2021-05-09 19:02:48 +02:00
parent 724fbadf9e
commit 9cfe2911e5

View File

@ -96,23 +96,19 @@ impl Image {
pub fn to_image(&self) -> Arc<DynamicImage> { Arc::clone(&self.0) } pub fn to_image(&self) -> Arc<DynamicImage> { Arc::clone(&self.0) }
} }
pub struct ImageLoader; pub struct PngLoader;
impl Loader<Image> for ImageLoader { impl Loader<Image> for PngLoader {
fn load(content: Cow<[u8]>, ext: &str) -> Result<Image, BoxedError> { fn load(content: Cow<[u8]>, _: &str) -> Result<Image, BoxedError> {
let format = match ext { let format = image::ImageFormat::Png;
"png" => image::ImageFormat::Png,
"jpg" => image::ImageFormat::Jpeg,
_ => return Err("unknown image format".into()),
};
let image = image::load_from_memory_with_format(&content, format)?; let image = image::load_from_memory_with_format(&content, format)?;
Ok(Image(Arc::new(image))) Ok(Image(Arc::new(image)))
} }
} }
impl Asset for Image { impl Asset for Image {
type Loader = ImageLoader; type Loader = PngLoader;
const EXTENSIONS: &'static [&'static str] = &["png", "jpg"]; const EXTENSION: &'static str = "png";
} }
pub struct DotVoxAsset(pub DotVoxData); pub struct DotVoxAsset(pub DotVoxData);