More SDL_image Stuff

I’ve posted about this a couple times now.
It seems to me based on the previous messages
that I should maybe try other methods for accessing
the seperate color values of a pixel.

In the SDL docs it says that R, B, G, and Ashift are
values for “binary left shifts”. How/Can I use these
values to get the different color values of a given pixel?
Assume thePixel is a Uint32 value that represents
the given pixel. How do I use the -shift values of
SDL_format for the surface to get the color values?
Or if I don’t use the -shifts, how DO I get the color values.
It appears from pervious messages that SDL_GetRGBA
doesn’t work for this.

Is there a definite way to get each individual color value
for R, G, and B of a pixel of a surface loaded by SDL_image
that is independent of endianness, the image format on
disk, etc.?

Thanks so much for all your help,
Randall Leeds

Randall Leeds wrote:

In the SDL docs it says that R, B, G, and Ashift are
values for “binary left shifts”. How/Can I use these
values to get the different color values of a given pixel?

actually the {R,G,B,A]masks are all you need; the “shift” and “loss” are
derived from the masks, to make some manipulation easier.

Example: 32bpp, red=0xbe, green=0xba, blue=0xfe, alpha=0xca,
Rmask=0x000000ff, Gmask=0x0000ff00, Bmask=0x00ff0000, Amask=0xff000000
=> pixel value is 0xcafebabe
On a little-endian machine, it is stored as the bytes {0xbe,0x0xba,0xfe,0xca}.

It appears from pervious messages that SDL_GetRGBA
doesn’t work for this.

This works for ALL pixel formats, depths, and byte orders:

Uint32 pixel;
Uint8 red, green, blue, alpha;
pixel = getpixel(surface, x, y);
SDL_GetRGBA(pixel, surface->format, &red, &green, &blue, &alpha);

where getpixel is as the example in http://sdldoc.csn.ul.ie/guidevideo.php.
This is somewhat slow but should serve as example. Once you’re comfortable
with the pixel formats and representation you can try writing your own
faster routines