-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document pixel format naming convention and surface format #8318
Conversation
Whenever I have to fix something endianness-related, I always get confused about whether the byte-oriented format that guarantees to put red in byte 0 is RGBA8888 or RGBA32. (The answer is that it's RGBA32.) Signed-off-by: Simon McVittie <[email protected]>
I don't think we ever explicitly said this. Signed-off-by: Simon McVittie <[email protected]>
@smcv 😉 I was confused too. I'm currently accumulating a large collection of pixel formats across various hardware and graphics API's (like afrantzis's list but more comprehensive to include older bitplane formats too, like Amiga and 2D video game consoles), which includes SDL pixel formats naturally. Below is a subset of what I have. It's important to me that a pixel format of a given name unambiguously conveys the layout, and that reading data from a file across different devices is consistent, where a
And these are less stable formats, where the meaning flips depending on the architecture:
Correct? Reading through documentation of many other formats, it sounds like PFNC, DXGI, Metal, and WebGPU all decided to go with memory order of nomenclature, and that WebGPU's |
In SDL world, formats with names like RGBA32 have this property, but formats with names like RGBA8888 do not.
If the format is described in terms of a byte sequence (as is common in a file on disk), the meaning of RGBA32 is stable between architectures, and the meaning of RGBA8888 flips depending on the architecture. But, if the format is thought of as being a sequence of 32-bit words, the opposite is true: RGBA32 could be said not to be stable between architectures, because it has the alpha in either the most or least significant 8 bits of the first 32-bit word depending on architecture; while RGBA8888 could be said to be stable between architectures, because it always has the alpha in the least significant 8 bits (with the way those bits happen to be arranged in memory treated as an implementation detail). Neither way of looking at a format is necessarily wrong, so I think it's important to be specific about which one you mean. I think your descriptions in terms of structs are accurate, but I am not a SDL maintainer and what I say is not necessarily authoritative.
This would presumably be described as either RGBA1010102 or ABGR2101010 in SDL, depending whether endianness conventions are the same or reversed. It's difficult to see how a format like this, where the channels do not line up neatly with bytes, could be described in terms of byte-sequences in a machine-independent way, so I suspect that endianness will matter for such formats - it certainly does in SDL. |
Thanks again Simon for confirming (at least as far as you know) and improving the documentation. |
@smcv is correct. :) |
Description
pixels: Document the naming convention
Whenever I have to fix something endianness-related, I always get
confused about whether the byte-oriented format that guarantees to put
red in byte 0 is RGBA8888 or RGBA32. (The answer is that it's RGBA32.)
surface: Document the in-memory layout of the pixels
I don't think we ever explicitly said this.
Existing Issue(s)
Prompted by #8315.