Commit e43f8d80 authored by Sam Lantinga's avatar Sam Lantinga

Fixed bitmap order interpretation; SDL defaults to MSB ordering so a bitstream...

Fixed bitmap order interpretation; SDL defaults to MSB ordering so a bitstream corresponds to a pixel stream.

The bitmap ordering is defined such that the numbering refers to the pixel index from left to right, and the number position refers to the bit position in the byte.

SDL_BITMAPORDER_4321 is the fourth pixel at the high bit and the first pixel at the low bit (LSBFirst)

SDL_BITMAPORDER_1234 is the first pixel at the high bit and the fourth pixel at the low bit (MSBFirst)
parent 2bea0e63
......@@ -149,16 +149,16 @@ enum
{
SDL_PIXELFORMAT_UNKNOWN,
SDL_PIXELFORMAT_INDEX1LSB =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
1, 0),
SDL_PIXELFORMAT_INDEX1MSB =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
1, 0),
SDL_PIXELFORMAT_INDEX4LSB =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
4, 0),
SDL_PIXELFORMAT_INDEX4MSB =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
4, 0),
SDL_PIXELFORMAT_INDEX8 =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
......
......@@ -242,9 +242,11 @@ SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
{
switch (bpp) {
case 1:
/* SDL defaults to MSB ordering */
return SDL_PIXELFORMAT_INDEX1MSB;
case 4:
/* Can't tell if this is LSB or MSB bitmap ordering... */
break;
/* SDL defaults to MSB ordering */
return SDL_PIXELFORMAT_INDEX4MSB;
case 8:
if (Rmask == 0) {
return SDL_PIXELFORMAT_INDEX8;
......
......@@ -75,44 +75,7 @@ SDL_CreateRGBSurface(Uint32 flags,
SDL_FreeSurface(surface);
return NULL;
}
if (Rmask || Bmask || Gmask) {
const SDL_PixelFormat *format = surface->format;
/* create palette according to masks */
int i;
int Rm = 0, Gm = 0, Bm = 0;
int Rw = 0, Gw = 0, Bw = 0;
if (Rmask) {
Rw = 8 - format->Rloss;
for (i = format->Rloss; i > 0; i -= Rw)
Rm |= 1 << i;
}
if (Gmask) {
Gw = 8 - format->Gloss;
for (i = format->Gloss; i > 0; i -= Gw)
Gm |= 1 << i;
}
if (Bmask) {
Bw = 8 - format->Bloss;
for (i = format->Bloss; i > 0; i -= Bw)
Bm |= 1 << i;
}
for (i = 0; i < palette->ncolors; ++i) {
int r, g, b;
r = (i & Rmask) >> format->Rshift;
r = (r << format->Rloss) | ((r * Rm) >> Rw);
palette->colors[i].r = r;
g = (i & Gmask) >> format->Gshift;
g = (g << format->Gloss) | ((g * Gm) >> Gw);
palette->colors[i].g = g;
b = (i & Bmask) >> format->Bshift;
b = (b << format->Bloss) | ((b * Bm) >> Bw);
palette->colors[i].b = b;
}
} else if (palette->ncolors == 2) {
if (palette->ncolors == 2) {
/* Create a black and white bitmap palette */
palette->colors[0].r = 0xFF;
palette->colors[0].g = 0xFF;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment