/** Ink bounding box of a region against a background colour: bun bench/slint/ink.ts in.png x y w h #bg [threshold] */
import { readFileSync } from 'node:fs'
import { inkBox } from '../../tools/bench/diff'
import { decodePng } from '../../tools/bench/png'
const [file, xs, ys, ws, hs, bg, th] = process.argv.slice(2)
if (!file || !bg) throw new Error('usage: bun bench/slint/ink.ts in.png x y w h #bg [threshold]')
const [x, y, w, h] = [xs, ys, ws, hs].map(Number) as [number, number, number, number]
const box = inkBox(decodePng(readFileSync(file)), [x, y, w, h], bg, th ? Number(th) : undefined)
console.log(box ? `ink x${box[0]}-${box[2] - 1} y${box[1]}-${box[3] - 1} mask [${box[0]}, ${box[1]}, ${box[2] - box[0]}, ${box[3] - box[1]}]` : 'no ink')