You can use SDL_ConvertSurfaceFormat() now
authorSam Lantinga
Mon, 28 Feb 2011 21:58:37 -0800
changeset 5418f8ecf0869cc9
parent 5417 958c15815b4a
child 5419 210b0abe9e44
You can use SDL_ConvertSurfaceFormat() now
Also, icon is guaranteed not to be NULL going into this function.
src/video/windows/SDL_windowswindow.c
     1.1 --- a/src/video/windows/SDL_windowswindow.c	Mon Feb 28 21:48:02 2011 -0800
     1.2 +++ b/src/video/windows/SDL_windowswindow.c	Mon Feb 28 21:58:37 2011 -0800
     1.3 @@ -286,57 +286,51 @@
     1.4  {
     1.5      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     1.6      HICON hicon = NULL;
     1.7 -
     1.8 -    if (icon) {
     1.9 -        BYTE *icon_bmp;
    1.10 -        int icon_len;
    1.11 -        SDL_RWops *dst;
    1.12 -        SDL_PixelFormat format;
    1.13 -        SDL_Surface *surface;
    1.14 +    BYTE *icon_bmp;
    1.15 +    int icon_len;
    1.16 +    SDL_RWops *dst;
    1.17 +    SDL_Surface *surface;
    1.18  
    1.19 -        /* Create temporary bitmap buffer */
    1.20 -        icon_len = 40 + icon->h * icon->w * 4;
    1.21 -        icon_bmp = SDL_stack_alloc(BYTE, icon_len);
    1.22 -        dst = SDL_RWFromMem(icon_bmp, icon_len);
    1.23 -        if (!dst) {
    1.24 -            SDL_stack_free(icon_bmp);
    1.25 -            return;
    1.26 -        }
    1.27 +    /* Create temporary bitmap buffer */
    1.28 +    icon_len = 40 + icon->h * icon->w * 4;
    1.29 +    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
    1.30 +    dst = SDL_RWFromMem(icon_bmp, icon_len);
    1.31 +    if (!dst) {
    1.32 +        SDL_stack_free(icon_bmp);
    1.33 +        return;
    1.34 +    }
    1.35  
    1.36 -        /* Write the BITMAPINFO header */
    1.37 -        SDL_WriteLE32(dst, 40);
    1.38 -        SDL_WriteLE32(dst, icon->w);
    1.39 -        SDL_WriteLE32(dst, icon->h * 2);
    1.40 -        SDL_WriteLE16(dst, 1);
    1.41 -        SDL_WriteLE16(dst, 32);
    1.42 -        SDL_WriteLE32(dst, BI_RGB);
    1.43 -        SDL_WriteLE32(dst, icon->h * icon->w * 4);
    1.44 -        SDL_WriteLE32(dst, 0);
    1.45 -        SDL_WriteLE32(dst, 0);
    1.46 -        SDL_WriteLE32(dst, 0);
    1.47 -        SDL_WriteLE32(dst, 0);
    1.48 +    /* Write the BITMAPINFO header */
    1.49 +    SDL_WriteLE32(dst, 40);
    1.50 +    SDL_WriteLE32(dst, icon->w);
    1.51 +    SDL_WriteLE32(dst, icon->h * 2);
    1.52 +    SDL_WriteLE16(dst, 1);
    1.53 +    SDL_WriteLE16(dst, 32);
    1.54 +    SDL_WriteLE32(dst, BI_RGB);
    1.55 +    SDL_WriteLE32(dst, icon->h * icon->w * 4);
    1.56 +    SDL_WriteLE32(dst, 0);
    1.57 +    SDL_WriteLE32(dst, 0);
    1.58 +    SDL_WriteLE32(dst, 0);
    1.59 +    SDL_WriteLE32(dst, 0);
    1.60  
    1.61 -        /* Convert the icon to a 32-bit surface with alpha channel */
    1.62 -        SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
    1.63 -        surface = SDL_ConvertSurface(icon, &format, 0);
    1.64 -        if (surface) {
    1.65 -            /* Write the pixels upside down into the bitmap buffer */
    1.66 -            int y = surface->h;
    1.67 -            while (y--) {
    1.68 -                Uint8 *src = (Uint8 *) surface->pixels + y * surface->pitch;
    1.69 -                SDL_RWwrite(dst, src, surface->pitch, 1);
    1.70 -            }
    1.71 -            SDL_FreeSurface(surface);
    1.72 +    /* Convert the icon to a 32-bit surface with alpha channel */
    1.73 +    surface = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
    1.74 +    if (surface) {
    1.75 +        /* Write the pixels upside down into the bitmap buffer */
    1.76 +        int y = surface->h;
    1.77 +        while (y--) {
    1.78 +            Uint8 *src = (Uint8 *) surface->pixels + y * surface->pitch;
    1.79 +            SDL_RWwrite(dst, src, surface->pitch, 1);
    1.80 +        }
    1.81 +        SDL_FreeSurface(surface);
    1.82  
    1.83  /* TODO: create the icon in WinCE (CreateIconFromResource isn't available) */
    1.84  #ifndef _WIN32_WCE
    1.85 -            hicon =
    1.86 -                CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
    1.87 +        hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
    1.88  #endif
    1.89 -        }
    1.90 -        SDL_RWclose(dst);
    1.91 -        SDL_stack_free(icon_bmp);
    1.92      }
    1.93 +    SDL_RWclose(dst);
    1.94 +    SDL_stack_free(icon_bmp);
    1.95  
    1.96      /* Set the icon for the window */
    1.97      SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);