/**
* Cut a region out of a PNG, zoom it and draw a grid (line every 10 source px, brighter every 50),
* so crop coordinates can be read off by eye. Usage: bun bench/slint/grid.ts in.png x y w h zoom out.png
*/
import { readFileSync, writeFileSync } from 'node:fs'
import { crop, decodePng, encodePng, zoom } from '../../tools/bench/png'
const [file, xs, ys, ws, hs, zs, out] = process.argv.slice(2)
if (!file || !out) throw new Error('usage: bun bench/slint/grid.ts in.png x y w h zoom out.png')
const [x, y, w, h, z] = [xs, ys, ws, hs, zs].map(Number) as [number, number, number, number, number]
const img = zoom(crop(decodePng(readFileSync(file)), x, y, w, h), z)
for (let sx = 0; sx < w; sx++) {
const gx = x + sx
if (gx % 10) continue
for (let py = 0; py < img.height; py++) {
const i = (py * img.width + sx * z) * 4
const c = gx % 50 === 0 ? [255, 0, 255] : [0, 200, 255]
img.data[i] = c[0]!; img.data[i + 1] = c[1]!; img.data[i + 2] = c[2]!; img.data[i + 3] = 255
}
}
for (let sy = 0; sy < h; sy++) {
const gy = y + sy
if (gy % 10) continue
for (let px = 0; px < img.width; px++) {
const i = ((sy * z) * img.width + px) * 4
const c = gy % 50 === 0 ? [255, 0, 255] : [0, 200, 255]
img.data[i] = c[0]!; img.data[i + 1] = c[1]!; img.data[i + 2] = c[2]!; img.data[i + 3] = 255
}
}
writeFileSync(out, encodePng(img))
console.log(`${out}: ${img.width}x${img.height} origin ${x},${y} zoom ${z}`)