mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 01:29:17 +02:00
Fix JPG function referencing detached heap. Also, optimize WASM module output.
This commit is contained in:
parent
9dc09e22f4
commit
3ad0fa4473
5 changed files with 12 additions and 9 deletions
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -20,8 +20,8 @@ function loadWebPShimApi() {
|
|||
return loadingPromise = new Promise((resolve, reject) => {
|
||||
const scriptEl = document.createElement('script');
|
||||
scriptEl.onload = () => {
|
||||
Module.print = str => console.log(str);
|
||||
Module.printErr = str => console.error(str);
|
||||
Module.print = str => console.log(`${Date.now()}: ${str}`);
|
||||
Module.printErr = str => console.error(`${Date.now()}: ${str}`);
|
||||
Module.onRuntimeInitialized = () => {
|
||||
api = {
|
||||
createWASMBuffer: Module.cwrap('create_buffer', 'number', ['number', 'number']),
|
||||
|
@ -76,13 +76,13 @@ export function convertWebPtoJPG(webpBuffer) {
|
|||
// Create a buffer of the WebP bytes that we can send into WASM-land.
|
||||
const size = webpBuffer.byteLength;
|
||||
const webpWASMBuffer = api.createWASMBuffer(size);
|
||||
api.heap.set(webpBuffer, webpWASMBuffer);
|
||||
api.module.HEAPU8.set(webpBuffer, webpWASMBuffer);
|
||||
|
||||
// Convert to JPG.
|
||||
const jpgHandle = api.getJPGHandle(webpWASMBuffer, size);
|
||||
const numJPGBytes = api.getNumBytesFromHandle(jpgHandle);
|
||||
const jpgBufPtr = api.getImageBytesFromHandle(jpgHandle);
|
||||
const jpgBuffer = api.heap.slice(jpgBufPtr, jpgBufPtr + numJPGBytes - 1);
|
||||
const jpgBuffer = api.module.HEAPU8.slice(jpgBufPtr, jpgBufPtr + numJPGBytes - 1);
|
||||
|
||||
// Cleanup.
|
||||
api.releaseImageHandle(jpgHandle);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue