matplotlib/matplotlib — pull request #1955 by Westacular (2013-04-27 22:20:56+00:00)
Title: Honouring the alpha attribute when creating composite images.

I noticed some problems with the drawing of Images onto axes. Specifically, when `option_image_nocomposite()` is False and a single composite image is created (which seems to be the default for most backends), the alpha attribute of the Image objects was being ignored in the compositing process.

I've fixed that by multiplying the alpha component of each pixel with the attribute of the image, if set, during the process of compositing/blending the images together.

I've set up a test for this, as well, but getting the correct results from it depends on the changes from #1868.

In the process of testing this, I discovered that for output formats other than PNG, the Cairo backend was entirely failing to render images. I fixed that issue, however, a problem still remains: the Cairo image blending algorithms assume that pixel values are premultiplied by their alpha components, which is not currently being done in the process of converting image buffers for use by Cairo. For non-opaque images where rgb values exceed the alpha value, the result can be pretty weird and psychedelic. I can take a crack at fixing this, but it's a more involved change, and given that previously images weren't working *at all* for Cairo, it's perhaps better saved for a separate pull request.