forked from external-repos/squoosh
Add Hq{2,3,4}x (#624)
* 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
This commit is contained in:
32
src/codecs/hqx/processor.ts
Normal file
32
src/codecs/hqx/processor.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user