Add convenience bindings for javascript to check filetype and to get primary image handle #1218
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.
Currently if you want to check the filetype of some buffer in javascript you need to do something like:
This is not only alot of manual memory management on the javascript side but also requires defining a copy of the
heif_filetype_result
enum on the javascript side to avoid using hardcoded numbers since the enum is not exported by the emscripten bindings.With new bindings it would be simplified to:
Additionally, (as far I know) the only way to get a proper javascript handle to the primary image is to first use
heif_js_context_get_list_of_top_level_image_IDs
to get all the image ids, then useheif_context_get_image_handle
on each id, then finally useheif_image_handle_is_primary_image
on each handle until the primary image handle is found. A special js binding likeheif_js_context_get_primary_image_handle
would be very convenient to avoid having to do this, especially since the functionheif_context_get_primary_image_handle
already exists.