[cairo] Cairo + GdkPixbuf

Bill Spitzak spitzak at gmail.com
Wed Jun 30 12:18:52 PDT 2010

 >> Yes, RGBA is the obvious choice of people new to image formats, because
 >> it's how people think of pixels. Which is why it shows up in every
 >> project that needs graphics but has inexperienced developers (like Gtk1,
 >> HTML5 canvas or the PNG specification).
 > Can you explain how experience moves one to favour premultiplied
 > alphas?

I think it was the byte order that was being talked about, not 
premultiplication. For a beginner working with an array of bytes it 
seems obvious to lay out the bytes in the order RGBA.

However being able to treat a color as a single integer is certainly 
useful and (especially in compilers at that time) vastly faster than any 
structure or array of bytes. If users are going to type in numbers it is 
fairly obvious to lay out the bits so when it is written in hex it is 
readable as 0xRRGGBB. Alpha was introduced later and was therefore put 
in the top 8 bits to be compatible (if alpha was popular originally it 
probably would have been put in the low 8 bits).

On a little-endian machine this results in the byte layout BGRA, and on 
a big-endian machine this ends up as ARGB, neither matches the obvious 
layout of RGBA.

Windows did this (and so did many other people) and because of this all 
graphics hardware was designed so that this layout was the fastest (or 
only) method of storing an image. I think we have to live with the 
results and use this as the image format, and I certainly still like the 
ability to treat 24 and 32 bit pixels as an unsigned value.

As for premultiplication, all the Porter-Duff compositing operations are 
much easier to describe mathmatically premultiplied. In fact Cairo's 
documentation could be improved and simplified by changing all the math 
to premultiplied form, I don't know why it is written the way it is.

Non-premultiplied means that renderers have to treat objects over the 
empty background in a totally different way than one object overlapping 
another. This is quite impractical and no renderers I know of work with 
non-premultiplied images (though they might unpremultiply the final 
output). Premultiplied means that a renderer can treat the empty area as 
another object that is transparent black.

Ian Britten wrote:
> On 26/06/10 07:22 AM, Benjamin Otte wrote:
>>> The fact that Cairo cannot understand non-premultiplied RGBA which is
>>> used in GdkPixbuf is somewhat inconvenient.
  When starting to integrate Cairo into our stuff, I found myself
> having to write shim code to convert various pixel representations
> to Cairo's format and back again, and have often wondered about
> the reason/benefit.
> eg: One thing I hate is how if you have a real RGB value and drop
> the Alpha to zero and premultiply it, then you can never get the
> original RGB value back.  You only ever get black back ...  :P
> Many thanks for any info, pointers, etc!
> Ian
> -- 
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo

More information about the cairo mailing list