This commit is contained in:
2026-11-16 19:32:44 +01:00
parent 0d0f84485a
commit 86ec6adb6b
5 changed files with 30 additions and 20 deletions
+6 -5
View File
@@ -1,4 +1,6 @@
import { decodeFrame, grayOf } from "/static/js/ringcode.js";
import { makeRingScanner } from "/static/js/ringscan.js";
const rings = makeRingScanner();
const $ = (id) => document.getElementById(id);
const video = $("v"), canvas = document.createElement("canvas"), ctx = canvas.getContext("2d", { willReadFrequently: true });
@@ -26,15 +28,14 @@ async function start() {
async function loop() {
if (!running) return;
if (video.readyState >= 2) {
// 960 px is plenty for the locator and keeps capture cheap on low-end phones
// the qr reference reads a 960 px copy, the rings read their own crop of the full frame
const k = Math.min(1, 960 / video.videoWidth);
canvas.width = Math.round(video.videoWidth * k);
canvas.height = Math.round(video.videoHeight * k);
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
frames++; fpsN++;
const img = grayOf(ctx.getImageData(0, 0, canvas.width, canvas.height));
const d = decodeFrame(img);
if (d.found) qr++;
const d = rings.scan(video, video.videoWidth, video.videoHeight);
if (d.cand) qr++;
if (d.token) { ring++; mode = "anneaux"; tokens.add(d.token); }
else if (mode !== "anneaux") {
// reference mode: the classic rotating qr