function replace_color_globally(image_data, from_r, from_g, from_b, from_a, to_r, to_g, to_b, to_a) {
	if (
		from_r === to_r &&
		from_g === to_g &&
		from_b === to_b &&
		from_a === to_a
	) {
		return;
	}
	const { data } = image_data;
	for (let i = 0; i < data.length; i += 4) {
		if (
			Math.abs(data[i + 0] - from_r) <= fill_threshold &&
			Math.abs(data[i + 1] - from_g) <= fill_threshold &&
			Math.abs(data[i + 2] - from_b) <= fill_threshold &&
			Math.abs(data[i + 3] - from_a) <= fill_threshold
		) {
			data[i + 0] = to_r;
			data[i + 1] = to_g;
			data[i + 2] = to_b;
			data[i + 3] = to_a;
		}
	}
}
Replaces a specific color globally in the given image data.

@param {ImageData} image_data - The image data to manipulate.
@param {number} from_r - The red component of the color to replace.
@param {number} from_g - The green component of the color to replace.
@param {number} from_b - The blue component of the color to replace.
@param {number} from_a - The alpha component of the color to replace.
@param {number} to_r - The red component of the new color.
@param {number} to_g - The green component of the new color.
@param {number} to_b - The blue component of the new color.
@param {number} to_a - The alpha component of the new color.