forked from external-repos/squoosh
* Scaling works on native * It works in wasm * Integrate with UI * Remove benchmark * Integrate Hqx into Resizer module * Link against repo for hqx * Remove unused defaultOpts * Re-add test file * Adding size dropdown * Chrome: go and sit on the naughty step * Better docs * Review * Add link to crbug * Update src/codecs/processor-worker/index.ts Co-Authored-By: Jake Archibald <jaffathecake@gmail.com> * Terminate worker inbetween resize jobs
33 lines
812 B
TypeScript
33 lines
812 B
TypeScript
import wasmUrl from '../../../codecs/hqx/pkg/squooshhqx_bg.wasm';
|
|
import '../../../codecs/hqx/pkg/squooshhqx';
|
|
import { HqxOptions } from './processor-meta';
|
|
|
|
interface WasmBindgenExports {
|
|
resize: typeof import('../../../codecs/hqx/pkg/squooshhqx').resize;
|
|
}
|
|
|
|
type WasmBindgen = ((url: string) => Promise<void>) & WasmBindgenExports;
|
|
|
|
declare var wasm_bindgen: WasmBindgen;
|
|
|
|
const ready = wasm_bindgen(wasmUrl);
|
|
|
|
export async function hqx(
|
|
data: ImageData,
|
|
opts: HqxOptions,
|
|
): Promise<ImageData> {
|
|
const input = data;
|
|
await ready;
|
|
const result = wasm_bindgen.resize(
|
|
new Uint32Array(input.data.buffer),
|
|
input.width,
|
|
input.height,
|
|
opts.factor,
|
|
);
|
|
return new ImageData(
|
|
new Uint8ClampedArray(result.buffer),
|
|
data.width * opts.factor,
|
|
data.height * opts.factor,
|
|
);
|
|
}
|