I need to blend together about 1 million semi-transparent rectangles, while being able to manage transparency accuracy by increment of 1e-6.
Typically, if my 1 millions rectangle would be drawn on top of each other, I want to have a resulting alpha value for these pixels of exactly 1.0 (0.5 for 500 000 rectangles, and so on).
Using the cairo library, it would ideally look like:
const int NB_RECT = 1000000;
//[...]
cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
cairo_set_source_rgba(cr, 1.0, 0, 0, 1.0/NB_RECT);
for(int i = 0 ; i < NB_RECT ; i++) {
//[...]
cairo_rectangle(cr, x, y, w, h);
cairo_fill(cr);
}
// [...]
This does not work because below alpha~=0.01, the drawing commands seem to be simply discarded (probably due to the internal representation of colors inside cairo).
Could you suggest a drawing library that handle high precision transparency, or possible workaround?