Skip to content

Conversation

@mrdoob
Copy link
Owner

@mrdoob mrdoob commented Nov 10, 2025

Related issue: #31911

Description

Adds support for HTJ2K (High Throughput JPEG 2000) compression in EXRLoader, following OpenEXR 3.4.0 specification. Includes a new JPHLoader for standalone JPEG 2000 files.

Changes

  • EXRLoader: Added HTJ2K decompression (compression code 11)

    • Automatic OpenJPH WASM initialization (lazy loading)
    • Parses HTJ2K header format (magic, payload length, channel map)
    • Async parse() method to support WASM loading
  • JPHLoader: New loader for standalone JPEG 2000/HTJ2K files

    • Auto-initializes OpenJPH WASM on first use
    • Supports 8-bit, 16-bit, and 32-bit data
    • Progressive decoding and resolution skipping
  • Bundled OpenJPH WASM: ~126 KB (105 KB WASM + 21 KB JS)

@mrdoob mrdoob added this to the r182 milestone Nov 10, 2025
}

// Read payload length
const payloadLength = dv.getUint32( offset, false ); // big-endian

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable payloadLength.

Copilot Autofix

AI about 15 hours ago

The fix is simple: remove the unused variable declaration. That is, eliminate the line where payloadLength is declared and assigned:

const payloadLength = dv.getUint32( offset, false ); // big-endian

but preserve the effect of incrementing the offset by 4, as this represents skipping over this header field in the binary data to reach the next field (numChannels). Thus, replace the line with just offset += 4; so the parsing continues correctly. Make this change only in the region of the function where payloadLength is present, i.e., in the surrounding code snippet.


Suggested changeset 1
examples/jsm/loaders/EXRLoader.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/examples/jsm/loaders/EXRLoader.js b/examples/jsm/loaders/EXRLoader.js
--- a/examples/jsm/loaders/EXRLoader.js
+++ b/examples/jsm/loaders/EXRLoader.js
@@ -1825,8 +1825,7 @@
 		}
 
 		// Read payload length
-		const payloadLength = dv.getUint32( offset, false ); // big-endian
-		offset += 4;
+		offset += 4; // skip payloadLength field (unused)
 
 		// Read number of channels
 		const numChannels = dv.getUint16( offset, false ); // big-endian
EOF
@@ -1825,8 +1825,7 @@
}

// Read payload length
const payloadLength = dv.getUint32( offset, false ); // big-endian
offset += 4;
offset += 4; // skip payloadLength field (unused)

// Read number of channels
const numChannels = dv.getUint16( offset, false ); // big-endian
Copilot is powered by AI and may make mistakes. Always verify output.
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