From e963f96de7f3db7629bb35f5cd84dcab43740677 Mon Sep 17 00:00:00 2001 From: wangzemei Date: Thu, 5 Sep 2024 16:04:25 +0800 Subject: [PATCH] + [task#127424] add findRegions function. --- lib/zin/wg/think3c/js/v1.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/zin/wg/think3c/js/v1.js b/lib/zin/wg/think3c/js/v1.js index 33dec1441c..7f606d0376 100644 --- a/lib/zin/wg/think3c/js/v1.js +++ b/lib/zin/wg/think3c/js/v1.js @@ -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; +}