— Tomas Bjerre <92tobj at utb.ronneby.se> wrote:
In the SDL documentation you only describe how to
use this function in
32 bit mode, but how do I create the masks in 16 or
24? Is this the
right way?
Traditionally 24 and 16 bit formats are alpha-less, so
in the case of using a ‘standard’ format, no. However,
I believe that the bellow, if creating a 16 bit
surface, should give 4 bits for each of red, green,
blue, and alpha. That’s 16 tones for each component.
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xf000;
gmask = 0x0f00;
bmask = 0x00f0;
amask = 0x000f;
#else
rmask = 0x000f;
gmask = 0x00f0;
bmask = 0x0f00;
amask = 0xf000;
#endif
surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
width, height, 16,
rmask, gmask,
bmask, amask);
Note: replaced the 32 with a 16 ;).
Okay, now if you wanted to create a more standard 16
bit surface, you’d use something like (for 5-5-5):
rmask = 31 << 10;
gmask = 31 << 5;
bmask = 31;
amask = 0;
surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
width, height, 16,
rmask, gmask,
bmask, amask);
Note that for 16 bit I excluded the endian code.
Reason?
Since the green component straddles multiple bytes, it
really dosn’t make sense to access them via bytes. The
way you WANT to access them is via words. Having edian
dependant masks will make the value of the word
different on different edians… totally un-necessary.
Let me explain:
32 bit pixel of color R:FF G:EE B:DD A:00
With the extra edian code, when we read the pixel a
byte at a time, we’ll allways get:
byte[0]=0xFF
byte[1]=0xEE
byte[2]=0xDD
byte[3]=0x00
whereas reading a dword at a time (aka an unsigned
int) we’ll get either:
0xFFEEDD00
or
0x00DDEEFF
depending on the endian.
Without the endian code, given the same scenario, if
we read a dword at a time, the value would allways be
0xFFEEDD00. However, if we read a byte at a time, we’d
either get:
byte[0]=0xFF
byte[1]=0xEE
byte[2]=0xDD
byte[3]=0x00
or:
byte[0]=0x00
byte[1]=0xDD
byte[2]=0xEE
byte[3]=0xFF
depending on which edian the system was using. Thus,
I’m assuming that in 32 bit mode, you want to access
via bytes, but in 16 bit mode, you want to access via
words, as the green component straddles bytes.
for a 24-bit, read-by-byte surface:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff0000;
gmask = 0xff00;
bmask = 0xff;
amask = 0;
#else
rmask = 0xff;
gmask = 0xff00;
bmask = 0xff0000;
amask = 0;
#endif
surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
width, height, 24,
rmask, gmask,
bmask, amask);
Hope this long-winded reply helps :).__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com