[cairo] Component-alpha in compositing operations.

Bill Spitzak spitzak at d2.com
Fri Oct 20 12:51:03 PDT 2006

jose_ogp at juno.com wrote:

> 	One fairly common operation that one seems to find in gui
> effects is to 'modulate' an image with some given color prior to
> blending with a destination.. ie. one wants to multiply the image
> channels by the given color's channels, and composite this result.

This does come up, mostly because GDI32 supports it.

One solution for Cairo is to replace "source" in the cairo equation with 
"source*color". The "source" is a surface, and a special solid-1 surface 
is provided. The source is always multiplied by the current color. The 
changes to the Cairo api would be to make the current API for setting 
the color set the source to 1, and setting the source sets the color to 
1, and add a new API to set the color without resetting the source. I'm 
not sure if gradients should be yet a third item that is mulitiplied, or 
should replace the color.

Alternative solution, which I think is what you are proposing, is to 
allow the clip to have a color. In fact the clip could be a full 4-color 
image. Each channel of output is set to

   ((source IN mask) OP dest) * C + dest * (1-C)

where C is the given channel of the clip image.

In this second case the changes to the API would be to be able to 
multiply the current clip by an image. One way would be to add a new 
compositing mode which changes the clip rather than the destination by 
doing clip = clip*(source IN mask). No operation other than multiply is 
allowed because the clip can only get smaller.

This second idea seems much more powerful and cleaner. It would also 
allow the grayed-out effect being talked about in other email. It's main 
problem is that I doubt it resembles how clip is implemented right now, 
and it is somewhat less intuitive to use.

Other email talks about per-channel alpha. This is NOT that, because, 
fortunately, only multiplication by the clip is done, and only 4 
channels need be stored for the clip. Per-channel alpha would mean the 
source and/or mask can have 6 channels instead of 4, one alpha for each 
color. In this case the OP would use each channel's alpha independently 
to produce each output color. The clip would probably need 6 channels as 
well if the above operation is supported. As far as I know, hardware 
support for per-channel alpha is almost non-existent, while the 
4-channel clip could be supported.

More information about the cairo mailing list