"use strict"; const { describe, it } = require("node:test"); const assert = require("node:assert/strict"); const DepthDecode = require("../src/ppda/depthDecode.js"); describe("DepthDecode encodings", () => { it("gray 8/16 roundtrip via encode/decode value", () => { for (const bits of [8, 16]) { const fmt = DepthDecode.parseFormat("gray", bits); for (const t of [0, 0.25, 0.5, 1]) { const enc = DepthDecode.encodeValue(fmt, t); const back = DepthDecode.decodeValue(fmt, enc[0], enc[1], enc[2]); assert.ok(Math.abs(back - t) < 2e-2, "gray" + bits + " t=" + t); } } }); it("rgb_bands fills R then G then B", () => { const fmt = DepthDecode.parseFormat("rgb_bands", 8); const mid = DepthDecode.encodeValue(fmt, 0.5); assert.equal(mid[0], 255); assert.ok(mid[1] > 0); const pix = DepthDecode.decodePixelChannels(fmt, [255, 100, 0, 255]); assert.ok(pix.gray > 0 && pix.alpha === 65535); }); it("rgb_bands rejects invalid order", () => { const fmt = DepthDecode.parseFormat("rgb_bands", 8); assert.throws(() => DepthDecode.decodePixelChannels(fmt, [100, 1, 0, 255])); }); it("rgb_packed positional", () => { const fmt = DepthDecode.parseFormat("rgb_packed", 8); const enc = DepthDecode.encodeValue(fmt, 0.5); const back = DepthDecode.decodeValue(fmt, enc[0], enc[1], enc[2]); assert.ok(Math.abs(back - 0.5) < 2e-2); }); it("distanceMeters uses near/far", () => { assert.equal(DepthDecode.distanceMeters(0, 1, 3), 1); assert.equal(DepthDecode.distanceMeters(65535, 1, 3), 3); }); });