I wrote a tool for this: https://github.com/igrmk/blec.
For your specific case you may use it this way
blec white deadbeef
Last ef
is the hex representation of an alpha channel. Or you may use it like this
blec white deadbe:0.75
Specifying the opacity as a decimal fraction.
Please note that the suggested formula Y = 255 - P * (255 - X)
is not quite accurate due to a gamma correction. More accurate one would be Y = (255^G * (1 - P) + X^G * P) ^ (1 / G)
where Y
— resulting RGB component value, X
— overlay RGB component value, P
— its opacity, G
— a value of a gamma. Most common value of a gamma is 2.2. The reason to include a gamma correction into the formula is to move components into linear space on calculating. Almost every RGB space that is used today interprets color components in a non-linear way in order to place more color information in 8 bits. Historically it was introduced to compensate a non-linearity of CRT displays.
Here is an example why a gamma correction is important for the blending. Let's take this red image

and this blue image

Let's take first one fully opaque and set an opacity of the second image equal to x-axis like this

Now let's blend them without a gamma correction (gamma = 1)

Let's enable a gamma correction and do the same (gamma = 2.2)

As you can see there is much more localized transition if we don't use a gamma correction. There are clearly darker colors in the center. If we use a gamma correction then the transition and the lightness become much more smooth.
Last gradient is built using a dithering.

The image contains pixels of just two colors but a probability of blue linearly increases from 0 in the left to 1 in the right. The result looks much closer to image with gamma = 2.2 in terms of lightness and transition colors. Try to look at it from a distance. And this is what you probably expect from blending two colors. We literally blend them by mixing like aquarelle in this example. So gamma is very important thing for blending especially when opacity is close to 0.5.
Let's finally compare the blending of opaque red and blue with alpha of 0.5 where the effect of a gamma correction is maximum.

First image does not use a gamma correction, the second one uses a gamma of 2.2, and the third one uses a dithering. As you can see the first one is very different to other two (If you don't see it, read the notes below). So I advise to always use a gamma correction. If you use any decent image editor then most probably you are safe and a gamma correction is enabled by default.
Note 1:
To compare a dithering to a blending you need to look at images at 100% scale so that every single pixel of the image occupies exactly one pixel of a screen. This is almost never the case if you use a mobile phone or a retina display. If you look at images at different scale probably you look at antialiased image. The antialiasing can lead to very inaccurate results because it doesn't use a gamma correction at the moment. I can confirm it for Chrome 83 on Android 10 and for the latest Safari on iOS 13. I guess it needs too much resources to do it right way. So it effectively decreases a gamma of a display to about 1.8 when you look at very contrast noisy images.
Note 2:
Not every display is calibrated well. If you feel like an image with gamma of 2.2 and an image with a dithering produce different colors I have a bad news for you. You can check a gamma of you monitor here http://web.mit.edu/jmorzins/www/gamma/adilger/gamma.html. However if you use a mobile device it is better to use an application because an antialiasing can lead to very inaccurate results.
Here is a code to get these pictures https://pastebin.com/fHYtWrMb.