use std::sync::Arc;
use renderer_core::ImageData;
use ui_core::{AssetDecoder, AssetError};
pub struct ImageDecoder;
impl AssetDecoder for ImageDecoder {
fn kind(&self) -> &'static str {
"image"
}
type Output = Arc<ImageData>;
fn decode(&self, bytes: &[u8]) -> Result<Self::Output, AssetError> {
let decoded = image::load_from_memory(bytes)
.map_err(|e| AssetError(format!("failed to decode image: {e}")))?;
let rgba = decoded.to_rgba8();
let (width, height) = rgba.dimensions();
Ok(Arc::new(ImageData::new(rgba.into_raw(), width, height)))
}
}
#[cfg(test)]
#[path = "image_test.rs"]
mod tests;