Vote page: no visible auto zoom (preview jumped, 4x shook on cheap phones); up to 4k stream and a centre search at twice the detail instead
This commit is contained in:
+22
-14
@@ -40,20 +40,28 @@ export function makeRingScanner(opts = {}) {
|
||||
if (d) return d;
|
||||
}
|
||||
track = null;
|
||||
// phones held upright hand over a 1080x1920 stream
|
||||
const k = Math.min(1, WIDE / Math.max(sw, sh));
|
||||
wide.width = Math.round(sw * k); wide.height = Math.round(sh * k);
|
||||
// plain bilinear at 3x reduction skips pixels and keeps the noise
|
||||
wctx.imageSmoothingQuality = "high";
|
||||
wctx.drawImage(src, 0, 0, wide.width, wide.height);
|
||||
const cands = locate(grayOf(wctx.getImageData(0, 0, wide.width, wide.height)), { max: 5 });
|
||||
let last = null;
|
||||
for (const c of cands) {
|
||||
const d = readAt(src, sw, sh, { cx: (c.cx + 0.5) / k, cy: (c.cy + 0.5) / k, unit: c.r / CENTER / k, A: c.A.map((v) => v / k) }, now);
|
||||
if (d && d.token) return d;
|
||||
last = d || last;
|
||||
}
|
||||
return last || { token: null, found: cands.length };
|
||||
const r = search(src, sw, sh, now, 0, 0, sw, sh);
|
||||
if (r.token || r.found) return r;
|
||||
// nothing in the whole view: the back rows see a ring too small to find on the reduced copy. look at the
|
||||
// middle, where people aim, at twice the detail. same as zooming in, without moving the preview
|
||||
return search(src, sw, sh, now, sw / 4, sh / 4, sw / 2, sh / 2);
|
||||
},
|
||||
};
|
||||
|
||||
// finds discs in the region x0 y0 w h of the frame (on a copy of at most WIDE px), reads them at full resolution
|
||||
function search(src, sw, sh, now, x0, y0, w, h) {
|
||||
const k = Math.min(1, WIDE / Math.max(w, h));
|
||||
wide.width = Math.round(w * k); wide.height = Math.round(h * k);
|
||||
// plain bilinear at 3x reduction skips pixels and keeps the noise
|
||||
wctx.imageSmoothingQuality = "high";
|
||||
wctx.drawImage(src, x0, y0, w, h, 0, 0, wide.width, wide.height);
|
||||
const cands = locate(grayOf(wctx.getImageData(0, 0, wide.width, wide.height)), { max: 5 });
|
||||
let last = null;
|
||||
for (const c of cands) {
|
||||
const d = readAt(src, sw, sh, { cx: x0 + (c.cx + 0.5) / k, cy: y0 + (c.cy + 0.5) / k, unit: c.r / CENTER / k, A: c.A.map((v) => v / k) }, now);
|
||||
if (d && d.token) return d;
|
||||
last = d || last;
|
||||
}
|
||||
return last || { token: null, found: cands.length };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user