mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 09:39:16 +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
|
@ -12,12 +12,15 @@ debug: ${OUT_TARGET}
|
|||
clean:
|
||||
rm -rf ${OUT_PATH}/${OUT_NAME}.*
|
||||
|
||||
${OUT_TARGET}: ${SHIM_SRC}
|
||||
emcc -O3 \
|
||||
# Debug:
|
||||
# -O0
|
||||
# Optimizations:
|
||||
# -Os --llvm-lto 1
|
||||
${OUT_TARGET}: ${SHIM_SRC} Makefile
|
||||
emcc -Os --llvm-lto 1 \
|
||||
-s WASM=1 \
|
||||
-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' \
|
||||
-s ALLOW_MEMORY_GROWTH=1 \
|
||||
-s ASSERTIONS=1 \
|
||||
-I stb \
|
||||
-I libwebp \
|
||||
${LIBWEBP_SRC} \
|
||||
|
|
|
@ -63,7 +63,7 @@ void write_image_to_mem(void* context, void* data, int size) {
|
|||
|
||||
uint8_t* decode_webp_to_rgba(uint8_t* webp_ptr, size_t size, int* width, int* height) {
|
||||
if (!webp_ptr) {
|
||||
printf("webp_ptr is NULL");
|
||||
printf("decode_webp_to_rgba() called with NULL webp_ptr");
|
||||
}
|
||||
if (!WebPGetInfo(webp_ptr, size, width, height)) {
|
||||
fprintf(stderr, "WebPGetInfo() returned an error\n");
|
||||
|
|
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