mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
29 lines
881 B
TypeScript
29 lines
881 B
TypeScript
import { readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { type ProgressCallback, parseStdoutJson, runPythonWithProgress } from "./bridge.js";
|
|
|
|
export async function inpaint(
|
|
inputBuffer: Buffer,
|
|
maskBuffer: Buffer,
|
|
outputDir: string,
|
|
onProgress?: ProgressCallback,
|
|
): Promise<Buffer> {
|
|
const inputPath = join(outputDir, "input_inpaint.png");
|
|
const maskPath = join(outputDir, "mask_inpaint.png");
|
|
const outputPath = join(outputDir, "output_inpaint.png");
|
|
|
|
await writeFile(inputPath, inputBuffer);
|
|
await writeFile(maskPath, maskBuffer);
|
|
|
|
const { stdout } = await runPythonWithProgress("inpaint.py", [inputPath, maskPath, outputPath], {
|
|
onProgress,
|
|
});
|
|
|
|
const result = parseStdoutJson(stdout);
|
|
if (!result.success) {
|
|
throw new Error(result.error || "Inpainting failed");
|
|
}
|
|
|
|
return readFile(outputPath);
|
|
}
|