<p>This depends on what function you're blending with. Since you don't say where you're doing this, I'll just take OpenGL as an example.</p>
<p>As you can see in the <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml" rel="nofollow noreferrer">API</a>, there are several ways of blending two colours (or rather how to interpret these two colours for a given blend function).</p>
<p>You speak of a colour and a background colour, so let's say your result is <span class="math-container">$c_r$</span>, your object in the foreground has colour <span class="math-container">$c_s$</span> (for Source, the new colour value being &quot;added&quot; someway) and your background has colour <span class="math-container">$c_d$</span> (for Destination, the old colour value that has been in the buffer already).</p>
<p>Let <span class="math-container">$c_s = \left(\begin{array}{c} R_s\\G_s\\B_s\\A_s \end{array}\right)$</span> (and analogously for <span class="math-container">$c_r$</span> and <span class="math-container">$c_d$</span>).</p>
<blockquote>
<p>To determine the blended RGBA values of a pixel, the system uses the following equations:
<span class="math-container">$R_d = min(k_{R'}, R_s s_R + R_d d_R) \ G_d = min(k_{G'}, G_s S_G + G_d d_G) \ B_d = min(k_{B'}, B_s s_B + B_d d_B) A_d = min(k_{A'}, A_s s_A + A_d d_A)$</span></p>
</blockquote>
<p>A bit confusing with the doubled <span class="math-container">$R_d$</span> and so forth, so I'll rewrite it to the denomination I defined earlier:</p>
<p><span class="math-container">$R_r = min(k_{R'}, R_s s_R + R_d d_R) \ G_r = min(k_{G'}, G_s S_G + G_d d_G) \ B_r = min(k_{B'}, B_s s_B + B_d d_B) A_r = min(k_{A'}, A_s s_A + A_d d_A)$</span></p>
<p>The min function is there for not going above a certain constant (and <span class="math-container">$k_{R'},\ k_{G'},\ k_{B'},\ k_{A'}$</span> are simply constants). For our purposes, let's just assume that we don't surpass this threshold, so we end up with</p>
<p><span class="math-container">$R_r = R_s s_R + R_d d_R$</span> (and of course the same for the other channels).</p>
<p>The rest of the components <span class="math-container">$s_R$</span> and <span class="math-container">$d_R$</span> which are some scaling factors for combining the two colours.</p>
<blockquote>
<p>Transparency is best implemented using blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest.</p>
</blockquote>
<p>This helps, because now we know what the factors <span class="math-container">$s_R$</span> and <span class="math-container">$d_R$</span> actually are: the alpha values of the <strong>Source</strong>.</p>
<p>This leaves us with</p>
<p><span class="math-container">$R_r = R_s A_s + (1 - R_d A_d)$</span></p>
<p>Therefore, to come back to your example, we have (for the green channel, since that is not <span class="math-container">$255$</span>):</p>
<p><span class="math-container">$G_r = 230$</span>, an undefined <span class="math-container">$\alpha$</span> value for the source, the background green <span class="math-container">$G_d = 255$</span> and probably a solid background, meaning <span class="math-container">$A_d = 255$</span>. We need the values to be in <span class="math-container">$\left[0, 1\right]$</span>, therefore we get <span class="math-container">$G_r = \frac{230}{255} = 0.90196078431$</span>, <span class="math-container">$G_d = 1$</span> and <span class="math-container">$A_d = 1$</span>.</p>
<p>Filling this in we get:</p>
<p><span class="math-container">$0.90196078431 = G_s A_s + (1 - 1 \cdot A_s)$</span></p>
<p>Your question lets me believe, that you know <span class="math-container">$A_s$</span>, thus only <span class="math-container">$G_s$</span> (and of course the same for the other colour channels) is missing. This can then be calculated by isolating the respective colour component.</p>

CC BY-SA 4.0
2018-11-08T12:53:16.813Z
It's worth mentioning that for some alphas and colour combinations, the colours may come out of the equation negative e.g. if you want to turn a pure red background into pure green, there's only a positive solution if $\alpha = 1$
Dan Hulme
CC BY-SA 4.0
2018-11-08T12:48:49.557Z
2018-11-08T12:48:49.557Z
2020-06-18T08:32:12.800Z
Tare
<p>Assume a color X with alpha 1 and RGB 255,230,210.</p>

