Trying to understand endian

hello all,
in the sdl docs putpixel() function, case 3, which i believe is 24bpp,
correct? … even if i’m wrong there, could somebody explain
SDL_BYTEORDER and SDL_BIG_ENDIAN to me? what’s that there for? do these
values vary from platform to platform or something? thanks.

/*

  • Set the pixel at (x, y) to the given value

  • NOTE: The surface must be locked before calling this!
    */
    void putpixel(SDL_Surface surface, int x, int y, Uint32 pixel)
    {
    int bpp = surface->format->BytesPerPixel;
    /
    Here p is the address to the pixel we want to set */
    Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

    switch(bpp) {
    case 1:
    *p = pixel;
    break;

    case 2:
    *(Uint16 *)p = pixel;
    break;

    case 3:
    if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
    p[0] = (pixel >> 16) & 0xff;
    p[1] = (pixel >> 8) & 0xff;
    p[2] = pixel & 0xff;
    } else {
    p[0] = pixel & 0xff;
    p[1] = (pixel >> 8) & 0xff;
    p[2] = (pixel >> 16) & 0xff;
    }
    break;

    case 4:
    *(Uint32 *)p = pixel;
    break;
    }
    }

– chris (@Christopher_Thielen)

hello all,
in the sdl docs putpixel() function, case 3, which i believe is 24bpp,
correct? … even if i’m wrong there, could somebody explain
SDL_BYTEORDER and SDL_BIG_ENDIAN to me? what’s that there for? do these
values vary from platform to platform or something? thanks.

Yes putpixel is correct.
SDL_BYTEORDER realy vary from platform to platform. It is about order of
bytes in word or double word. (int16,int32)
it depends on processor.
for example 0x000000ff on apple PPC means 0xff000000 on intel pc
Krata