pixels = {
let img;
if (photo === "Photo 1") img = await FileAttachment("photo1.jpg").image();
else if (photo === "Photo 2") img = await FileAttachment("photo2.jpg").image();
else img = await FileAttachment("photo3.jpg").image();
const
width = pixelsPerLine,
height = Math.floor(width * img.height / img.width),
hw = width / 2, hh = height / 2;
const ctx = DOM.context2d(width, height, 1);
ctx.drawImage(img, 0, 0, width, height);
const
{data: array} = ctx.getImageData(0, 0, width, height),
len = array.length / 4,
pixels = new Array(len);
for(let i = 0; i < len; i++) {
const
x = i % width * pixelSize.ratio - width * pixelSize.half,
y = Math.floor(i / width) * pixelSize.ratio - height * pixelSize.half,
ai = i * 4, r = array[ai], g = array[ai + 1], b = array[ai + 2],
index = r * 65536 + g * 256 + b,
xi = ((r - 128) - (x - hw)) / steps,
yi = (g - 128) / steps,
zi = ((b - 128) - (y - hh)) / steps;
pixels[i] = {
x, y,
r, g, b,
xi, yi, zi, index
};
}
return pixels;
invalidation.then(() => dispose());
}