[cairo] Image handling guidelines

Ian Britten britten at caris.com
Wed Aug 27 09:34:00 PDT 2008


Hi all,
I'm looking at trying to draw our image data (from our existing
framework) via Cairo, and had a couple of high-level questions
about image handling - Mostly related to alpha handling and
performance...

- It seems that Cairo only renders 24/32 bit RGB images, correct?
   I may be passed 1-bit, 8-bit, etc, images, so I guess I'll have
   to expand them to 24/32 bit, right?
   [ I have to do this with WX, but GTK has interfaces to draw
     palette-based images, which makes it simpler.  I just want
     to make sure I haven't missed something in Cairo. ]

- Other than the obvious difference of extra memory, is there
   any fundamental difference in performance between 24-bit and
   32-bit images?  For example, is the 24-bit just converted to
   32-bit internally (Extra copy?), or is there a separate
   (Optimal?) code path for images that have no alpha?

- Similarly, is there any performance penalty to using a 32-bit
   image when there is no alpha specified?  It would probably
   simplify my code if I just made everything 32-bit, but I
   wouldn't want to introduce a performance hit if handling
   solid images via separate 24-bit techniques was more optimal.

- We have several ways of specifying 'transparency' for images
   - Clip regions (Shaped images)
   - 32-bit image data (Alpha per pixel)
   - Images with a single alpha for the entire image
   - Masked colours (Specific colours that should be transparent)
   One way of dealing with all this (At my level) is to always
   make a 32-bit image, then set the alpha values for the relevant
   pixels to the appropriate value (Depending on which type of
   transparency was specified).
   This might be my simplest approach, but might be sub-optimal
   in terms of Cairo.  For example, maybe Cairo can make a 24-bit
   image partially transparent faster than it can process a 32-bit
   image?  (Just an example, but hopefully you get the idea)

Anyways, I'm just trying to get the groundwork right for my
image handling, any would appreciate any input/suggestions!
Many thanks!
Ian


More information about the cairo mailing list