diff options
| author | Micha White <botahamec@outlook.com> | 2022-10-01 21:47:27 -0400 |
|---|---|---|
| committer | Micha White <botahamec@outlook.com> | 2022-10-01 21:47:27 -0400 |
| commit | 39e36dd10cd7a335897e66e0f613d0191e7f9eba (patch) | |
| tree | 9363197b9450b68f35f26f48080c56333574b62c | |
| parent | 5d299af0e592c76c62c6347152eae2257a95c71f (diff) | |
Custom ImageFormat type
| -rw-r--r-- | src/texture.rs | 26 |
1 files changed, 23 insertions, 3 deletions
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<TextureId, TextureError> { - let img = image::load_from_memory(buf)?.into_rgba8(); + pub fn load_from_memory( + &mut self, + buf: &[u8], + format: ImageFormat, + ) -> Result<TextureId, TextureError> { + let img = image::load_from_memory_with_format(buf, format.format())?.into_rgba8(); let id = TextureId::new(); self.packer .pack_own(id, img) |
