SDL_CreateRGBSurface, with 24 and 16 bit

I was wondering how to use SDL_CreateRGBSurface with a colordepth of 16
and 24 bit. In the manual and anywhere else on the net I only find
examples with 32 bit.
Currently I use it as this example demonstrates (
www.shell.linux.se/bjerre/filer/projektarbete/del3-creatergbsurface.cpp
).
This is the function I have created to calculate the [rgba]mask. The
red, green, blue and alpha parameters are the gamma in percent for each
color.
void getRGBAMask(Uint8 bpp, Uint32 &rmask, Uint32 &gmask, Uint32 &bmask,
Uint32 &amask, int red, int green, int blue, int alpha) {
switch(bpp) {
case 16:
//4 bitar per nyans
red = ((float)15*0.01)red;
green = ((float)15
0.01)green;
blue = ((float)15
0.01)blue;
alpha = ((float)15
0.01)alpha;
break;
case 24:
//6 bitar per nyans
red = ((float)63
0.01)red;
green = ((float)63
0.01)green;
blue = ((float)63
0.01)blue;
alpha = ((float)63
0.01)alpha;
break;
case 32:
//8 bitar per nyans
red = ((float)255
0.01)red;
green = ((float)255
0.01)green;
blue = ((float)255
0.01)blue;
alpha = ((float)255
0.01)*alpha;
break;
}

int position = bpp/4;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	rmask = red   << (position*3);
	gmask = green << (position*2);
	bmask = blue  << (position*1);
	amask = alpha;
#else
	rmask = red;
	gmask = green  << (position*1);
	bmask = blue   << (position*2);
	amask = alpha  << (position*3);
#endif

}

Is this the easiest way? If anybody has examples then please email them
to me.

Tomas Bjerre wrote:

[snip]

Is this the easiest way? If anybody has examples then please email them
to me.

Well, not really the easiest way. The mask values are platform dependent.

The easiest way is to read shift/mask/loss values where they are :
inside the surface format structure (of type SDL_PixelFormat)
Read this for more info :
http://sdldoc.csn.ul.ie/sdlpixelformat.php

Stephane