From 39e36dd10cd7a335897e66e0f613d0191e7f9eba Mon Sep 17 00:00:00 2001 From: Micha White Date: Sat, 1 Oct 2022 21:47:27 -0400 Subject: Custom ImageFormat type --- src/texture.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/texture.rs b/src/texture.rs index aa6f871..8a36334 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -20,6 +20,23 @@ impl TextureId { } } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum ImageFormat { + Bmp, + Ico, + Farbfeld, +} + +impl ImageFormat { + const fn format(self) -> image::ImageFormat { + match self { + Self::Bmp => image::ImageFormat::Bmp, + Self::Ico => image::ImageFormat::Ico, + Self::Farbfeld => image::ImageFormat::Farbfeld, + } + } +} + type PackError = impl std::fmt::Debug; #[derive(Error, Debug)] @@ -66,10 +83,13 @@ impl<'a> TextureAtlases<'a> { } } - // TODO specify format // TODO support RGBA16 - pub fn load_from_memory(&mut self, buf: &[u8]) -> Result { - let img = image::load_from_memory(buf)?.into_rgba8(); + pub fn load_from_memory( + &mut self, + buf: &[u8], + format: ImageFormat, + ) -> Result { + let img = image::load_from_memory_with_format(buf, format.format())?.into_rgba8(); let id = TextureId::new(); self.packer .pack_own(id, img) -- cgit v1.2.3