+ [task#127424] add findRegions function.
This commit is contained in:
@@ -128,3 +128,23 @@ function getRegionInfo(pixels, visited, x, y, width, height)
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
function findRegions(pixels, width, height)
|
||||
{
|
||||
const visited = {};
|
||||
const regions = [];
|
||||
for(let y = 0; y < height; y++)
|
||||
{
|
||||
for(let x = 0; x < width; x++)
|
||||
{
|
||||
const index = (y * width * 4) + (x * 4);
|
||||
if(pixels[index] === 255 && !visited[y + ',' + x])
|
||||
{
|
||||
const region = getRegionInfo(pixels, visited, x, y, width, height);
|
||||
regions.push(region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return regions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user