I have some images of static objects using per-pixel alpha (trees, rocks) for a background. In order to make them look a bit more natural, I want to create some kind of atmospheric fog, which means the farther away the object is, the more bluish tint it has.
I have the RGB color of a fog [108, 119, 135] (which appears to be a color of my image if it is totally far away) and I need to mix this color with my image somehow depending on the object's specified distance (which I'm mapping to percentage of fog).
If I had to mix solid colors, I'd just find the difference between the original color and 100% fog color, multiply this by the distance percentage, and subtract this from the original color. E.g. I have a value 208 in original red channel, and to make it 30% foggy I do
208-(208-108)*0.3 = 178.
But I have no clue how to do this with an image that has per-pixel alpha. Blitting original image and then fog color with solid transparency doesn't work because I'd get a square of color over my image instead of respecting the shape of the image's alpha.