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:
+14
-10
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user