mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 18:19:47 +00:00
wip
# Conflicts: # codecs/cpp.Dockerfile # codecs/imagequant/example.html # codecs/webp/dec/webp_dec.d.ts # codecs/webp/dec/webp_dec.js # codecs/webp/dec/webp_dec.wasm # codecs/webp/enc/webp_enc.d.ts # codecs/webp/enc/webp_enc.js # codecs/webp/enc/webp_enc.wasm # package-lock.json # package.json # src/codecs/tiny.webp # src_old/codecs/encoders.ts # src_old/codecs/processor-worker/tiny.avif # src_old/codecs/processor-worker/tiny.webp # src_old/codecs/tiny.webp # src_old/components/compress/index.tsx # src_old/lib/util.ts # src_old/sw/util.ts
This commit is contained in:
30
src_old/codecs/imagequant/processor.ts
Normal file
30
src_old/codecs/imagequant/processor.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import imagequant, {
|
||||
QuantizerModule,
|
||||
} from '../../../codecs/imagequant/imagequant';
|
||||
import wasmUrl from '../../../codecs/imagequant/imagequant.wasm';
|
||||
import { QuantizeOptions } from './processor-meta';
|
||||
import { initEmscriptenModule } from '../util';
|
||||
|
||||
let emscriptenModule: Promise<QuantizerModule>;
|
||||
|
||||
export async function process(
|
||||
data: ImageData,
|
||||
opts: QuantizeOptions,
|
||||
): Promise<ImageData> {
|
||||
if (!emscriptenModule)
|
||||
emscriptenModule = initEmscriptenModule(imagequant, wasmUrl);
|
||||
|
||||
const module = await emscriptenModule;
|
||||
|
||||
const result = opts.zx
|
||||
? module.zx_quantize(data.data, data.width, data.height, opts.dither)
|
||||
: module.quantize(
|
||||
data.data,
|
||||
data.width,
|
||||
data.height,
|
||||
opts.maxNumColors,
|
||||
opts.dither,
|
||||
);
|
||||
|
||||
return new ImageData(result, data.width, data.height);
|
||||
}
|
||||
Reference in New Issue
Block a user