MCPcopy Create free account
hub / github.com/GoogleChrome/samples / process

Function process

mkbitmap/script.js:26–75  ·  view source on GitHub ↗
(buffer)

Source from the content-addressed store, hash-verified

24let buffer;
25
26const process = async (buffer) => {
27 const Module = await loadWASM();
28 Module.FS.writeFile(inputImage, new Uint8Array(buffer));
29
30 if (Module.FS.analyzePath(outputImage).exists) {
31 Module.FS.unlink(outputImage);
32 }
33
34 try {
35 const options = [
36 '-o',
37 outputImage,
38 inputImage,
39 '-s',
40 scaleInput.value,
41 cubicRadio.checked ? '-3' : '-1',
42 ];
43 if (blurInput.value > 0) {
44 options.push('-b', blurInput.value);
45 }
46 if (!noFilterCheckbox.checked) {
47 options.push('-f', filterInput.value);
48 }
49 if (!noThresholdCheckbox.checked) {
50 options.push('-t', thresholdInput.value);
51 }
52 if (invertCheckbox.checked) {
53 options.push('-i');
54 }
55 pre.textContent = `mkbitmap ${options
56 .join(' \\\n ')
57 .replaceAll(/\\\n\s+(-?[\d+|+o])/g, '$1')}`;
58 Module.callMain(options);
59
60 const output = Module.FS.readFile(outputImage, { encoding: 'binary' });
61 const file = new File([output], outputImage, {
62 type: 'image/x-portable-bitmap',
63 });
64
65 const image = new PBMImage(await file.text());
66 const imageData = image.getImageData();
67
68 ctx.clearRect(0, 0, canvas.width, canvas.height);
69 canvas.width = imageData.width;
70 canvas.height = imageData.height;
71 ctx.putImageData(imageData, 0, 0);
72 } catch (err) {
73 console.error(err.name, err.message);
74 }
75};
76
77[blurInput, filterInput, scaleInput, thresholdInput].forEach((input) => {
78 input.nextElementSibling.textContent = input.value;

Callers 1

script.jsFile · 0.85

Calls 2

unlinkMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected