(ctx, src, x, y, w, h, color)
| 3643 | } |
| 3644 | |
| 3645 | function drawOledThresholdedImage(ctx, src, x, y, w, h, color) { |
| 3646 | const img = getCachedOledImage(src); |
| 3647 | if (!img || !img.complete || !img.naturalWidth) return; |
| 3648 | const W = Math.max(1, Math.floor(w)); |
| 3649 | const H = Math.max(1, Math.floor(h)); |
| 3650 | imgCanvas.width = W; |
| 3651 | imgCanvas.height = H; |
| 3652 | imgCtx.clearRect(0, 0, W, H); |
| 3653 | imgCtx.imageSmoothingEnabled = false; |
| 3654 | imgCtx.drawImage(img, 0, 0, W, H); |
| 3655 | let data = null; |
| 3656 | try { |
| 3657 | data = imgCtx.getImageData(0, 0, W, H).data; |
| 3658 | } catch (e) { |
| 3659 | // Likely a CORS/file:// tainted canvas. Fallback: draw pixelated image without thresholding. |
| 3660 | try { |
| 3661 | ctx.imageSmoothingEnabled = false; |
| 3662 | ctx.drawImage(img, x, y, W, H); |
| 3663 | return; |
| 3664 | } catch (_) { |
| 3665 | return; |
| 3666 | } |
| 3667 | } |
| 3668 | ctx.fillStyle = color; |
| 3669 | for (let j = 0; j < H; j++) { |
| 3670 | for (let i = 0; i < W; i++) { |
| 3671 | const idx = (j * W + i) * 4; |
| 3672 | const a = data[idx + 3]; |
| 3673 | if (a < 50) continue; |
| 3674 | const r = data[idx], g = data[idx + 1], b = data[idx + 2]; |
| 3675 | const lum = (0.299 * r + 0.587 * g + 0.114 * b); |
| 3676 | if (lum > 80) ctx.fillRect(x + i, y + j, 1, 1); |
| 3677 | } |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | function renderElements() { |
| 3682 | const scale = parseFloat(preview.dataset.scale || "1"); |
nothing calls this directly
no test coverage detected