mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-18 11:39:08 +00:00
Simplify memory management for other C++ codecs
This commit is contained in:
committed by
Ingvar Stepanyan
parent
97931bad22
commit
93cbe557cd
@@ -15,5 +15,5 @@ export async function process(data: ImageData, opts: QuantizeOptions): Promise<I
|
||||
:
|
||||
module.quantize(data.data, data.width, data.height, opts.maxNumColors, opts.dither);
|
||||
|
||||
return new ImageData(new Uint8ClampedArray(result), data.width, data.height);
|
||||
return new ImageData(result, data.width, data.height);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,6 @@ export async function encode(data: ImageData, options: EncodeOptions): Promise<A
|
||||
|
||||
const module = await emscriptenModule;
|
||||
const resultView = module.encode(data.data, data.width, data.height, options);
|
||||
const result = new Uint8Array(resultView);
|
||||
module.free_result();
|
||||
|
||||
// wasm can’t run on SharedArrayBuffers, so we hard-cast to ArrayBuffer.
|
||||
return result.buffer as ArrayBuffer;
|
||||
return resultView.buffer as ArrayBuffer;
|
||||
}
|
||||
|
||||
@@ -8,13 +8,5 @@ export async function decode(data: ArrayBuffer): Promise<ImageData> {
|
||||
if (!emscriptenModule) emscriptenModule = initEmscriptenModule(webp_dec, wasmUrl);
|
||||
|
||||
const module = await emscriptenModule;
|
||||
const rawImage = module.decode(data);
|
||||
const result = new ImageData(
|
||||
new Uint8ClampedArray(rawImage.buffer),
|
||||
rawImage.width,
|
||||
rawImage.height,
|
||||
);
|
||||
|
||||
module.free_result();
|
||||
return result;
|
||||
return module.decode(data);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ export async function encode(data: ImageData, options: EncodeOptions): Promise<A
|
||||
if (!emscriptenModule) emscriptenModule = initEmscriptenModule(webp_enc, wasmUrl);
|
||||
|
||||
const module = await emscriptenModule;
|
||||
const resultView = module.encode(data.data, data.width, data.height, options);
|
||||
const result = new Uint8Array(resultView);
|
||||
module.free_result();
|
||||
|
||||
const result = module.encode(data.data, data.width, data.height, options);
|
||||
// wasm can’t run on SharedArrayBuffers, so we hard-cast to ArrayBuffer.
|
||||
return result.buffer as ArrayBuffer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user