[cairo] Direct manipulation and write to PNG

Andrea Canciani ranma42 at gmail.com
Mon Jul 9 13:25:36 PDT 2012


On Mon, Jul 9, 2012 at 10:19 PM, Carlos López González
<genetita at gmail.com> wrote:
> Hi!
>
>>
>> The issue was simply that you were assuming a different byte order
>> than the one used on your machine.
>> To avoid having these issues, always access whole pixels.
>
> Can you be a little more explicit there ^^?
> I don't imagine other way than access the data directly by pixel channels.

Instead of accessing a single channel, access a whole pixel, which in
your case is a 32-bits value.
Each channel is then accessible as specified in the format description.

For a code example, see the difference between the code I wrote and yours.
In your code you are accessing each channel independently.
Instead, in the code I wrote, each channel is provided as part of a
32-bit value, independent of the byte order.

Basically, whenever you're doing pointer arithmetic to access a
channel in a pixel, you're probably doing it wrong (well, it might be
ok on your architecture, but the code is going to be
endian-dependent).
Use pointer arithmetic to get the pixel value and shift/masking to
access channels.

>
>> Some documentation about pixel formats can be found here:
>> http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t
>> As you can see, ARGB32 is a 32-bits format stored native-endian.
>>
>> I hope this helps, but don't hesitate to ask for more clarification if
>> it is not sufficient.
>>
>> Andrea
>>
>
> Thanks to you too!
>
> --
> Carlos
> http://synfig.org


More information about the cairo mailing list