/** Run-length colours along a row or column: bun bench/slint/runs.ts in.png row|col fixed from to */
import { readFileSync } from 'node:fs'
import { decodePng, pixelHex } from '../../tools/bench/png'
const [file, axis, fixedS, fromS, toS] = process.argv.slice(2)
if (!file || !axis) throw new Error('usage: bun bench/slint/runs.ts in.png row|col fixed from to')
const img = decodePng(readFileSync(file))
const fixed = Number(fixedS), from = Number(fromS), to = Number(toS)
let prev = '', start = from
const out: string[] = []
for (let t = from; t <= Math.min(to, (axis === "row" ? img.width : img.height) - 1); t++) {
const hex = pixelHex(img, axis === 'row' ? t : fixed, axis === 'row' ? fixed : t)
if (hex !== prev) {
if (prev) out.push(t - 1 > start ? `${start}-${t - 1}:${prev}` : `${start}:${prev}`)
prev = hex; start = t
}
}
out.push(to > start ? `${start}-${to}:${prev}` : `${start}:${prev}`)
console.log(out.join(' '))