function renderDownsampledImage(context, rgba_data, w, h) {
for (let row = 0; row < h / tile_size; row++) {
for (let col = 0; col < w / tile_size; col++) {
context.save()
context.translate(col * tile_size, row * tile_size)
const index = (row * tile_size * w + col * tile_size) * 4
const r = average(rgba_data, row, col, 0)
const g = average(rgba_data, row, col, 1)
const b = average(rgba_data, row, col, 2)
if (monochrome[0] === "Gray") {
const gray = Math.floor((0.299 * r / 255 + 0.587 * g / 255 + 0.114 * b / 255) * 255)
drawTile(context, gray, gray, gray)
}
else {
drawTile(context, r, g, b)
}
context.restore()
}
}
}