Commit b1787d42 authored by Matija Obreza's avatar Matija Obreza
Browse files

Outline: record all startAts and skip if already processed

- WIP
parent 78f9553b
......@@ -693,6 +693,7 @@ export function filterOutline(image) {
}
for (let color = 0; color < 1; color++) {
const allStartAts = new Array();
// Scanning by row, left to right
// 1. Find a non-emtpy pixel
// 2. Find next pixel:
......@@ -701,13 +702,17 @@ export function filterOutline(image) {
let shapes = 0;
let startAt = findNext(0, 0, color);
do {
if (startAt) {
if (startAt && allStartAts.find((oldStart) => oldStart[0] === startAt[0] && oldStart[1] === startAt[1]) !== null) {
allStartAts.push(startAt);
let x = startAt[0];
let y = startAt[1];
let d = 0; // initial direction is east 'ea' at 0
let go = true;
dataR[P(x, y, color)] = 255; // mark
dataR[P(x, y, 1)] = 0; // unmark
let safety = 0;
let lineLength = 0;
for (; go && y >= 0 && y < h;) {
for (; go && x >= 0 && x < w;) {
go = false;
......@@ -727,6 +732,7 @@ export function filterOutline(image) {
dataR[P(x, y, color)] = 255; // mark
dataR[P(x, y, 3)] = 255; // full alpha
}
lineLength++;
go = true;
break; // break new direction checking
}
......@@ -737,27 +743,31 @@ export function filterOutline(image) {
dataR[P(x, y, color)] = 0; // unmark
dataR[P(x, y, 3)] = 0; // no alpha
d = (4 + d) % 8; // reverse
lineLength--;
go = true;
continue;
}
// back at start?
if (x === startAt[0] && y === startAt[1]) {
// console.log('Back at start pixel!');
console.log(`Back at start pixel! ${lineLength}`);
dataR[P(x, y, color)] = 255; // mark
dataR[P(x, y, 3)] = 255; // full alpha
// TODO fill the outline or clear the src data
shapes++;
floodFill(dataR, w, h, x, y, color);
if (lineLength > 4) {
// fill the outline or clear the src data
shapes++;
// if (shapes === 1) {
floodFill(dataR, w, h, x, y, color, 200);
}
go = false;
break;
}
// break;
if (safety++ > 1000) {
if (safety++ > 100000) {
break;
}
// break;
}
if (safety++ > 1000) {
if (safety++ > 100000) {
break;
}
// no next pixel found. End of trail.
......@@ -766,21 +776,23 @@ export function filterOutline(image) {
// find next shape
safety = 0;
startAt = undefined;
if (shapes < 2) {
if (shapes < 100) {
startAt = findNext(x + 1, y, color);
if (startAt) {
x = startAt[0];
y = startAt[1];
console.log('Next start at', x, y);
dataR[P(x, y, 1)] = 255; // mark
} else {
console.log('No start found');
}
}
startAt = undefined;
// startAt = undefined;
} else {
console.log('No start found');
}
} while (startAt); // repeat while shapes are found
} while (shapes < 10 && startAt); // repeat while shapes are found
}
const result = new ImageData(dataR, w, h);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment