[cairo] byte data storage format
Bill Spitzak
spitzak at thefoundry.co.uk
Wed Feb 11 03:21:55 PST 2009
Gerdus van Zyl wrote:
> It's in BGRA format. I think it's platform and not architecture
> specific since windows at least works with BGR. And the reason for
> that is I guess performance.
The bytes are in the order BGRA:
unsigned char* p = data;
p[0] == B, p[1] == G, p[2] == B, p[3] == A
Sometimes this is called ARGB32 (and sometimes just ARGB), because this
is the order the bytes appear if you look at a 32-bit word:
unsigned int* p = data;
p[0] == (A<<24)+(R<<16)+(B<<8)+(B<<0);
We are pretty much stuck with this, as Windows used ARGB32 to represent
colors, so all the graphics cards made that the fastest format.
It appears on big-endian machines like PowerPC, the native data is
*still* ARGB32, but that means the bytes are in the reversed order ARGB.
This is because the 32-bit bus that connects to the graphics is swapped
around so that 32-bit integers and floats look the same to the graphics
cards. I am not sure about this, somebody please correct me if wrong.
However if this is true it is probably best to not use bytes, but use
words to address your image data at all times, so that your code is
portable to big-endian.
--
Bill Spitzak, Senior Software Engineer
The Foundry, 1 Wardour Street, London, W1D 6PA, UK
Tel: +44 (0)20 7434 0449 * Fax: +44 (0)20 7434 1550 * Web:
www.thefoundry.co.uk
The Foundry Visionmongers Ltd * Registered in England and Wales No: 4642027
More information about the cairo
mailing list