[cairo] render in grayscale

Behdad Esfahbod behdad at behdad.org
Tue Sep 22 11:30:57 PDT 2009


On 09/22/2009 02:01 PM, Per Hermansson wrote:
> Behdad Esfahbod wrote:
>> On 09/22/2009 01:00 PM, Bill Spitzak wrote:
>>> I think the original poster wants to render not the alpha, but something
>>> like (r+g+b)/3 of the image as grayscale.
>>
>> That's exactly what the solution Kalle and I proposed does. Though,
>> one typically wants a non-uniform combination of rgb for grayscale,
>> with green getting a larger multiplier.
>>
>> behdad
>
> So if I understand correctly rendering with the alpha surface as mask
> should work to get all colors replaced with different gray values?

That part works, yes.


> After I applied the suggested changes, with the following code:
> cairo_set_source_rgb(cr, 0, 0, 0);
> pattern = cairo_pattern_create_for_surface(target);
> cairo_mask(cr, pattern);
>
> I only get a white background with a filled black rectangle, how is the
> transparency supposed to work?

I think what's happening here is that poppler is drawing everything with full 
transparency (and clear the background?) so the mask is all opaque.

I was wrong.

I think we need to do instead:

   1) render to a RGB24 surface

   2) render that to an A8 surface

   3) use the A8 surface as a mask

So, another step needs to be added.

behdad

behdad


> Per



More information about the cairo mailing list