code: function prepareMask(mask) {
          var x, y,
              w = mask.width,
              data = mask.data,
              minX = mask.bounds.minX,
              maxX = mask.bounds.maxX,
              minY = mask.bounds.minY,
              maxY = mask.bounds.maxY,
              rw = maxX - minX + 3, // bounds size +1 px on each side (a "white" border)
              rh = maxY - minY + 3,
              result = new Uint8Array(rw * rh); // reduced mask (bounds size)
  
          // walk through inner values and copy only "black" points to the result mask
          for (y = minY; y < maxY + 1; y++)
              for (x = minX; x < maxX + 1; x++) {
                  if (data[y * w + x] === 1)
                      result[(y - minY + 1) * rw + (x - minX + 1)] = 1;
              }
  
          return {
              data: result,
              width: rw,
              height: rh,
              offset: { x: minX - 1, y: minY - 1 }
          };
      }
docs: Create a compressed mask with a "white" border (1px border with zero values) for the contour tracing
  @param {Object} mask: {Uint8Array} data, {int} width, {int} height, {Object} bounds
  @return {Object} border mask: {Uint8Array} data, {int} width, {int} height, {Object} offset