[cairo] ARGB, BGRA, RGBA mess
Bill Spitzak
spitzak at d2.com
Thu Jan 13 14:18:28 PST 2005
Carl Worth wrote:
> On Thu, 13 Jan 2005 13:24:55 -0800, Bill Spitzak wrote:
>
>>I think what several people here have been saying, me included, is that
>>the "standard" is that "RGBA" means R is in the byte with the lowest
>>address.
>
>
> "address" to me sounds like we are talking about an image in memory.
Yes indeed. What else could we be talking about?
>>I just checked sevearal interfaces to file reading/writing code
>
> File reading/writing to me sounds like a bytestream-oriented interface
> which is fundamentally different than an in-memory image. (But some of
> the confusion here may be a bit of "culture clash" between these two
> kinds of image interfaces).
I was talking about the API to the library, not to the file.
>>(libjpeg, libpng, and libtiff, imagemagic, etc) and every single one of
>>them uses RGBA. I do not see ARGB or BGRA anywhere! I also thing ABGR is
>>rarely used, except to handle endian issues.
>
>
> Quoting from libpng(3) I see the following input transformations
> available in that library:
>
> PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
> to BGRA
> PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
> to AG
>
> So this library clearly advertises support for RGBA, BGRA, and
> ARGB. And presumably if both transforms are enabled simultaneously one
> would get ABGR. Note: I'm just looking at the manual now, not
> examining any images in memory nor in files.
I was unaware of those controls. Nonetheless, the default for libpng is
to return the data in RGBA byte order. The code I am using (which works
on both big-endian and little-endian machines) reads and writes png
files without setting this transform stuff, and it clearly shows that
the passed and returned arrays are in RGBA byte order.
In addiont libpng calls the data "PNG_COLOR_TYPE_RGB" and
"PNG_COLOR_TYPE_RGB_ALPHA", and returns RGBA byte order if you don't set
a "transformation". Therefore they certainly think that the letters
"RGB" mean R is in the lower-numbered address. Also the comments you
quote above also show that they thing "BGRA" means B is in the lowest
addressed byte.
Therefore I still stand by my statement that almost everybody thinks
"RGBA" means R is in the byte with the lowest address, and that RGBA is
extremely common and should be the most-supported format. I still have
not seen any examples of ARGB or BGRA in any library that does not also
support RGBA.
More information about the cairo
mailing list