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 heif_items API to emscripten #1462

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

dukesook
Copy link
Contributor

@dukesook dukesook commented Feb 11, 2025

I would like add the heif_items.h API so JavaScript application can leverage that functionality.

I'm still trying to compile libheif to JavaScript/WASM so I can't test out the code yet, but I wanted some initial feedback on this task.

@farindk
Copy link
Contributor

farindk commented Feb 11, 2025

Sure, would be good to increase the coverage of the JS wrapper.

@farindk
Copy link
Contributor

farindk commented Feb 11, 2025

Main hurdle might be that we do not do any encoding and writing of HEIFs in JS yet. You cannot add items to existing files (yet), even in the C API.

@dukesook
Copy link
Contributor Author

That's fine, I'm mostly interested in reading & decoding.

@dukesook
Copy link
Contributor Author

Half the emscripten functions have the js prefix and the other half don't.
e.g.
heif_context_read_from_memory()
heif_js_check_filetype()

It would be nice if there was a more consistent naming convention, but this might be a breaking change. Any thoughts?

@farindk
Copy link
Contributor

farindk commented Feb 19, 2025

Half the emscripten functions have the js prefix and the other half don't. e.g. heif_context_read_from_memory() heif_js_check_filetype()

Yes. I think originally every function that required an explicit JS wrapper got the _js_ prefix. But I guess that this is not necessary. We can simply put the original name into the function table and reference the _js_ function from there. We could also leave the old _js_ functions in the table to avoid breaking backwards compatibility (and add a deprecation comment).

The convention could be: use the original name when the function is the equivalent of the original function, even if they required a wrapper. Functions that are JavaScript specific (e.g. heif_js_decode_image2) keep the _js_ prefix.

@farindk
Copy link
Contributor

farindk commented Feb 19, 2025

For heif_item_get_item_type() vs heif_js_item_get_item_type_string() it's a bit tricky. I would argue that working with uint32_t on the JS side is inconvenient such that we always use strings for four-cc codes. Hence, the original name heif_item_get_item_type() is ok despite the changed type.

@dukesook dukesook marked this pull request as ready for review February 21, 2025 16:06
@dukesook
Copy link
Contributor Author

dukesook commented Feb 21, 2025

The PR now:

  • Adds the heif_item.h API
  • Adheres to a naming convention & deprecates functions don't follow it
  • Ignores the buildjs directory
  • Uses alloca() instead of malloc()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants