function replace_colors_with_swatch(ctx, swatch, x_offset_from_global_canvas = 0, y_offset_from_global_canvas = 0) {
	ctx.globalCompositeOperation = "source-in";
	ctx.fillStyle = swatch;
	ctx.beginPath();
	ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height);
	ctx.save();
	ctx.translate(-x_offset_from_global_canvas, -y_offset_from_global_canvas);
	ctx.fill();
	ctx.restore();
}
Replaces colors from a mask with a specified color or pattern.
This function is mainly for patterns support but naturally handles solid colors as well.

USAGE NOTE: Context MUST be untranslated! (for the rectangle to cover the exact area of the canvas, and presumably for the pattern alignment as well)

@param {CanvasRenderingContext2D} ctx - The canvas rendering context.
@param {string | CanvasPattern | CanvasGradient} swatch - The color swatch to replace the colors with.
@param {number} [x_offset_from_global_canvas=0] - The x-coordinate of the mask's top-left corner relative to the global canvas.
@param {number} [y_offset_from_global_canvas=0] - The y-coordinate of the mask's top-left corner relative to the global canvas.