<p>How can i find another color with alpha A ( or an array of colors ) that blended with a background of color Y ( e.g 255,255,255 ) would produce the original color  ?</p>

<color>
Converting color to equivalent with opacity
Return-1
# Converting color to equivalent with opacity

(Asked by: username_0 on 2018-11-08)

Assume a color X with alpha 1 and RGB 255,230,210.

How can i find another color with alpha A ( or an array of colors ) that blended with a background of color Y ( e.g 255,255,255 ) would produce the original color ?

**Tags:** color


---

## 1 answers

### Answer by username_1 on 2018-11-08. Score: 1 | Accepted answer

This depends on what function you're blending with. Since you don't say where you're doing this, I'll just take OpenGL as an example.

As you can see in the [API](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml), there are several ways of blending two colours (or rather how to interpret these two colours for a given blend function).

You speak of a colour and a background colour, so let's say your result is $c\_r$, your object in the foreground has colour $c\_s$ (for Source, the new colour value being "added" someway) and your background has colour $c\_d$ (for Destination, the old colour value that has been in the buffer already).

Let $c\_s = \left(\begin{array}{c} R\_s\\G\_s\\B\_s\\A\_s \end{array}\right)$ (and analogously for $c\_r$ and $c\_d$).

> To determine the blended RGBA values of a pixel, the system uses the following equations:
> $R\_d = min(k\_{R'}, R\_s s\_R + R\_d d\_R) \ G\_d = min(k\_{G'}, G\_s S\_G + G\_d d\_G) \ B\_d = min(k\_{B'}, B\_s s\_B + B\_d d\_B) A\_d = min(k\_{A'}, A\_s s\_A + A\_d d\_A)$

A bit confusing with the doubled $R\_d$ and so forth, so I'll rewrite it to the denomination I defined earlier:

$R\_r = min(k\_{R'}, R\_s s\_R + R\_d d\_R) \ G\_r = min(k\_{G'}, G\_s S\_G + G\_d d\_G) \ B\_r = min(k\_{B'}, B\_s s\_B + B\_d d\_B) A\_r = min(k\_{A'}, A\_s s\_A + A\_d d\_A)$

The min function is there for not going above a certain constant (and $k\_{R'},\ k\_{G'},\ k\_{B'},\ k\_{A'}$ are simply constants). For our purposes, let's just assume that we don't surpass this threshold, so we end up with

$R\_r = R\_s s\_R + R\_d d\_R$ (and of course the same for the other channels).

The rest of the components $s\_R$ and $d\_R$ which are some scaling factors for combining the two colours.

> Transparency is best implemented using blend function (GL\_SRC\_ALPHA, GL\_ONE\_MINUS\_SRC\_ALPHA) with primitives sorted from farthest to nearest.

This helps, because now we know what the factors $s\_R$ and $d\_R$ actually are: the alpha values of the **Source**.

This leaves us with

$R\_r = R\_s A\_s + (1 - R\_d A\_d)$

Therefore, to come back to your example, we have (for the green channel, since that is not $255$):

$G\_r = 230$, an undefined $\alpha$ value for the source, the background green $G\_d = 255$ and probably a solid background, meaning $A\_d = 255$. We need the values to be in $\left[0, 1\right]$, therefore we get $G\_r = \frac{230}{255} = 0.90196078431$, $G\_d = 1$ and $A\_d = 1$.

Filling this in we get:

$0.90196078431 = G\_s A\_s + (1 - 1 \cdot A\_s)$

Your question lets me believe, that you know $A\_s$, thus only $G\_s$ (and of course the same for the other colour channels) is missing. This can then be calculated by isolating the respective colour component.

> **Comments:**
> **username_2**: It's worth mentioning that for some alphas and colour combinations, the colours may come out of the equation negative e.g. if you want to turn a pure red background into pure green, there's only a positive solution if $\alpha = 1$  

---

