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

Method analyzeScanline

pixelizer.js:313–348  ·  view source on GitHub ↗
(data, width, height, pos, isHorizontal)

Source from the content-addressed store, hash-verified

311 }
312
313 analyzeScanline(data, width, height, pos, isHorizontal) {
314 const segments = [];
315 let currentColor = null;
316 let currentLength = 0;
317
318 const length = isHorizontal ? width : height;
319
320 for (let i = 0; i < length; i++) {
321 const pixelIndex = isHorizontal
322 ? (pos * width + i) * 4
323 : (i * width + pos) * 4;
324
325 const r = data[pixelIndex];
326 const g = data[pixelIndex + 1];
327 const b = data[pixelIndex + 2];
328 const a = data[pixelIndex + 3];
329
330 const colorKey = `${r},${g},${b},${a}`;
331
332 if (colorKey === currentColor) {
333 currentLength++;
334 } else {
335 if (currentLength > 0) {
336 segments.push(currentLength);
337 }
338 currentColor = colorKey;
339 currentLength = 1;
340 }
341 }
342
343 if (currentLength > 0) {
344 segments.push(currentLength);
345 }
346
347 return segments;
348 }
349
350 calculateSizeStatistics(sizes) {
351 if (sizes.length === 0) return { mode: 1, gcd: 1, variance: 0 };

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected