[cairo] CAIRO_FORMAT_A1 image source color

Uli Schlachter psychon at znc.in
Sat Mar 29 11:48:55 PDT 2014


Hi,

On 28.03.2014 17:51, sthustfo wrote:
> Thanks for the clarification regarding the A1 and A8 formats. I did not
> notice this in the documentation. Further, when I run the sample program
> provided by you, the generated out.png is 1x2 image in complete black. I do
> not see the white pixel.

Oh, yay, bugs!

This was fixed in git half a year ago and will be gone with the next release:

http://cgit.freedesktop.org/cairo/commit/?id=0c2faf6621c4983e2ec2bea7c722a5cd3d89cc6d

> I would like to generate a white surface and then draw some text over it in
> black using pango layout api (pango_layout_set_text). And then make use the
> raw data of the surface, and not really interested in the png output. Is
> this possible using the cairo?

Sure, but why do you do this with A1 surfaces?

Anyway, attached is a quick example for this.

Uli

> On Fri, Mar 28, 2014 at 6:15 PM, Uli Schlachter <psychon at znc.in> wrote:
> 
>> Hi,
>>
>> On 28.03.2014 07:01, sthustfo wrote:
>>> I am using cairopango library to render text on monochrome image on
>> Ubuntu
>>> 13.10. Now before rendering text, I create a surface of type
>>> CAIRO_FORMAT_A1, create a cairo context and set the source to solid
>> white.
>>> However, the color of the image remains black even though I have set the
>>> color source to solid white. I want to render black color text on white
>>> background.
>>>
>>> surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 320, 280);
>>> cr = cairo_create (surface);
>>> cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
>>> cairo_paint (cr);
>>>
>>> cairo_surface_write_to_png (surface, filename);
>>>
>>> The saved PNG image always is black color. How do I achieve an image of
>>> solid white color for a monochrome image (CAIRO_FORMAT_A1)? If suppose,
>> the
>>> surface is created using CAIRO_FORMAT_ARGB32, then everyrhing is fine.
>>
>> Please note that CAIRO_FORMAT_A1 and CAIRO_FORMAT_A8 are *not* monochrome
>> images. They describe images without any colors at all which only contain
>> an
>> alpha channel. Only when generating a PNG are these images interpreted as
>> monochrome. The contents of the color components in your call to
>> cairo_set_source_rgba() won't make any difference at all.
>>
>> Also note that the default operator (CAIRO_OPERATOR_OVER) doesn't allow to
>> "remove transparency", it only ever is added.
>>
>> Attached is a program which generates a PNG with a white and a black
>> pixel. It
>> uses the operator "SOURCE" to set the alpha-value of the target pixel. I
>> hope
>> this can help you.
>>
>> Cheers,
>> Uli
>> --
>> No matter how much cats fight, there always seem to be plenty of kittens.
>>
> 


-- 
<alanc> I think someone had a Xprint version of glxgears at one point,
    but benchmarking how many GL pages you can print per second
    was deemed too silly to merge


More information about the cairo mailing list