Another way to describe the pixel formats in PCI-based Power Macintosh computers is by C struct definitions. The bit packing and bit ordering of packed bit structure fields in C match the endian formats of the target architecture.
Big-endian C compilers pack bits from left to right, while little-endian C compilers pack the bits from right to left. Hence different data structures must be used to describe a given pixel format, depending upon whether the target code is big-endian or little-endian.
Listing B-1 shows how the pixel formats described in this appendix can be defined in C for big-endian and little-endian bit ordering.
Listing B-1 C structures for pixel formats
typedef struct { /* big-endian pixel formats */
u_int alpha:1;
u_int red:5;
u_int green:5;
u_int blue:5;
} RGB_15_alpha;
typedef struct {
u_int alpha:8;
u_int red:8;
u_int green:8;
u_int blue:8;
} RGB_24_alpha;
typedef struct { /* little-endian pixel formats */
u_int blue:5;
u_int green:5;
u_int red:5;
u_int alpha:1;
} RGB_15_alpha;
typedef struct {
u_int blue:8;
u_int green:8;
u_int red:8;
u_int alpha:8;
} RGB_24_alpha;