♻️ Use of "target_family" instead of feature to manage wasm platform
This commit is contained in:
@@ -6,6 +6,12 @@ use image::{DynamicImage, ImageFormat};
|
||||
use image::{GenericImage, RgbImage};
|
||||
use tracing::{error, warn};
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(not(target_family = "wasm"))] {
|
||||
use tokio::task::spawn_blocking;
|
||||
}
|
||||
}
|
||||
|
||||
fn from_raw_to_image(raw: &Vec<u8>) -> Option<DynamicImage> {
|
||||
match Reader::new(Cursor::new(raw)).with_guessed_format() {
|
||||
Ok(reader) => match reader.decode() {
|
||||
@@ -19,7 +25,7 @@ fn from_raw_to_image(raw: &Vec<u8>) -> Option<DynamicImage> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn create_mozaik(
|
||||
fn create_mozaik_(
|
||||
width_px: u32,
|
||||
height_px: u32,
|
||||
images: &[Vec<u8>],
|
||||
@@ -90,3 +96,21 @@ pub fn create_mozaik(
|
||||
|
||||
bytes
|
||||
}
|
||||
|
||||
pub async fn create_mozaik(
|
||||
width_px: u32,
|
||||
height_px: u32,
|
||||
images: Vec<Vec<u8>>,
|
||||
padding_image: Option<Vec<u8>>,
|
||||
) -> Vec<u8> {
|
||||
cfg_if! {
|
||||
if #[cfg(target_family = "wasm")] {
|
||||
create_mozaik_(width_px, height_px, &images, &padding_image)
|
||||
}
|
||||
else {
|
||||
spawn_blocking(move || {
|
||||
create_mozaik_(width_px, height_px, &images, &padding_image)
|
||||
}).await.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user