I'm writing a simple box blur for a graphics library. The formula makes the average of a range of pixels by adding the ARGB amounts and then dividing by the blur range
For example, with a blur range of 3;
pixel1 FF FF 00 00 + pixel2 FF 00 FF 00 + pixel3 FF 00 00 FF / 3 = result FF 55 55 55
Which is correct. A typical result shows as;
However, I am having difficulty with coming up with a formula to blur an image with alpha transparency. The formula above gives this result for a yellow box on a transparent background;
You can see that the yellow is surrounded by black colour - because the red and green are being diminished to 0. The result should actually look like so;
So; the formula of
(pixel + pixel + pixel) / range is not working for alpha-blended images.
Can anyone please give a correct formula?