android-cairo icon indicating copy to clipboard operation
android-cairo copied to clipboard

Endianness issues on ARM

Open esaule opened this issue 12 years ago • 2 comments

Hi, nice of you to have packaged cairo for android: I love it.

I am experiencing issues with cairo on an arm processor based machine. When the window format is 32 bit on android, the cairo library appears to generate the frame with the wrong format. It appears to use BGRA instead of RGBA. I am not sure whether I did something wrong at compile time (like forgot to pass a compatibility flag somewhere). Anyway, the bits can be swizzled manually after cairo did his rendering using at the end of the draw_frame function. It would be nice if cairo was supporting more pixel formats. All comments are welcomed!

if _BYTE_ORDER == _LITTLE_ENDIAN

if (buffer->format == WINDOW_FORMAT_RGBA_8888 || buffer->format == WINDOW_FORMAT_RGBX_8888 ) { for (char * p = (char_)buffer->bits; p != (char_)buffer->bits+(4_buffer->stride_buffer->height); p+=4) { char x = p[0]; p[0] = p[2]; p[2] = x; } }

endif

esaule avatar Dec 02 '12 08:12 esaule

I'm not the owner of this project, but you should write this problem to Cairo ML. Here is a wrong place. By the way, answering to your question, you should use Pixman. See PIXMAN_b8g8r8a8.

yukoba avatar Dec 05 '12 10:12 yukoba

This is not a cairo problem! Cairo define its RGBA and RGBX format based on high bits and low bits. So it depends on endianness. Multiple posts on cairo MLs indicates that they are aware of the endianness problem and that it is what they want (in brief it allows them to keep the code simple.)

Editing the pure_ndk example on android-cairo would certainly be usefull https://github.com/anoek/android-cairo/blob/master/examples/pure-ndk/jni/pure-ndk.c

esaule avatar Dec 06 '12 14:12 esaule