Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions skills-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"files": 3
},
"hyperframes": {
"hash": "90b4e96c091ebe16",
"files": 80
"hash": "5e1305c67d48155a",
"files": 81
},
"hyperframes-cli": {
"hash": "8c7ba18bfc4e86c1",
Expand Down
32 changes: 13 additions & 19 deletions skills/hyperframes/scripts/locate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
import "./lib/windows-exe-search.mjs";
import { execFileSync } from "node:child_process";
import { existsSync, mkdirSync, copyFileSync } from "node:fs";
import { existsSync, mkdirSync } from "node:fs";

const N1 = 9,
PAD1 = 0.4; // stage 1: strips per axis, padding in STRIP units
Expand Down Expand Up @@ -54,39 +54,33 @@ function probe(img) {
const [w, h] = out.split(",").map(Number);
return { w, h };
}
function font() {
const dst = "/tmp/locate-font.ttf";
if (!existsSync(dst)) {
for (const c of [
"/System/Library/Fonts/Supplemental/Arial Bold.ttf",
"/System/Library/Fonts/Supplemental/Arial.ttf",
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
]) {
if (existsSync(c)) {
copyFileSync(c, dst);
break;
}
}
}
return dst;
const FONT_FILES = [
"/System/Library/Fonts/Supplemental/Arial Bold.ttf",
"/System/Library/Fonts/Supplemental/Arial.ttf",
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
];
// ffmpeg reads the system font in place; with none found, drawtext falls back to its default font.
function fontOption() {
const file = FONT_FILES.find((candidate) => existsSync(candidate));
return file ? `fontfile='${file}':` : "";
}
function gridFilters(w, h, n, axis, fz) {
const F = font(),
const F = fontOption(),
fs = [];
if (axis === "v" || axis === "both") {
for (let i = 1; i < n; i++)
fs.push(`drawbox=x=${Math.round((i * w) / n)}:y=0:w=2:h=${h}:color=${GREEN}@0.8:t=fill`);
for (let i = 0; i < n; i++)
fs.push(
`drawtext=fontfile=${F}:text='${i + 1}':x=${Math.round(((i + 0.5) * w) / n - fz * 0.3)}:y=6:fontsize=${fz}:fontcolor=black:box=1:boxcolor=white@0.95:boxborderw=5`,
`drawtext=${F}text='${i + 1}':x=${Math.round(((i + 0.5) * w) / n - fz * 0.3)}:y=6:fontsize=${fz}:fontcolor=black:box=1:boxcolor=white@0.95:boxborderw=5`,
);
}
if (axis === "h" || axis === "both") {
for (let j = 1; j < n; j++)
fs.push(`drawbox=x=0:y=${Math.round((j * h) / n)}:w=${w}:h=2:color=${BLUE}@0.8:t=fill`);
for (let j = 0; j < n; j++)
fs.push(
`drawtext=fontfile=${F}:text='${j + 1}':x=6:y=${Math.round(((j + 0.5) * h) / n - fz * 0.5)}:fontsize=${fz}:fontcolor=black:box=1:boxcolor=white@0.95:boxborderw=5`,
`drawtext=${F}text='${j + 1}':x=6:y=${Math.round(((j + 0.5) * h) / n - fz * 0.5)}:fontsize=${fz}:fontcolor=black:box=1:boxcolor=white@0.95:boxborderw=5`,
);
}
return fs;
Expand Down
51 changes: 51 additions & 0 deletions skills/hyperframes/scripts/locate.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import test from "node:test";
import assert from "node:assert/strict";
import { execFileSync, spawnSync } from "node:child_process";
import { existsSync, lstatSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";

const LOCATE = fileURLToPath(new URL("./locate.mjs", import.meta.url));
const SHARED_FONT_PATH = "/tmp/locate-font.ttf";

function hasDrawtext() {
const filters = spawnSync("ffmpeg", ["-hide_banner", "-filters"], { encoding: "utf8" });
return filters.status === 0 && /\bdrawtext\b/.test(filters.stdout);
}

function sharedFontState() {
const stat = lstatSync(SHARED_FONT_PATH, { throwIfNoEntry: false, bigint: true });
return stat ? `${stat.ino}:${stat.mtimeNs}` : null;
}

test(
"overlay draws its grids without reading or writing a font at a shared /tmp path",
{ skip: !hasDrawtext() && "ffmpeg without the drawtext filter" },
() => {
const dir = mkdtempSync(join(tmpdir(), "locate-test-"));
try {
const image = join(dir, "in.png");
execFileSync("ffmpeg", [
"-v",
"error",
"-f",
"lavfi",
"-i",
"color=c=gray:s=320x180",
"-frames:v",
"1",
image,
]);
const before = sharedFontState();
execFileSync(process.execPath, [LOCATE, "overlay", image, "--out", join(dir, "grid")], {
stdio: ["ignore", "ignore", "inherit"],
});
assert.ok(existsSync(join(dir, "grid", "gv.png")));
assert.ok(existsSync(join(dir, "grid", "gh.png")));
assert.equal(sharedFontState(), before);
} finally {
rmSync(dir, { recursive: true, force: true });
}
},
);
Loading