use valo::ImageContext;
use valo_codec::{Decoder, ImageLoader};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum DecodeExecution {
#[cfg_attr(
not(all(feature = "image-worker", not(target_arch = "wasm32"))),
default
)]
Local,
#[cfg(all(feature = "image-worker", not(target_arch = "wasm32")))]
#[default]
Worker,
}
pub fn create_image_loader(
images: ImageContext,
execution: DecodeExecution,
) -> std::io::Result<ImageLoader> {
let decoders: Vec<Box<dyn Decoder>> = vec![
#[cfg(all(feature = "image-apple", any(target_os = "macos", target_os = "ios")))]
Box::new(valo_codec_apple::AppleDecoder::default()),
#[cfg(feature = "image-software")]
Box::new(valo_codec_software::SoftwareDecoder),
];
match execution {
DecodeExecution::Local => Ok(ImageLoader::new(images, decoders)),
#[cfg(all(feature = "image-worker", not(target_arch = "wasm32")))]
DecodeExecution::Worker => ImageLoader::with_worker(images, decoders),
}
}