42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
/**
|
|
* AWB Runner - Static WASM version
|
|
*
|
|
* Usage: node run_awb_static.cjs <input_base64>
|
|
*
|
|
* Writes input PNG to MEMFS (preRun), runs main(), reads output from MEMFS,
|
|
* outputs base64 of result PNG to stdout. Metadata to stderr.
|
|
*/
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const inputBase64 = process.argv[2];
|
|
if (!inputBase64) {
|
|
console.error('Usage: node run_awb_static.cjs <input_base64>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const mod = require('./awb_static.js');
|
|
|
|
// Prevent auto-running of main()
|
|
mod.noInitialRun = true;
|
|
|
|
// Write input to MEMFS before main()
|
|
mod.preRun = function() {
|
|
const buf = Buffer.from(inputBase64, 'base64');
|
|
mod.FS.mkdirTree('/data');
|
|
mod.FS.writeFile('/data/input.png', new Uint8Array(buf));
|
|
};
|
|
|
|
// Wait for runtime init, then call callMain manually
|
|
mod.onRuntimeInitialized = function() {
|
|
try {
|
|
mod.callMain([]);
|
|
// After main completes, read output
|
|
const outputBytes = mod.FS.readFile('/data/output.png');
|
|
process.stdout.write(Buffer.from(outputBytes).toString('base64'));
|
|
} catch (e) {
|
|
console.error('ERR:', e.message || e);
|
|
process.exit(1);
|
|
}
|
|
};
|