src/video/SDL_bmp.c
changeset 2969 1ee69e7e7cea
parent 2967 e4a469d6ddab
child 2990 502adab079a4
equal deleted inserted replaced
2968:efe4d0ce2e97 2969:1ee69e7e7cea
   375     Uint32 biClrImportant;
   375     Uint32 biClrImportant;
   376 
   376 
   377     /* Make sure we have somewhere to save */
   377     /* Make sure we have somewhere to save */
   378     surface = NULL;
   378     surface = NULL;
   379     if (dst) {
   379     if (dst) {
   380         if (saveme->format->palette) {
   380         SDL_bool save32bit = SDL_FALSE;
       
   381 #ifdef SAVE_32BIT_BMP
       
   382         /* We can save alpha information in a 32-bit BMP */
       
   383         if (saveme->map->info.flags & SDL_COPY_COLORKEY ||
       
   384             saveme->format->Amask) {
       
   385             save32bit = SDL_TRUE;
       
   386         }
       
   387 #endif /* SAVE_32BIT_BMP */
       
   388 
       
   389         if (saveme->format->palette && !save32bit) {
   381             if (saveme->format->BitsPerPixel == 8) {
   390             if (saveme->format->BitsPerPixel == 8) {
   382                 surface = saveme;
   391                 surface = saveme;
   383             } else {
   392             } else {
   384                 SDL_SetError("%d bpp BMP files not supported",
   393                 SDL_SetError("%d bpp BMP files not supported",
   385                              saveme->format->BitsPerPixel);
   394                              saveme->format->BitsPerPixel);
   397             ) {
   406             ) {
   398             surface = saveme;
   407             surface = saveme;
   399         } else {
   408         } else {
   400             SDL_PixelFormat format;
   409             SDL_PixelFormat format;
   401 
   410 
   402             /* Convert to 24 bits per pixel */
   411             /* If the surface has a colorkey or alpha channel we'll save a
   403             SDL_InitFormat(&format, 24,
   412                32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
       
   413             if (save32bit) {
       
   414                 SDL_InitFormat(&format, 32,
       
   415                                0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
       
   416             } else {
       
   417                 SDL_InitFormat(&format, 24,
   404 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   418 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   405                            0x00FF0000, 0x0000FF00, 0x000000FF,
   419                                0x00FF0000, 0x0000FF00, 0x000000FF,
   406 #else
   420 #else
   407                            0x000000FF, 0x0000FF00, 0x00FF0000,
   421                                0x000000FF, 0x0000FF00, 0x00FF0000,
   408 #endif
   422 #endif
   409                            0);
   423                                0);
       
   424             }
   410             surface = SDL_ConvertSurface(saveme, &format, 0);
   425             surface = SDL_ConvertSurface(saveme, &format, 0);
   411             if (!surface) {
   426             if (!surface) {
   412                 SDL_SetError("Couldn't convert image to 24 bpp");
   427                 SDL_SetError("Couldn't convert image to %d bpp", format.BitsPerPixel);
   413             }
   428             }
   414         }
   429         }
   415     }
   430     }
   416 
   431 
   417     if (surface && (SDL_LockSurface(surface) == 0)) {
   432     if (surface && (SDL_LockSurface(surface) == 0)) {