Scanner: gpu canvases (cpu ones copied whole frames in software), back to 1080p with a 720p fallback on slow phones; lab frame save works on android

This commit is contained in:
2026-11-17 14:06:03 +01:00
parent 7765f22f61
commit 70d09b1008
5 changed files with 35 additions and 17 deletions
+1
View File
@@ -12,3 +12,4 @@ html, body { margin: 0; height: 100%; background: #f5f6fa; color: #1c2036; font:
button { font: 600 16px system-ui; padding: 12px 18px; border-radius: 99px; border: 0; background: #ffcc00; color: #1c2036; width: 100%; margin-top: 8px; }
button.ghost { background: #fff; }
.hist { font-size: 14px; color: #4a4f66; }
#shot { width: 100%; border-radius: 12px; margin-top: 12px; }
+1
View File
@@ -20,4 +20,5 @@
<button id="snap" class="ghost">Enregistrer l'image vidéo</button>
<button id="again" class="ghost">Nouvel essai</button>
<p class="hist" id="hist"></p>
<img id="shot" alt="Image vidéo enregistrée" hidden>
</main></body></html>
+14 -10
View File
@@ -3,7 +3,7 @@ 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 });
const video = $("v"), canvas = document.createElement("canvas"), ctx = canvas.getContext("2d");
let engine, running = false, frames = 0, qr = 0, ring = 0, t0 = 0, fpsT = performance.now(), fpsN = 0;
let tokens = new Set(), mode = "aucun", msAvg = 0;
const history = [];
@@ -17,7 +17,7 @@ async function start() {
engine = await QrScanner.createQrEngine();
// same request as the vote page, so what this page measures is what voters get
const stream = await navigator.mediaDevices.getUserMedia({
video: { facingMode: { ideal: "environment" }, width: { ideal: 3840 }, height: { ideal: 2160 } },
video: { facingMode: { ideal: "environment" }, width: { ideal: 1920 }, height: { ideal: 1080 } },
});
const set = stream.getVideoTracks()[0].getSettings();
$("res").textContent = `${set.width}×${set.height} ${set.frameRate ? Math.round(set.frameRate) + " i/s" : ""}`;
@@ -69,17 +69,21 @@ async function loop() {
$("go").addEventListener("click", () => start().catch((e) => { $("state").textContent = `Caméra : ${e.message}`; }));
$("again").addEventListener("click", reset);
// one raw frame of the stream as the decoder sees it, to send back when a phone can't read the ring
// one raw frame of the stream as the decoder sees it, to send back when a phone can't read the ring.
// built and clicked in the same tap: android drops a download started after an async step (toBlob)
$("snap").addEventListener("click", () => {
if (!video.videoWidth) return;
const c = document.createElement("canvas");
c.width = video.videoWidth; c.height = video.videoHeight;
c.getContext("2d").drawImage(video, 0, 0);
c.toBlob((b) => {
const a = document.createElement("a");
a.href = URL.createObjectURL(b);
a.download = `rotatyvote-frame-${video.videoWidth}x${video.videoHeight}-${Date.now()}.png`;
a.click();
setTimeout(() => URL.revokeObjectURL(a.href), 5000);
}, "image/png");
const url = c.toDataURL("image/jpeg", 0.95);
const a = document.createElement("a");
a.href = url;
a.download = `rotatyvote-frame-${video.videoWidth}x${video.videoHeight}-${Date.now()}.jpg`;
document.body.append(a);
a.click();
a.remove();
// fallback: long press the picture to save it
$("shot").src = url;
$("shot").hidden = false;
});