+ [task#127424] add findRegions function.

This commit is contained in:
wangzemei
2024-09-05 16:39:53 +08:00
committed by 刘刚
parent 086de2bf5b
commit e963f96de7
+20
View File
@@ -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;
}