summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2022-10-13 21:02:34 -0400
committerMicha White <botahamec@outlook.com>2022-10-13 21:02:34 -0400
commit7a7fab532c88c7ce7be5dc35f7cd70d0cb369a16 (patch)
tree6109d834282270527e01c4fc8c47e401b597e44c /src
parent67c133aa0ab205259176d2c210b9ab538f6109ba (diff)
You can load images now!
Diffstat (limited to 'src')
-rw-r--r--src/texture.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/texture.rs b/src/texture.rs
index ac2dd63..3b998a8 100644
--- a/src/texture.rs
+++ b/src/texture.rs
@@ -40,14 +40,26 @@ impl ImageFormat {
}
}
-type PackError = impl std::fmt::Debug;
+#[derive(Debug, Error)]
+#[error("{:?}", .0)]
+pub struct PackError(PackErrorInternal);
+
+type PackErrorInternal = impl std::fmt::Debug;
#[derive(Error, Debug)]
pub enum TextureError {
#[error("{:?}", .0)]
- TextureTooLarge(PackError), // use an error with a source
+ TextureTooLarge(
+ #[source]
+ #[from]
+ PackError,
+ ),
#[error("{}", .0)]
- BadImage(#[source] DecodingError), // TODO don't export this
+ BadImage(
+ #[source]
+ #[from]
+ DecodingError,
+ ), // TODO don't export this
#[error("Unexpected Error (this is a bug in alligator_render): {}", .0)]
Unexpected(#[source] Box<dyn Error>),
}
@@ -55,7 +67,7 @@ pub enum TextureError {
impl From<ImageError> for TextureError {
fn from(ie: ImageError) -> Self {
match ie {
- ImageError::Decoding(de) => Self::BadImage(de),
+ ImageError::Decoding(de) => de.into(),
_ => Self::Unexpected(Box::new(ie)),
}
}
@@ -189,11 +201,12 @@ impl TextureAtlas {
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)
- .map_err(TextureError::TextureTooLarge)?;
+ Ok(self.pack_rgba8(img)?)
+ }
+ pub fn pack_rgba8(&mut self, img: RgbaImage) -> Result<TextureId, PackError> {
+ let id = TextureId::new();
+ self.packer.pack_own(id, img).map_err(PackError)?;
Ok(id)
}