Skip to content

fixes for issue #62#63

Open
ahmedezzat85 wants to merge 23 commits into
cornerstonejs:mainfrom
ahmedezzat85:main
Open

fixes for issue #62#63
ahmedezzat85 wants to merge 23 commits into
cornerstonejs:mainfrom
ahmedezzat85:main

Conversation

@ahmedezzat85
Copy link
Copy Markdown

No description provided.

ahmedezzat85 and others added 23 commits May 17, 2026 11:42
…irect call signature mismatch in openjpeg j2k_exec pipeline
…gnature mismatch in openjpeg j2k_exec pipeline

WebAssembly's typed function table traps on any indirect call where the
caller and callee signatures don't match exactly. openjpeg's j2k_exec()
builds a procedure list of function pointers at runtime and invokes them
with casts that are valid in C but illegal in WASM.

EMULATE_FUNCTION_POINTER_CASTS=1 instructs Emscripten to emit a trampoline
shim for each mismatched indirect call, padding/truncating arguments to
match the actual call site signature, preventing the hard WASM trap.
Two independent correctness fixes:

1. Use x1-x0 / y1-y0 for image dimensions instead of x1/y1 directly.
   image->x1 and image->y1 are absolute grid coordinates, not pixel counts.
   For any DICOM image where the image origin (x0, y0) is non-zero (tiled
   datasets, multi-frame, images with a non-zero offset), using x1/y1
   directly produces an incorrect buffer size and pixel mapping.

2. Call opj_end_decompress() after opj_decode().
   This is required by the openjpeg API to properly finalize decompression
   and release internal codec state before destroying the codec/stream.
   Omitting it can leave codec resources in an inconsistent state.

3. Remove unused variable: int comp_num.
The info handler printed [INFO] for every tile header read, tile decode,
and image data update. This floods the browser console with ~4 lines per
tile. Warning and error handlers are retained for diagnostics.
Restore info_callback and opj_set_info_handler in J2KDecoder.hpp.
Restore full EMSCRIPTEN_BINDINGS in jslib-decode.cpp.
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.

1 participant