(index)
| 93 | |
| 94 | const pixelCache = new Map(); |
| 95 | const normaliseSlice = (index) => { |
| 96 | if (pixelCache.has(index)) { |
| 97 | return pixelCache.get(index); |
| 98 | } |
| 99 | const start = index * sampleSize; |
| 100 | const slice = imageBytes.subarray(start, start + sampleSize); |
| 101 | const normalized = new Float32Array(sampleSize); |
| 102 | for (let i = 0; i < sampleSize; i += 1) { |
| 103 | normalized[i] = slice[i] / 255; |
| 104 | } |
| 105 | pixelCache.set(index, normalized); |
| 106 | return normalized; |
| 107 | }; |
| 108 | |
| 109 | return { |
| 110 | rows, |