Hi all,
I want to be able to simply create a SDL surface using the SDL_CreateRGBSurface() routine, but only if I am given a width, height, and one of a few common bit depths. I need to calculate the 4 masks for that routine that depends on the endiness of the system.

So given a bit depth like so:

Code:
Type
    TBitDepth = (
        eBitDepth_8Bit,
        eBitDepth_15Bit,
        eBitDepth_16Bit,
        eBitDepth_24Bit,
        eBitDepth_32Bit
    );
Is there any 'easy' way of calculating the R, G, B and A masks for that depth and endiness?

Code:
Procedure CalculateRGBAMasks(Const ABitDepth               : TBitDepth;
                             Var   RMask,GMask,BMask,AMask : LongWord);
Begin
    // calculate masks required for bit depth?
End;
I am figuring it may be something like so (for little endian)

Code:
Procedure CalculateRGBAMasks(Const ABitDepth               : TBitDepth;
                             Var   RMask,GMask,BMask,AMask : LongWord);
Begin
    RMask := 0;
    GMask := 0;
    BMask := 0;
    AMask := 0;
    If SDL_BYTEORDER = SDL_LIL_ENDIAN Then
    Begin
        If ABitDepth In[eBitDepth_15Bit,eBitDepth_16Bit] Then
        Begin
            RMask := 31;         // 5 bits wide
            GMask := 63 Shl 5;   // 6 bits wide
            BMask := 31 Shl 11;  // 5 bits wide
        End
        Else
        If ABitDepth = eBitDepth_24Bit Then
        Begin
            RMask := 8;
            GMask := 8 Shl 8;
            BMask := 8 Shl 16;
        End
        Else
        If ABitDepth = eBitDepth_32Bit Then
        Begin
            RMask := 8;
            GMask := 8 Shl 8;
            BMask := 8 Shl 16;
            AMask := 8 Shl 24;
        End;
    End
    Else
    // bit endian format
    Begin
    End;
End;
If the little endian part is correct, I am not sure what the big endian version should be...

Thanks for any help you can give me :-)
cheers,
Paul