function createBorderForBlur(mask, radius, visited) {
    let x;
    let i;
    let j;
    let y;
    let k;
    let k1;
    let k2;
    const w = mask.width;
    const h = mask.height;
    const data = mask.data;
    const visitedData = new Uint8Array(data);
    const minX = mask.bounds.minX;
    const maxX = mask.bounds.maxX;
    const minY = mask.bounds.minY;
    const maxY = mask.bounds.maxY;
    let len = w * h;
    const temp = new Uint8Array(len); // auxiliary array to check uniqueness
    const border = []; // only border points
    const x0 = Math.max(minX, 1);
    const x1 = Math.min(maxX, w - 2);
    const y0 = Math.max(minY, 1);
    const y1 = Math.min(maxY, h - 2);

    if (visited && visited.length > 0) {
      // copy visited points (only "black")
      for (k = 0; k < len; k++) {
        if (visited[k] === 1) visitedData[k] = 1;
      }
    }

    // walk through inner values except points on the boundary of the image
    for (y = y0; y < y1 + 1; y++)
      for (x = x0; x < x1 + 1; x++) {
        k = y * w + x;
        if (data[k] === 0) continue; // "white" point isn't the border
        k1 = k + w; // y + 1
        k2 = k - w; // y - 1
        // check if any neighbor with a "white" color
        if (
          visitedData[k + 1] === 0 ||
          visitedData[k - 1] === 0 ||
          visitedData[k1] === 0 ||
          visitedData[k1 + 1] === 0 ||
          visitedData[k1 - 1] === 0 ||
          visitedData[k2] === 0 ||
          visitedData[k2 + 1] === 0 ||
          visitedData[k2 - 1] === 0
        ) {
          //if (visitedData[k + 1] + visitedData[k - 1] +
          //    visitedData[k1] + visitedData[k1 + 1] + visitedData[k1 - 1] +
          //    visitedData[k2] + visitedData[k2 + 1] + visitedData[k2 - 1] === 8) continue;
          border.push(k);
        }
      }

    // walk through points on the boundary of the image if necessary
    // if the "black" point is adjacent to the boundary of the image, it is a border point
    if (minX === 0) for (y = minY; y < maxY + 1; y++) if (data[y * w] === 1) border.push(y * w);

    if (maxX === w - 1) for (y = minY; y < maxY + 1; y++) if (data[y * w + maxX] === 1) border.push(y * w + maxX);

    if (minY === 0) for (x = minX; x < maxX + 1; x++) if (data[x] === 1) border.push(x);

    if (maxY === h - 1) for (x = minX; x < maxX + 1; x++) if (data[maxY * w + x] === 1) border.push(maxY * w + x);

    const result = []; // border points with radius-neighbors
    let start;
    let end;
    const endX = radius + w;
    const endY = radius + h;
    const n = radius * 2 + 1; // size of the pattern for radius-neighbors (from -r to +r with the center point)

    len = border.length;
    // walk through radius-neighbors of border points and add them to the result array
    for (j = 0; j < len; j++) {
      k = border[j]; // index of the border point
      temp[k] = 1; // mark border point
      result.push(k); // save the border point
      x = k % w; // calc x by index
      y = (k - x) / w; // calc y by index
      start = radius - x > 0 ? radius - x : 0;
      end = endX - x < n ? endX - x : n; // Math.min((((w - 1) - x) + radius) + 1, n);
      k1 = k - radius;
      // walk through x-neighbors
      for (i = start; i < end; i++) {
        k2 = k1 + i;
        if (temp[k2] === 0) {
          // check the uniqueness
          temp[k2] = 1;
          result.push(k2);
        }
      }
      start = radius - y > 0 ? radius - y : 0;
      end = endY - y < n ? endY - y : n; // Math.min((((h - 1) - y) + radius) + 1, n);
      k1 = k - radius * w;
      // walk through y-neighbors
      for (i = start; i < end; i++) {
        k2 = k1 + i * w;
        if (temp[k2] === 0) {
          // check the uniqueness
          temp[k2] = 1;
          result.push(k2);
        }
      }
    }

    return result;
  }
Create a border index array of boundary points of the mask with radius-neighbors
@param {Object} mask: {Uint8Array} data, {int} width, {int} height, {Object} bounds
@param {int} blur radius
@param {Uint8Array} visited: mask of visited points (optional)
@return {Array} border index array of boundary points with radius-neighbors (only points need for blur)