Repeating alpha over/under operation multiple times I have two RGBA colors in linear [0..1] space, src and dst and I want to alpha blender src over/under dst n times. Of course, I could call the respective operation n times using the result from the previous one (which is what I am currently doing), but I want to optimize it into a single operation. I think just calculating the correct alpha on src should be sufficient, but I may be wrong. Here's what I currently use:

public static final Color alphaOver(Color dst, Color src) {
    float src1A = 1 - src.a;
    float outA = src.a + dst.a * src1A;

    if (outA == 0)
        return Color.TRANSPARENT;
    return new Color(
            outA,
            (src.r * src.a + dst.r * dst.a * src1A) / outA,
            (src.g * src.a + dst.g * dst.a * src1A) / outA,
            (src.b * src.a + dst.b * dst.a * src1A) / outA);
}

public static final Color alphaUnder(Color dst, Color src) {
    return alphaOver(src, dst);
}

public static final Color alphaOver(Color dst, Color src, int times) {
    Color ret = dst;
    for (int i = 0; i &lt; times; i++)
        ret = alphaOver(ret, src);
    return ret;
}

public static final Color alphaUnder(Color dst, Color src, int times) {
    Color ret = dst;
    for (int i = 0; i &lt; times; i++)
        ret = alphaUnder(ret, src);
    return ret;
}


How can I optimize the last two functions?
So taking source over as an example, the math works out to:


  dst = a * src + (1 - a) * dst


Taking Nathan Reed's suggestion of replacing (1 - a) with b, that gives us:


  dst = a * src + b * dst


If we perform the next iteration, it becomes:


  dst = a * src + ab * src + b^2 * dst


Doing it again, we get:


  dst = a * src + ab * src + ab^2 * src + b^3 * dst


And then:


  dst = a * src + ab * src + ab^2 * src + ab^3 * src + b^4 * dst


The pattern appears to be:

int exponent;
for (exponent = 0; exponent &lt; numIterations; exponent++)
{
    newDst += a * pow(b, exponent) * src;
}
newDst += pow(b, exponent) * dst;