Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support building for wasm32-wasi targets. #168

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ pub fn to_image_data(photon_image: PhotonImage) -> ImageData {
.unwrap()
}

#[cfg(not(target_os = "wasi"))]
fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function to get better error messages if we ever panic.
Expand Down
16 changes: 8 additions & 8 deletions crate/src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::PhotonImage;
#[cfg(feature = "enable_wasm")]
use wasm_bindgen::prelude::*;

#[cfg(target_family = "wasm")]
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use js_sys::Math::random;

#[cfg(not(target_family = "wasm"))]
#[cfg(not(all(target_arch = "wasm", not(target_os = "wasi"))))]
use rand::Rng;

/// Add randomized noise to an image.
Expand All @@ -39,14 +39,14 @@ use rand::Rng;
pub fn add_noise_rand(photon_image: &mut PhotonImage) {
let mut img = helpers::dyn_image_from_raw(photon_image);

#[cfg(not(target_family = "wasm"))]
#[cfg(not(all(target_arch = "wasm", not(target_os = "wasi"))))]
let mut rng = rand::thread_rng();

for (x, y) in ImageIterator::with_dimension(&img.dimensions()) {
#[cfg(not(target_family = "wasm"))]
#[cfg(not(all(target_arch = "wasm", not(target_os = "wasi"))))]
let offset = rng.gen_range(0, 150);

#[cfg(target_family = "wasm")]
#[cfg(all(target_arch = "wasm", not(target_os = "wasi")))]
let offset = (random() * 150.0) as u8;

let px =
Expand Down Expand Up @@ -84,13 +84,13 @@ pub fn add_noise_rand(photon_image: &mut PhotonImage) {
#[cfg_attr(feature = "enable_wasm", wasm_bindgen)]
pub fn pink_noise(photon_image: &mut PhotonImage) {
let mut img = helpers::dyn_image_from_raw(photon_image);
#[cfg(not(target_family = "wasm"))]
#[cfg(not(all(target_arch = "wasm", not(target_os = "wasi"))))]
let mut rng = rand::thread_rng();

#[cfg(not(target_family = "wasm"))]
#[cfg(not(all(target_arch = "wasm", not(target_os = "wasi"))))]
let mut rng_gen = move || rng.gen();

#[cfg(target_family = "wasm")]
#[cfg(all(target_arch = "wasm", not(target_os = "wasi")))]
let rng_gen = || random();

for (x, y) in ImageIterator::with_dimension(&img.dimensions()) {
Expand Down
4 changes: 2 additions & 2 deletions crate/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn crop(
}
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
#[cfg_attr(feature = "enable_wasm", wasm_bindgen)]
pub fn crop_img_browser(
source_canvas: HtmlCanvasElement,
Expand Down Expand Up @@ -198,7 +198,7 @@ fn filter_type_from_sampling_filter(sampling_filter: SamplingFilter) -> FilterTy
/// * `width` - New width.
/// * `height` - New height.
/// * `sampling_filter` - Nearest = 1, Triangle = 2, CatmullRom = 3, Gaussian = 4, Lanczos3 = 5
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
#[cfg_attr(feature = "enable_wasm", wasm_bindgen)]
pub fn resize_img_browser(
photon_img: &PhotonImage,
Expand Down
Loading