Wrong colors on big endian systems + fix
There's a bug in cairo-ft.font.c
when copying colored glyphs to cairo surfaces. In _get_bitmap_surface
we have this code:
if (!_cairo_is_little_endian ())
{
/* Byteswap. */
unsigned int i, count = height * width;
uint32_t *p = (uint32_t *) data;
for (i = 0; i < count; i++)
p[i] = be32_to_cpu (p[i]);
}
But on big endian systems be32_to_cpu
is defined as:
#define be32_to_cpu(v) (v)
i.e. it does nothing. So the code above doesn't actually convert from BGRA to ARGB as it should be done on a big endian system. I don't know how to file a merge request here so I'm just going to post my fix:
if (!_cairo_is_little_endian ())
{
/* Byteswap. */
unsigned int i, count = height * width;
uint32_t *p = (uint32_t *) data;
for (i = 0; i < count; i++)
p[i] = (p[i]<<24)|((p[i]&0xff00)<<8)|((p[i]&0xff0000)>>8)|(p[i]>>24);
}
This will correctly convert from the BGRA in the FT_Bitmap to the ARGB byte order expected by the cairo surface. I've tested this fix on a PowerPC system and colored glyphs like emojis appear correctly now.