add sla .ctb format and a few related printer targets

This commit is contained in:
Stewart Allen 2026-05-15 16:53:58 -04:00
commit a1af70b496
11 changed files with 937 additions and 11 deletions

39
bin/ctb2rsla.mjs Executable file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env node
import fs from 'fs/promises';
import path from 'path';
import { CTB } from '../src/kiri/mode/sla/work/x_ctb.js';
let [,, input, output] = process.argv;
if (!input) {
console.error("usage: node bin/ctb2rsla.mjs input.ctb [output.rsla]");
process.exit(1);
}
output = output || input.replace(/\.ctb$/i, "") + ".rsla";
let data = await fs.readFile(input);
let ctb = CTB.read(data);
let { header, machine } = ctb;
let lastPercent = -1;
console.log([
"ctb",
machine || "unknown-machine",
`${header.resolutionX}x${header.resolutionY}`,
`${header.layerCount} layers`,
`${path.basename(output)}`
].join(" "));
let file = await CTB.toRSLA(data, (progress, message) => {
let percent = Math.floor(progress * 100);
if (percent !== lastPercent) {
lastPercent = percent;
process.stderr.write(`\r${message} ${percent}%`);
}
});
if (lastPercent >= 0) process.stderr.write("\n");
await fs.writeFile(output, Buffer.from(file));
console.log(`wrote ${output}`);