title: Algorithm to convert semi-transparent to solid color
body: <p>Let's say I have the color rgba(255, 0, 0, 0.5) on a white background. The color that can bee seen is almost identical to rgba(255, 140, 140, 1) which is a solid color. I'm looking for an algorithm that converts a semi-transparent color (over white) to a solid color so that it looks (pretty much) the same when it's one near each other (like in the photo below)</p>
  
  <p><a href="https://i.stack.imgur.com/JHqOA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JHqOA.png" alt="Two rectangles with diferent colors that look the same on a white background"></a></p>
  
  <p>I noticed that if there are 2 components (r, g, or b) that are 0, then you have to keep the not-null component's value and adjust the null components by the same value so that it matches the wight color. This value (I guess) depends on the alpha component of semi-transparent color. But I can't seem to find the formula. How about the rest of the case? I think there must be a general formula that can be applied. </p>
  
  <p>I'm looking for an answer in pseudocode, javascript, Java, Python, C# or C++.</p>
  
  <p>Also, I am not working on any project. This question is for learning purposes and for helping people that might need this.  </p>