MCPcopy Create free account
hub / github.com/32comic/image2pixel-web / extractBlockGridNearest

Function extractBlockGridNearest

web/js/algorithms.js:207–225  ·  view source on GitHub ↗
(imageData, blockSize)

Source from the content-addressed store, hash-verified

205}
206
207function 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
227function paintBlockGrid(grid, rows, cols, imageData, blockSize) {
228 const { width, height } = imageData;

Callers 2

processWithTezumieFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected