(imageData, blockSize)
| 205 | } |
| 206 | |
| 207 | function extractBlockGridNearest(imageData, blockSize) { |
| 208 | const { width, height } = imageData; |
| 209 | const d = imageData.data; |
| 210 | const cols = Math.ceil(width / blockSize); |
| 211 | const rows = Math.ceil(height / blockSize); |
| 212 | const grid = []; |
| 213 | |
| 214 | for (let row = 0; row < rows; row++) { |
| 215 | grid[row] = []; |
| 216 | for (let col = 0; col < cols; col++) { |
| 217 | const x0 = col * blockSize, y0 = row * blockSize; |
| 218 | const cx = Math.min(x0 + Math.floor(blockSize / 2), width - 1); |
| 219 | const cy = Math.min(y0 + Math.floor(blockSize / 2), height - 1); |
| 220 | const idx = (cy * width + cx) * 4; |
| 221 | grid[row][col] = [d[idx], d[idx + 1], d[idx + 2]]; |
| 222 | } |
| 223 | } |
| 224 | return { grid, cols, rows }; |
| 225 | } |
| 226 | |
| 227 | function paintBlockGrid(grid, rows, cols, imageData, blockSize) { |
| 228 | const { width, height } = imageData; |
no outgoing calls
no test coverage detected