Memory view rather than pointers (#144). Part of #141.

* Returning an object seems to work well

* This doesn't work

* This does!

* Better cast?

* Updating usage in Squoosh
This commit is contained in:
Jake Archibald
2018-08-21 09:27:04 +01:00
committed by GitHub
parent 1ae65dd4a1
commit 8006a1a5e7
14 changed files with 62 additions and 146 deletions

View File

@@ -34,17 +34,10 @@ export default class WebPEncoder {
async encode(data: ImageData, options: EncodeOptions): Promise<ArrayBuffer> {
const module = await this.emscriptenModule;
const p = module.create_buffer(data.width, data.height);
module.HEAP8.set(data.data, p);
module.encode(p, data.width, data.height, options);
const resultPointer = module.get_result_pointer();
const resultSize = module.get_result_size();
const resultView = new Uint8Array(module.HEAP8.buffer, resultPointer, resultSize);
const resultView = module.encode(data.data, data.width, data.height, options);
const result = new Uint8Array(resultView);
module.free_result();
module.destroy_buffer(p);
// wasm cant run on SharedArrayBuffers, so we hard-cast to ArrayBuffer.
return result.buffer as ArrayBuffer;
}
}