[cairo] Image surface pixel twiddling API

T Rowley tor at cs.brown.edu
Tue Mar 6 08:51:06 PST 2007


On 3/5/07 7:08 PM, Jeff Muizelaar wrote:
> On Mon, Mar 05, 2007 at 02:20:21PM -0600, T Rowley wrote:
>> We would like an API to obtain the particular channel of a pixel.  In 
>> our experiments we tried two different types of API.  The first was a 
>> set of macros that returned a particular channel from pixel word [1], 
>> the second were channel offset macros that could be used to index into a 
>> byte pointer.  For our use, the first approach of word accessors made 
>> for somewhat messier source code and generated code that was slightly 
>> slower for x86 though faster on PPC [3].
> 
> This is probably because x86 is better at byte addressing/operations.  If
> it's faster on PPC it will probably be faster on ARM which I imagine is a
> platform Mozilla will care about more in the future.

Yes, I'd expect that any architecture with a RISC lineage would probably 
  have a slight performance benefit with the word oriented code. 
However since x86 is what the vast majority of Mozilla/Firefox users run 
on, we tend to favor solutions that benefit that architecture as long as 
it doesn't overly hurt performance elsewhere.

> Personally, I think the word accessors are a 'cleaner' API. However, the
> offsets might be easier to use when writing byte oriented code. They might
> also be useful if the inkscape people want to convert their pixel munging
> routines to the same format as cairo's.

There's always the option of having both techniques provided, and 
letting the developer use whichever is most appropriate for their code.

> Well looking into this, I noticed that mozilla's macros for 255 division
> do not do any rounding, which is sort of wrong. e.g (1 * 254) is 0 with
> mozilla's code and should be 1.

Interesting, thanks.

-tor


More information about the cairo mailing list