Correctly calculate layered transparencies

Take this structure of backgrounds for example, 1 being the closest element:
1. rgba(10,10,10, .5);
2. rgba(10,10,50, .1);
3. rgb(10,10,250);

We need to transform background 2 into a solid color before we transform background 1 into a solid colour.