Trying to detect source color after mixing it with another one.
What I have tried:
For example:
A R G B
source 255 128 64 64
overlay 204 0 128 128
result 255 26 115 115
After mixing source color with overlay (with normal blending mode), i get the result color.
Knowing, that source alpha and result alpha are constants, for calculating result color I use this formula:
result.red = source.red + (overlay.red - source.red) * overlay.alpha / 255;
respectively for the rest blue and green channels the same formula.
The first trouble I face, is that the result value is rounded, so instead of 25.6 (for result R), I will get 26 (because rgb are byte values).
So, this will cause the problem while detecting source color, knowing only result and overlay. So, using this formula:
source.red = (255 * result.red - overlay.red * overlay.alpha) / (255 - overlay.alpha)
will result source red value = 130 insted of 128 (because result red value is 26 insted of 25.6).
Any ideas how the source color can be calculated another way?