From 20f84144b3e9d0b8fdf2798cbfe3c831a3286300 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 28 Jan 2024 20:08:42 +0100 Subject: [PATCH] Add `image.kill` property accessor Handy for stopping long-running computations. --- CHANGELOG.md | 1 + build/preamble_vips.d.ts | 5 +++++ lib/vips.d.ts | 5 +++++ src/bindings/image.h | 8 ++++++++ src/vips-emscripten.cpp | 1 + 5 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12a1d7623..e245d9d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Uses libvips v8.15.1, compiled with Emscripten v3.1.52. - Add `image.onProgress` callback for progress feedback. [#63](https://github.com/kleisauke/wasm-vips/issues/63) +- Add `image.kill` property accessor to block evaluation. ## [v0.0.7] - 2023-11-12 diff --git a/build/preamble_vips.d.ts b/build/preamble_vips.d.ts index 14051743b..2f743d4f7 100644 --- a/build/preamble_vips.d.ts +++ b/build/preamble_vips.d.ts @@ -506,6 +506,11 @@ declare module Vips { */ readonly filename: string; + /** + * Block evaluation on this image. + */ + kill: boolean; + /** * Attach progress feedback. * diff --git a/lib/vips.d.ts b/lib/vips.d.ts index 5d258390b..feb01a746 100644 --- a/lib/vips.d.ts +++ b/lib/vips.d.ts @@ -506,6 +506,11 @@ declare module Vips { */ readonly filename: string; + /** + * Block evaluation on this image. + */ + kill: boolean; + /** * Attach progress feedback. * diff --git a/src/bindings/image.h b/src/bindings/image.h index cbfcaa1db..b535b4d49 100644 --- a/src/bindings/image.h +++ b/src/bindings/image.h @@ -82,6 +82,14 @@ class Image : public Object { return vips_image_get_filename(get_image()); } + bool is_killed() const { + return vips_image_iskilled(get_image()); + } + + void set_kill(bool kill) { + vips_image_set_kill(get_image(), kill ? 1 : 0); + } + static void eval_handler(VipsImage *image, VipsProgress *progress, void *user); diff --git a/src/vips-emscripten.cpp b/src/vips-emscripten.cpp index 343bc951b..b33d9b407 100644 --- a/src/vips-emscripten.cpp +++ b/src/vips-emscripten.cpp @@ -1105,6 +1105,7 @@ EMSCRIPTEN_BINDINGS(my_module) { .property("yres", &Image::yres) .property("filename", &Image::filename) // Handwritten setters + .property("kill", &Image::is_killed, &Image::set_kill) .property("onProgress", &Image::stub_getter, &Image::set_progress_callback) // Auto-generated (class-)functions