Skip to content
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup emscripten
uses: mymindstorm/setup-emsdk@v14

- name: Prepare cargo tests
run: |
rustup target add wasm32-unknown-emscripten --toolchain=nightly
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ yuv = { version = "0.1.9", optional = true }
wasm-bindgen = { version = "0.2.108", optional = true }
web-sys = {version="0.3.85", features = ["console"], optional = true }
console_error_panic_hook = {version = "0.1.7", optional = true}

# Only for browser wasm (wasm-pack). Requires RUSTFLAGS with +atomics,+bulk-memory.
# Not used on wasm32-unknown-emscripten, where rayon uses pthreads instead.
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
wasm-bindgen-rayon = "1.3.0"

[dependencies.ffmpeg]
Expand Down
2 changes: 1 addition & 1 deletion src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub unsafe extern "C" fn gifski_add_fixed_color(handle: *mut GifskiHandle, col_r
///
/// Returns 0 (`GIFSKI_OK`) on success, and non-0 `GIFSKI_*` constant on error.
#[no_mangle]
#[cfg(feature = "png")]
#[cfg(all(feature = "png", not(all(target_arch = "wasm32", target_os = "unknown"))))]
pub unsafe extern "C" fn gifski_add_frame_png_file(handle: *const GifskiHandle, frame_number: u32, file_path: *const c_char, presentation_timestamp: f64) -> GifskiError {
if file_path.is_null() {
return GifskiError::NULL_ARG;
Expand Down
6 changes: 3 additions & 3 deletions src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ pub use rgb::{RGB8, RGBA8};
use crate::error::GifResult;
use crossbeam_channel::Sender;

#[cfg(feature = "png")]
#[cfg(all(feature = "png", not(all(target_arch = "wasm32", target_os = "unknown"))))]
use std::path::PathBuf;

pub(crate) enum FrameSource {
Pixels(ImgVec<RGBA8>),
#[cfg(feature = "png")]
PngData(Vec<u8>),
#[cfg(all(feature = "png", not(target_arch = "wasm32")))]
#[cfg(all(feature = "png", not(all(target_arch = "wasm32", target_os = "unknown"))))]
Path(PathBuf),
}

Expand Down Expand Up @@ -102,7 +102,7 @@ impl Collector {
/// If the first frame doesn't start at pts=0, the delay will be used for the last frame.
///
/// If this function appears to be stuck after a few frames, it's because [`crate::Writer::write()`] is not running.
#[cfg(feature = "png")]
#[cfg(all(feature = "png", not(all(target_arch = "wasm32", target_os = "unknown"))))]
pub fn add_frame_png_file(&self, frame_index: usize, path: PathBuf, presentation_timestamp: f64) -> GifResult<()> {
self.queue.send(InputFrame {
frame: FrameSource::Path(path),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl Writer {
.map_err(|err| Error::PNG(format!("Can't load PNG: {err}")))?;
Img::new(image.buffer, image.width, image.height)
},
#[cfg(feature = "png")]
#[cfg(all(feature = "png", not(all(target_arch = "wasm32", target_os = "unknown"))))]
FrameSource::Path(path) => {
let image = lodepng::decode32_file(&path)
.map_err(|err| Error::PNG(format!("Can't load {}: {err}", path.display())))?;
Expand Down
3 changes: 2 additions & 1 deletion src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ impl GifskiWasm {
}
}

// thread pool for wasm-bindgen-rayon
// thread pool for wasm-bindgen-rayon (browser wasm only; emscripten uses pthreads)
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
#[wasm_bindgen]
pub fn init_thread_pool(num_threads: usize) -> Result<(), JsValue> {
wasm_bindgen_rayon::init_thread_pool(num_threads);
Expand Down