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)150.01)green;
blue = ((float)150.01)blue;
alpha = ((float)150.01)alpha;
break;
case 24:
//6 bitar per nyans
red = ((float)630.01)red;
green = ((float)630.01)green;
blue = ((float)630.01)blue;
alpha = ((float)630.01)alpha;
break;
case 32:
//8 bitar per nyans
red = ((float)2550.01)red;
green = ((float)2550.01)green;
blue = ((float)2550.01)blue;
alpha = ((float)2550.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.