Support for use in WASM environments (#192) #1697
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enables the use of libvips in WebAssembly environments (see #192). It consist of fixing function pointer cast issues,
which can only be detected at runtime (as far as I know). This PR has been tested on a WASM-ported version of the libvips test suite that includes 192 different tests.
It is possible that not all function pointer cast issues are fixed by this PR, as the WASM build does not contain all dependencies supported by libvips. I've managed to support JPEG, PNG, TIFF and WebP images by using libjpeg-turbo, libpng, libtiff and libwebp. EXIF metadata in JPEG files and ICC profile support is also available by using libexif and lcms2. For more details, see #192 (comment).
Here is a brief overview of the related changes within this PR:
vips_area_free_cb
(that matches theint (*VipsCallbackFn) (void *a, void *b)
signature), in favour of thevips_free
callback.vips_free
, just useg_free
for non-callback functions andvips_area_free_cb
for callback functions (e.g.vips_blob_new
orvips_image_set_blob
).vips_crop
needs an adapter function to work properly. This is basically the same as this patch for glib. I've#ifdef
'd this change with__EMSCRIPTEN__
since this is a quite a hackish workaround.GThreadFunc
callbacks now have the correct signature (i.e.void *(*GThreadFunc) (void *data)
).void *
parameter was missing from theVipsSListMap2Fn
andVipsRegionFillFn
callbacks.void *user_data
parameter to theGCompareFunc
andGFunc
callback functions. Needed byg_slist_sort
andg_slist_foreach
. This SO answer might be relevant here.vips_INT__VOID
,g_cclosure_marshal_VOID__POINTER
andg_cclosure_marshal_VOID__VOID
closures are called with an additionalvoid *data
argument.abi-compliance-checker
result:https://kleisauke.nl/compat_reports/vips/master_to_wasm-function-pointers/compat_report.html