From e43f8d8003e2a6bf882ccafca9219af12add77d9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 7 Mar 2011 00:30:05 -0800 Subject: [PATCH] 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) --- include/SDL_pixels.h | 10 +++++----- src/video/SDL_pixels.c | 6 ++++-- src/video/SDL_surface.c | 39 +-------------------------------------- 3 files changed, 10 insertions(+), 45 deletions(-) diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h index 05f8c256c..3438eece1 100644 --- a/include/SDL_pixels.h +++ b/include/SDL_pixels.h @@ -149,16 +149,16 @@ enum { SDL_PIXELFORMAT_UNKNOWN, SDL_PIXELFORMAT_INDEX1LSB = - SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0, - 1, 0), - SDL_PIXELFORMAT_INDEX1MSB = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0, 1, 0), + SDL_PIXELFORMAT_INDEX1MSB = + 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), diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 85f860b86..61ef60388 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -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; diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index b9c07b06a..10fb5cf52 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -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;