function renderImageWithSquare(
rgbMatrix,
squareSize,
startRow,
startCol,
w = 512,
h = 512,
canvasId = "canvas"
) {
const canvas = html`<canvas style="height: ${h}px; width: ${w}px"/>`;
const ctx = canvas.getContext("2d");
const height = rgbMatrix.length;
const width = rgbMatrix[0].length;
canvas.width = width;
canvas.height = height;
const imageData = ctx.createImageData(width, height);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const pixelIndex = (y * width + x) * 4;
const [r, g, b] = rgbMatrix[y][x];
imageData.data[pixelIndex] = r;
imageData.data[pixelIndex + 1] = g;
imageData.data[pixelIndex + 2] = b;
imageData.data[pixelIndex + 3] = 255 * 0.75;
}
}
ctx.putImageData(imageData, 0, 0);
ctx.strokeStyle = "white";
ctx.lineWidth = 3;
ctx.strokeRect(startCol, startRow, squareSize, squareSize);
return canvas;
}