Default palette entries to white, instead of black. SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Fri, 16 Jun 2006 06:00:31 +0000
branchSDL-1.3
changeset 16827ae8018b2e5d
parent 1681 80a5e6a4e1e2
child 1683 396a35389351
Default palette entries to white, instead of black.
More palettized video mode support...
include/SDL_compat.h
include/SDL_pixels.h
include/SDL_video.h
src/SDL_compat.c
src/video/SDL_pixels.c
src/video/SDL_surface.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dummy/SDL_nullrender.c
     1.1 --- a/include/SDL_compat.h	Thu Jun 15 07:07:07 2006 +0000
     1.2 +++ b/include/SDL_compat.h	Fri Jun 16 06:00:31 2006 +0000
     1.3 @@ -44,8 +44,8 @@
     1.4  #define SDL_RESIZABLE       0x01000000
     1.5  #define SDL_NOFRAME         0x02000000
     1.6  #define SDL_OPENGL          0x04000000
     1.7 -#define SDL_ASYNCBLIT       0x00000000
     1.8 -#define SDL_HWACCEL         0x00000000
     1.9 +#define SDL_ASYNCBLIT       0x08000000  /* Not used */
    1.10 +#define SDL_HWACCEL         0x08000000  /* Not used */
    1.11  #define SDL_SCREEN_SURFACE  0x10000000  /* Surface is a window screen surface */
    1.12  #define SDL_SHADOW_SURFACE  0x20000000  /* Surface is a window shadow surface */
    1.13  
    1.14 @@ -146,10 +146,10 @@
    1.15  extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface * surface);
    1.16  extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode);
    1.17  extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface, int flags,
    1.18 -                                           SDL_Color * colors,
    1.19 +                                           const SDL_Color * colors,
    1.20                                             int firstcolor, int ncolors);
    1.21  extern DECLSPEC int SDLCALL SDL_SetScreenColors(SDL_Surface * screen,
    1.22 -                                                SDL_Color * colors,
    1.23 +                                                const SDL_Color * colors,
    1.24                                                  int firstcolor, int ncolors);
    1.25  extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo * info);
    1.26  extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void);
     2.1 --- a/include/SDL_pixels.h	Thu Jun 15 07:07:07 2006 +0000
     2.2 +++ b/include/SDL_pixels.h	Fri Jun 16 06:00:31 2006 +0000
     2.3 @@ -114,7 +114,7 @@
     2.4       (SDL_PIXELTYPE(format) == SDL_PixelType_Index8))
     2.5  
     2.6  #define SDL_ISPIXELFORMAT_FOURCC(format)    \
     2.7 -    ((format) && !((format) & 0x8000000))
     2.8 +    ((format) && !((format) & 0x80000000))
     2.9  
    2.10  enum
    2.11  {
     3.1 --- a/include/SDL_video.h	Thu Jun 15 07:07:07 2006 +0000
     3.2 +++ b/include/SDL_video.h	Fri Jun 16 06:00:31 2006 +0000
     3.3 @@ -1082,8 +1082,8 @@
     3.4   * emulation.
     3.5   */
     3.6  extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface * surface,
     3.7 -                                          SDL_Color * colors, int firstcolor,
     3.8 -                                          int ncolors);
     3.9 +                                          const SDL_Color * colors,
    3.10 +                                          int firstcolor, int ncolors);
    3.11  
    3.12  /*
    3.13   * Maps an RGB triple to an opaque pixel value for a given pixel format
     4.1 --- a/src/SDL_compat.c	Thu Jun 15 07:07:07 2006 +0000
     4.2 +++ b/src/SDL_compat.c	Fri Jun 16 06:00:31 2006 +0000
     4.3 @@ -218,6 +218,7 @@
     4.4      Uint32 desktop_format;
     4.5      Uint32 desired_format;
     4.6      Uint32 texture_format;
     4.7 +    Uint32 surface_flags;
     4.8  
     4.9      if (!SDL_GetVideoDevice()) {
    4.10          if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
    4.11 @@ -264,6 +265,21 @@
    4.12          return NULL;
    4.13      }
    4.14  
    4.15 +    window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
    4.16 +    surface_flags = SDL_SCREEN_SURFACE;
    4.17 +    if (window_flags & SDL_WINDOW_FULLSCREEN) {
    4.18 +        surface_flags |= SDL_FULLSCREEN;
    4.19 +    }
    4.20 +    if (window_flags & SDL_WINDOW_OPENGL) {
    4.21 +        surface_flags |= SDL_OPENGL;
    4.22 +    }
    4.23 +    if (window_flags & SDL_WINDOW_RESIZABLE) {
    4.24 +        surface_flags |= SDL_RESIZABLE;
    4.25 +    }
    4.26 +    if (window_flags & SDL_WINDOW_BORDERLESS) {
    4.27 +        surface_flags |= SDL_NOFRAME;
    4.28 +    }
    4.29 +
    4.30      /* Set up the desired display mode */
    4.31      desktop_mode = SDL_GetDesktopDisplayMode();
    4.32      desktop_format = desktop_mode->format;
    4.33 @@ -323,6 +339,18 @@
    4.34          return NULL;
    4.35      }
    4.36  
    4.37 +    /* If we're in OpenGL mode, just create a stub surface and we're done! */
    4.38 +    if (flags & SDL_OPENGL) {
    4.39 +        SDL_VideoSurface =
    4.40 +            SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
    4.41 +        if (!SDL_VideoSurface) {
    4.42 +            return NULL;
    4.43 +        }
    4.44 +        SDL_VideoSurface->flags |= surface_flags;
    4.45 +        SDL_PublicSurface = SDL_VideoSurface;
    4.46 +        return SDL_PublicSurface;
    4.47 +    }
    4.48 +
    4.49      /* Create a renderer for the window */
    4.50      if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
    4.51          return NULL;
    4.52 @@ -345,6 +373,7 @@
    4.53      if (!SDL_VideoSurface) {
    4.54          return NULL;
    4.55      }
    4.56 +    SDL_VideoSurface->flags |= surface_flags;
    4.57  
    4.58      /* Set a default screen palette */
    4.59      if (SDL_VideoSurface->format->palette) {
    4.60 @@ -354,6 +383,8 @@
    4.61          SDL_SetTexturePalette(SDL_VideoTexture,
    4.62                                SDL_VideoSurface->format->palette->colors, 0,
    4.63                                SDL_VideoSurface->format->palette->ncolors);
    4.64 +        SDL_SetDisplayPalette(SDL_VideoSurface->format->palette->colors, 0,
    4.65 +                              SDL_VideoSurface->format->palette->ncolors);
    4.66      }
    4.67  
    4.68      /* Create a shadow surface if necessary */
    4.69 @@ -377,6 +408,9 @@
    4.70          if (!SDL_ShadowSurface) {
    4.71              return NULL;
    4.72          }
    4.73 +        surface_flags &= ~SDL_SCREEN_SURFACE;
    4.74 +        surface_flags |= SDL_SHADOW_SURFACE;
    4.75 +        SDL_ShadowSurface->flags |= surface_flags;
    4.76  
    4.77          /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
    4.78          if (SDL_ShadowSurface->format->palette) {
    4.79 @@ -615,15 +649,15 @@
    4.80  }
    4.81  
    4.82  int
    4.83 -SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors,
    4.84 +SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
    4.85                 int firstcolor, int ncolors)
    4.86  {
    4.87      SDL_SetColors(surface, colors, firstcolor, ncolors);
    4.88  }
    4.89  
    4.90  int
    4.91 -SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor,
    4.92 -                    int ncolors)
    4.93 +SDL_SetScreenColors(SDL_Surface * screen, const SDL_Color * colors,
    4.94 +                    int firstcolor, int ncolors)
    4.95  {
    4.96      SDL_Palette *pal;
    4.97      int gotall;
     5.1 --- a/src/video/SDL_pixels.c	Thu Jun 15 07:07:07 2006 +0000
     5.2 +++ b/src/video/SDL_pixels.c	Fri Jun 16 06:00:31 2006 +0000
     5.3 @@ -386,7 +386,7 @@
     5.4                  a = (a << format->Aloss) | ((a * Am) >> Aw);
     5.5                  format->palette->colors[i].unused = a;
     5.6  #else
     5.7 -                format->palette->colors[i].unused = 0;
     5.8 +                format->palette->colors[i].unused = SDL_ALPHA_OPAQUE;
     5.9  #endif
    5.10              }
    5.11          } else if (ncolors == 2) {
    5.12 @@ -399,7 +399,7 @@
    5.13              format->palette->colors[1].b = 0x00;
    5.14          } else {
    5.15              /* Create an empty palette */
    5.16 -            SDL_memset((format->palette)->colors, 0,
    5.17 +            SDL_memset((format->palette)->colors, 0xFF,
    5.18                         (format->palette)->ncolors * sizeof(SDL_Color));
    5.19          }
    5.20      }
    5.21 @@ -474,6 +474,7 @@
    5.22          b |= b << 2;
    5.23          b |= b << 4;
    5.24          colors[i].b = b;
    5.25 +        colors[i].unused = SDL_ALPHA_OPAQUE;
    5.26      }
    5.27  }
    5.28  
    5.29 @@ -696,7 +697,7 @@
    5.30  
    5.31      /* SDL_DitherColors does not initialize the 'unused' component of colors,
    5.32         but Map1to1 compares it against pal, so we should initialize it. */
    5.33 -    SDL_memset(colors, 0, sizeof(colors));
    5.34 +    SDL_memset(colors, 0xFF, sizeof(colors));
    5.35  
    5.36      dithered.ncolors = 256;
    5.37      SDL_DitherColors(colors, 8);
     6.1 --- a/src/video/SDL_surface.c	Thu Jun 15 07:07:07 2006 +0000
     6.2 +++ b/src/video/SDL_surface.c	Fri Jun 16 06:00:31 2006 +0000
     6.3 @@ -39,7 +39,6 @@
     6.4                       int width, int height, int depth,
     6.5                       Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
     6.6  {
     6.7 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
     6.8      SDL_Surface *screen;
     6.9      SDL_Surface *surface;
    6.10  
    6.11 @@ -170,7 +169,7 @@
    6.12   * Set the palette in a blittable surface
    6.13   */
    6.14  int
    6.15 -SDL_SetColors(SDL_Surface * surface, SDL_Color * colors, int firstcolor,
    6.16 +SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
    6.17                int ncolors)
    6.18  {
    6.19      SDL_Palette *pal;
    6.20 @@ -557,7 +556,6 @@
    6.21  int
    6.22  SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
    6.23  {
    6.24 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    6.25      int x, y;
    6.26      Uint8 *row;
    6.27  
    6.28 @@ -789,9 +787,9 @@
    6.29      if (format->palette != NULL) {
    6.30          int i;
    6.31          for (i = 0; i < format->palette->ncolors; ++i) {
    6.32 -            if ((format->palette->colors[i].r != 0) ||
    6.33 -                (format->palette->colors[i].g != 0) ||
    6.34 -                (format->palette->colors[i].b != 0))
    6.35 +            if ((format->palette->colors[i].r != 0xFF) ||
    6.36 +                (format->palette->colors[i].g != 0xFF) ||
    6.37 +                (format->palette->colors[i].b != 0xFF))
    6.38                  break;
    6.39          }
    6.40          if (i == format->palette->ncolors) {
     7.1 --- a/src/video/SDL_sysvideo.h	Thu Jun 15 07:07:07 2006 +0000
     7.2 +++ b/src/video/SDL_sysvideo.h	Fri Jun 16 06:00:31 2006 +0000
     7.3 @@ -159,6 +159,8 @@
     7.4      /* The hash list of textures */
     7.5      SDL_Texture *textures[64];
     7.6  
     7.7 +    SDL_VideoDevice *device;
     7.8 +
     7.9      void *driverdata;
    7.10  };
    7.11  
     8.1 --- a/src/video/SDL_video.c	Thu Jun 15 07:07:07 2006 +0000
     8.2 +++ b/src/video/SDL_video.c	Fri Jun 16 06:00:31 2006 +0000
     8.3 @@ -333,6 +333,7 @@
     8.4      if (displays) {
     8.5          index = _this->num_displays++;
     8.6          displays[index] = *display;
     8.7 +        displays[index].device = _this;
     8.8          _this->displays = displays;
     8.9      } else {
    8.10          SDL_OutOfMemory();
     9.1 --- a/src/video/dummy/SDL_nullrender.c	Thu Jun 15 07:07:07 2006 +0000
     9.2 +++ b/src/video/dummy/SDL_nullrender.c	Fri Jun 16 06:00:31 2006 +0000
     9.3 @@ -32,11 +32,11 @@
     9.4  static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
     9.5                                     SDL_Texture * texture);
     9.6  static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
     9.7 -                                      SDL_Rect * rect, void *pixels,
     9.8 +                                      const SDL_Rect * rect, void *pixels,
     9.9                                        int pitch);
    9.10  static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
    9.11 -                                       SDL_Rect * rect, const void *pixels,
    9.12 -                                       int pitch);
    9.13 +                                       const SDL_Rect * rect,
    9.14 +                                       const void *pixels, int pitch);
    9.15  static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
    9.16  static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
    9.17  
    9.18 @@ -57,7 +57,7 @@
    9.19  
    9.20  typedef struct
    9.21  {
    9.22 -    SDL_Surface *screen;
    9.23 +    SDL_Surface *surface;
    9.24  } SDL_DUMMY_RenderData;
    9.25  
    9.26  SDL_Renderer *
    9.27 @@ -99,24 +99,34 @@
    9.28      renderer->window = window;
    9.29      renderer->driverdata = data;
    9.30  
    9.31 -    data->screen =
    9.32 +    data->surface =
    9.33          SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
    9.34                               Bmask, Amask);
    9.35 -    if (!data->screen) {
    9.36 +    if (!data->surface) {
    9.37          SDL_DUMMY_DestroyRenderer(renderer);
    9.38          return NULL;
    9.39      }
    9.40  
    9.41 +    /* If the display has a palette, use it for the window surfaces */
    9.42 +    if (window->display->palette.ncolors) {
    9.43 +        SDL_PixelFormat *format = data->surface->format;
    9.44 +        if (format->palette->colors) {
    9.45 +            SDL_free(format->palette->colors);
    9.46 +        }
    9.47 +        SDL_free(format->palette);
    9.48 +        format->palette = &window->display->palette;
    9.49 +    }
    9.50 +
    9.51      return renderer;
    9.52  }
    9.53  
    9.54  int
    9.55 -SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
    9.56 +SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    9.57                             void *pixels, int pitch)
    9.58  {
    9.59      SDL_DUMMY_RenderData *data =
    9.60          (SDL_DUMMY_RenderData *) renderer->driverdata;
    9.61 -    SDL_Surface *surface = data->screen;
    9.62 +    SDL_Surface *surface = data->surface;
    9.63      Uint8 *src, *dst;
    9.64      int row;
    9.65      size_t length;
    9.66 @@ -135,12 +145,12 @@
    9.67  }
    9.68  
    9.69  int
    9.70 -SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
    9.71 +SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    9.72                              const void *pixels, int pitch)
    9.73  {
    9.74      SDL_DUMMY_RenderData *data =
    9.75          (SDL_DUMMY_RenderData *) renderer->driverdata;
    9.76 -    SDL_Surface *surface = data->screen;
    9.77 +    SDL_Surface *surface = data->surface;
    9.78      Uint8 *src, *dst;
    9.79      int row;
    9.80      size_t length;
    9.81 @@ -164,7 +174,7 @@
    9.82      static int frame_number;
    9.83      SDL_DUMMY_RenderData *data =
    9.84          (SDL_DUMMY_RenderData *) renderer->driverdata;
    9.85 -    SDL_Surface *surface = data->screen;
    9.86 +    SDL_Surface *surface = data->surface;
    9.87  
    9.88      if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
    9.89          char file[128];
    9.90 @@ -181,8 +191,9 @@
    9.91          (SDL_DUMMY_RenderData *) renderer->driverdata;
    9.92  
    9.93      if (data) {
    9.94 -        if (data->screen) {
    9.95 -            SDL_FreeSurface(data->screen);
    9.96 +        if (data->surface) {
    9.97 +            data->surface->format->palette = NULL;
    9.98 +            SDL_FreeSurface(data->surface);
    9.99          }
   9.100          SDL_free(data);
   9.101      }