MCPcopy
hub / github.com/Leonxlnx/taste-skill / removeOuterBackground

Function removeOuterBackground

scripts/process-readme-buttons.mjs:21–52  ·  view source on GitHub ↗
(rgba, width, height)

Source from the content-addressed store, hash-verified

19}
20
21function removeOuterBackground(rgba, width, height) {
22 const visited = new Uint8Array(width * height);
23 const queue = [];
24
25 for (let x = 0; x < width; x++) {
26 queue.push(x, 0, x, height - 1);
27 }
28 for (let y = 1; y < height - 1; y++) {
29 queue.push(0, y, width - 1, y);
30 }
31
32 while (queue.length) {
33 const y = queue.pop();
34 const x = queue.pop();
35 const idx = y * width + x;
36 if (x < 0 || y < 0 || x >= width || y >= height || visited[idx]) continue;
37
38 const i = idx * 4;
39 const r = rgba[i];
40 const g = rgba[i + 1];
41 const b = rgba[i + 2];
42 const a = rgba[i + 3];
43 if (!isBackground(r, g, b, a)) continue;
44
45 visited[idx] = 1;
46 rgba[i + 3] = 0;
47
48 queue.push(x + 1, y, x - 1, y, x, y + 1, x, y - 1);
49 }
50
51 return rgba;
52}
53
54function getBounds(rgba, width, height) {
55 let minX = width;

Callers 1

processOneFunction · 0.70

Calls 1

isBackgroundFunction · 0.70

Tested by

no test coverage detected