Apologies for the unclear title, but it's a hard problem to explain. Essentially, I need a Typescript function which accepts two RGB values, both being of the same translucent colour, just with different backgrounds, one being white and the other being black. I understand this isn't a very good explanation, so I have an example.
Let's say you have a colour: rgba(255, 0, 0, 0.5). If you were to overlay black (rgb(0, 0, 0)) behind it, then pick the resulting colour, you'd get rgb(128, 0, 0). If you did the same for white, you'd get rgb(255, 127, 127). Ideally, you'd have some class, Color, with an R, G, B and A value, which this function accepts. So, in code, this would look like:
class Color {
constructor(public r: number, public g: number, public b: number, public a: number = 1) {}
}
const unknownColorWithBlackBg = new Color(128, 0, 0);
const unknownColorWithWhiteBg = new Color(255, 127, 127);
// calculateColor is the function which I am trying to write.
const result = calculateColor(unknownColorWithBlackBg, unknownColorWithWhiteBg);
console.log(result); // Color { R: 255, G: 0, B: 0, A: 0.5 }