src/video/SDL_bmp.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
child 1670 eef792d31de8
     1.1 --- a/src/video/SDL_bmp.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/video/SDL_bmp.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -46,7 +46,7 @@
     1.4  
     1.5  
     1.6  SDL_Surface *
     1.7 -SDL_LoadBMP_RW (SDL_RWops * src, int freesrc)
     1.8 +SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
     1.9  {
    1.10      int was_error;
    1.11      long fp_offset;
    1.12 @@ -89,30 +89,30 @@
    1.13      }
    1.14  
    1.15      /* Read in the BMP file header */
    1.16 -    fp_offset = SDL_RWtell (src);
    1.17 -    SDL_ClearError ();
    1.18 -    if (SDL_RWread (src, magic, 1, 2) != 2) {
    1.19 -        SDL_Error (SDL_EFREAD);
    1.20 +    fp_offset = SDL_RWtell(src);
    1.21 +    SDL_ClearError();
    1.22 +    if (SDL_RWread(src, magic, 1, 2) != 2) {
    1.23 +        SDL_Error(SDL_EFREAD);
    1.24          was_error = 1;
    1.25          goto done;
    1.26      }
    1.27 -    if (SDL_strncmp (magic, "BM", 2) != 0) {
    1.28 -        SDL_SetError ("File is not a Windows BMP file");
    1.29 +    if (SDL_strncmp(magic, "BM", 2) != 0) {
    1.30 +        SDL_SetError("File is not a Windows BMP file");
    1.31          was_error = 1;
    1.32          goto done;
    1.33      }
    1.34 -    bfSize = SDL_ReadLE32 (src);
    1.35 -    bfReserved1 = SDL_ReadLE16 (src);
    1.36 -    bfReserved2 = SDL_ReadLE16 (src);
    1.37 -    bfOffBits = SDL_ReadLE32 (src);
    1.38 +    bfSize = SDL_ReadLE32(src);
    1.39 +    bfReserved1 = SDL_ReadLE16(src);
    1.40 +    bfReserved2 = SDL_ReadLE16(src);
    1.41 +    bfOffBits = SDL_ReadLE32(src);
    1.42  
    1.43      /* Read the Win32 BITMAPINFOHEADER */
    1.44 -    biSize = SDL_ReadLE32 (src);
    1.45 +    biSize = SDL_ReadLE32(src);
    1.46      if (biSize == 12) {
    1.47 -        biWidth = (Uint32) SDL_ReadLE16 (src);
    1.48 -        biHeight = (Uint32) SDL_ReadLE16 (src);
    1.49 -        biPlanes = SDL_ReadLE16 (src);
    1.50 -        biBitCount = SDL_ReadLE16 (src);
    1.51 +        biWidth = (Uint32) SDL_ReadLE16(src);
    1.52 +        biHeight = (Uint32) SDL_ReadLE16(src);
    1.53 +        biPlanes = SDL_ReadLE16(src);
    1.54 +        biBitCount = SDL_ReadLE16(src);
    1.55          biCompression = BI_RGB;
    1.56          biSizeImage = 0;
    1.57          biXPelsPerMeter = 0;
    1.58 @@ -120,20 +120,20 @@
    1.59          biClrUsed = 0;
    1.60          biClrImportant = 0;
    1.61      } else {
    1.62 -        biWidth = SDL_ReadLE32 (src);
    1.63 -        biHeight = SDL_ReadLE32 (src);
    1.64 -        biPlanes = SDL_ReadLE16 (src);
    1.65 -        biBitCount = SDL_ReadLE16 (src);
    1.66 -        biCompression = SDL_ReadLE32 (src);
    1.67 -        biSizeImage = SDL_ReadLE32 (src);
    1.68 -        biXPelsPerMeter = SDL_ReadLE32 (src);
    1.69 -        biYPelsPerMeter = SDL_ReadLE32 (src);
    1.70 -        biClrUsed = SDL_ReadLE32 (src);
    1.71 -        biClrImportant = SDL_ReadLE32 (src);
    1.72 +        biWidth = SDL_ReadLE32(src);
    1.73 +        biHeight = SDL_ReadLE32(src);
    1.74 +        biPlanes = SDL_ReadLE16(src);
    1.75 +        biBitCount = SDL_ReadLE16(src);
    1.76 +        biCompression = SDL_ReadLE32(src);
    1.77 +        biSizeImage = SDL_ReadLE32(src);
    1.78 +        biXPelsPerMeter = SDL_ReadLE32(src);
    1.79 +        biYPelsPerMeter = SDL_ReadLE32(src);
    1.80 +        biClrUsed = SDL_ReadLE32(src);
    1.81 +        biClrImportant = SDL_ReadLE32(src);
    1.82      }
    1.83  
    1.84      /* Check for read error */
    1.85 -    if (SDL_strcmp (SDL_GetError (), "") != 0) {
    1.86 +    if (SDL_strcmp(SDL_GetError(), "") != 0) {
    1.87          was_error = 1;
    1.88          goto done;
    1.89      }
    1.90 @@ -188,24 +188,24 @@
    1.91          case 15:
    1.92          case 16:
    1.93          case 32:
    1.94 -            Rmask = SDL_ReadLE32 (src);
    1.95 -            Gmask = SDL_ReadLE32 (src);
    1.96 -            Bmask = SDL_ReadLE32 (src);
    1.97 +            Rmask = SDL_ReadLE32(src);
    1.98 +            Gmask = SDL_ReadLE32(src);
    1.99 +            Bmask = SDL_ReadLE32(src);
   1.100              break;
   1.101          default:
   1.102              break;
   1.103          }
   1.104          break;
   1.105      default:
   1.106 -        SDL_SetError ("Compressed BMP files not supported");
   1.107 +        SDL_SetError("Compressed BMP files not supported");
   1.108          was_error = 1;
   1.109          goto done;
   1.110      }
   1.111  
   1.112      /* Create a compatible surface, note that the colors are RGB ordered */
   1.113 -    surface = SDL_CreateRGBSurface (SDL_SWSURFACE,
   1.114 -                                    biWidth, biHeight, biBitCount, Rmask,
   1.115 -                                    Gmask, Bmask, 0);
   1.116 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   1.117 +                                   biWidth, biHeight, biBitCount, Rmask,
   1.118 +                                   Gmask, Bmask, 0);
   1.119      if (surface == NULL) {
   1.120          was_error = 1;
   1.121          goto done;
   1.122 @@ -219,25 +219,25 @@
   1.123          }
   1.124          if (biSize == 12) {
   1.125              for (i = 0; i < (int) biClrUsed; ++i) {
   1.126 -                SDL_RWread (src, &palette->colors[i].b, 1, 1);
   1.127 -                SDL_RWread (src, &palette->colors[i].g, 1, 1);
   1.128 -                SDL_RWread (src, &palette->colors[i].r, 1, 1);
   1.129 +                SDL_RWread(src, &palette->colors[i].b, 1, 1);
   1.130 +                SDL_RWread(src, &palette->colors[i].g, 1, 1);
   1.131 +                SDL_RWread(src, &palette->colors[i].r, 1, 1);
   1.132                  palette->colors[i].unused = 0;
   1.133              }
   1.134          } else {
   1.135              for (i = 0; i < (int) biClrUsed; ++i) {
   1.136 -                SDL_RWread (src, &palette->colors[i].b, 1, 1);
   1.137 -                SDL_RWread (src, &palette->colors[i].g, 1, 1);
   1.138 -                SDL_RWread (src, &palette->colors[i].r, 1, 1);
   1.139 -                SDL_RWread (src, &palette->colors[i].unused, 1, 1);
   1.140 +                SDL_RWread(src, &palette->colors[i].b, 1, 1);
   1.141 +                SDL_RWread(src, &palette->colors[i].g, 1, 1);
   1.142 +                SDL_RWread(src, &palette->colors[i].r, 1, 1);
   1.143 +                SDL_RWread(src, &palette->colors[i].unused, 1, 1);
   1.144              }
   1.145          }
   1.146          palette->ncolors = biClrUsed;
   1.147      }
   1.148  
   1.149      /* Read the surface pixels.  Note that the bmp image is upside down */
   1.150 -    if (SDL_RWseek (src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
   1.151 -        SDL_Error (SDL_EFSEEK);
   1.152 +    if (SDL_RWseek(src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
   1.153 +        SDL_Error(SDL_EFSEEK);
   1.154          was_error = 1;
   1.155          goto done;
   1.156      }
   1.157 @@ -265,8 +265,8 @@
   1.158                  int shift = (8 - ExpandBMP);
   1.159                  for (i = 0; i < surface->w; ++i) {
   1.160                      if (i % (8 / ExpandBMP) == 0) {
   1.161 -                        if (!SDL_RWread (src, &pixel, 1, 1)) {
   1.162 -                            SDL_SetError ("Error reading from BMP");
   1.163 +                        if (!SDL_RWread(src, &pixel, 1, 1)) {
   1.164 +                            SDL_SetError("Error reading from BMP");
   1.165                              was_error = 1;
   1.166                              goto done;
   1.167                          }
   1.168 @@ -278,9 +278,9 @@
   1.169              break;
   1.170  
   1.171          default:
   1.172 -            if (SDL_RWread (src, bits, 1, surface->pitch)
   1.173 +            if (SDL_RWread(src, bits, 1, surface->pitch)
   1.174                  != surface->pitch) {
   1.175 -                SDL_Error (SDL_EFREAD);
   1.176 +                SDL_Error(SDL_EFREAD);
   1.177                  was_error = 1;
   1.178                  goto done;
   1.179              }
   1.180 @@ -293,7 +293,7 @@
   1.181                  {
   1.182                      Uint16 *pix = (Uint16 *) bits;
   1.183                      for (i = 0; i < surface->w; i++)
   1.184 -                        pix[i] = SDL_Swap16 (pix[i]);
   1.185 +                        pix[i] = SDL_Swap16(pix[i]);
   1.186                      break;
   1.187                  }
   1.188  
   1.189 @@ -301,7 +301,7 @@
   1.190                  {
   1.191                      Uint32 *pix = (Uint32 *) bits;
   1.192                      for (i = 0; i < surface->w; i++)
   1.193 -                        pix[i] = SDL_Swap32 (pix[i]);
   1.194 +                        pix[i] = SDL_Swap32(pix[i]);
   1.195                      break;
   1.196                  }
   1.197              }
   1.198 @@ -312,28 +312,28 @@
   1.199          if (pad) {
   1.200              Uint8 padbyte;
   1.201              for (i = 0; i < pad; ++i) {
   1.202 -                SDL_RWread (src, &padbyte, 1, 1);
   1.203 +                SDL_RWread(src, &padbyte, 1, 1);
   1.204              }
   1.205          }
   1.206      }
   1.207    done:
   1.208      if (was_error) {
   1.209          if (src) {
   1.210 -            SDL_RWseek (src, fp_offset, RW_SEEK_SET);
   1.211 +            SDL_RWseek(src, fp_offset, RW_SEEK_SET);
   1.212          }
   1.213          if (surface) {
   1.214 -            SDL_FreeSurface (surface);
   1.215 +            SDL_FreeSurface(surface);
   1.216          }
   1.217          surface = NULL;
   1.218      }
   1.219      if (freesrc && src) {
   1.220 -        SDL_RWclose (src);
   1.221 +        SDL_RWclose(src);
   1.222      }
   1.223      return (surface);
   1.224  }
   1.225  
   1.226  int
   1.227 -SDL_SaveBMP_RW (SDL_Surface * saveme, SDL_RWops * dst, int freedst)
   1.228 +SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
   1.229  {
   1.230      long fp_offset;
   1.231      int i, pad;
   1.232 @@ -367,8 +367,8 @@
   1.233              if (saveme->format->BitsPerPixel == 8) {
   1.234                  surface = saveme;
   1.235              } else {
   1.236 -                SDL_SetError ("%d bpp BMP files not supported",
   1.237 -                              saveme->format->BitsPerPixel);
   1.238 +                SDL_SetError("%d bpp BMP files not supported",
   1.239 +                             saveme->format->BitsPerPixel);
   1.240              }
   1.241          } else if ((saveme->format->BitsPerPixel == 24) &&
   1.242  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.243 @@ -386,31 +386,29 @@
   1.244              SDL_Rect bounds;
   1.245  
   1.246              /* Convert to 24 bits per pixel */
   1.247 -            surface = SDL_CreateRGBSurface (SDL_SWSURFACE,
   1.248 -                                            saveme->w, saveme->h, 24,
   1.249 +            surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   1.250 +                                           saveme->w, saveme->h, 24,
   1.251  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.252 -                                            0x00FF0000, 0x0000FF00,
   1.253 -                                            0x000000FF,
   1.254 +                                           0x00FF0000, 0x0000FF00, 0x000000FF,
   1.255  #else
   1.256 -                                            0x000000FF, 0x0000FF00,
   1.257 -                                            0x00FF0000,
   1.258 +                                           0x000000FF, 0x0000FF00, 0x00FF0000,
   1.259  #endif
   1.260 -                                            0);
   1.261 +                                           0);
   1.262              if (surface != NULL) {
   1.263                  bounds.x = 0;
   1.264                  bounds.y = 0;
   1.265                  bounds.w = saveme->w;
   1.266                  bounds.h = saveme->h;
   1.267 -                if (SDL_LowerBlit (saveme, &bounds, surface, &bounds) < 0) {
   1.268 -                    SDL_FreeSurface (surface);
   1.269 -                    SDL_SetError ("Couldn't convert image to 24 bpp");
   1.270 +                if (SDL_LowerBlit(saveme, &bounds, surface, &bounds) < 0) {
   1.271 +                    SDL_FreeSurface(surface);
   1.272 +                    SDL_SetError("Couldn't convert image to 24 bpp");
   1.273                      surface = NULL;
   1.274                  }
   1.275              }
   1.276          }
   1.277      }
   1.278  
   1.279 -    if (surface && (SDL_LockSurface (surface) == 0)) {
   1.280 +    if (surface && (SDL_LockSurface(surface) == 0)) {
   1.281          const int bw = surface->w * surface->format->BytesPerPixel;
   1.282  
   1.283          /* Set the BMP file header values */
   1.284 @@ -420,13 +418,13 @@
   1.285          bfOffBits = 0;          /* We'll write this when we're done */
   1.286  
   1.287          /* Write the BMP file header values */
   1.288 -        fp_offset = SDL_RWtell (dst);
   1.289 -        SDL_ClearError ();
   1.290 -        SDL_RWwrite (dst, magic, 2, 1);
   1.291 -        SDL_WriteLE32 (dst, bfSize);
   1.292 -        SDL_WriteLE16 (dst, bfReserved1);
   1.293 -        SDL_WriteLE16 (dst, bfReserved2);
   1.294 -        SDL_WriteLE32 (dst, bfOffBits);
   1.295 +        fp_offset = SDL_RWtell(dst);
   1.296 +        SDL_ClearError();
   1.297 +        SDL_RWwrite(dst, magic, 2, 1);
   1.298 +        SDL_WriteLE32(dst, bfSize);
   1.299 +        SDL_WriteLE16(dst, bfReserved1);
   1.300 +        SDL_WriteLE16(dst, bfReserved2);
   1.301 +        SDL_WriteLE32(dst, bfOffBits);
   1.302  
   1.303          /* Set the BMP info values */
   1.304          biSize = 40;
   1.305 @@ -446,17 +444,17 @@
   1.306          biClrImportant = 0;
   1.307  
   1.308          /* Write the BMP info values */
   1.309 -        SDL_WriteLE32 (dst, biSize);
   1.310 -        SDL_WriteLE32 (dst, biWidth);
   1.311 -        SDL_WriteLE32 (dst, biHeight);
   1.312 -        SDL_WriteLE16 (dst, biPlanes);
   1.313 -        SDL_WriteLE16 (dst, biBitCount);
   1.314 -        SDL_WriteLE32 (dst, biCompression);
   1.315 -        SDL_WriteLE32 (dst, biSizeImage);
   1.316 -        SDL_WriteLE32 (dst, biXPelsPerMeter);
   1.317 -        SDL_WriteLE32 (dst, biYPelsPerMeter);
   1.318 -        SDL_WriteLE32 (dst, biClrUsed);
   1.319 -        SDL_WriteLE32 (dst, biClrImportant);
   1.320 +        SDL_WriteLE32(dst, biSize);
   1.321 +        SDL_WriteLE32(dst, biWidth);
   1.322 +        SDL_WriteLE32(dst, biHeight);
   1.323 +        SDL_WriteLE16(dst, biPlanes);
   1.324 +        SDL_WriteLE16(dst, biBitCount);
   1.325 +        SDL_WriteLE32(dst, biCompression);
   1.326 +        SDL_WriteLE32(dst, biSizeImage);
   1.327 +        SDL_WriteLE32(dst, biXPelsPerMeter);
   1.328 +        SDL_WriteLE32(dst, biYPelsPerMeter);
   1.329 +        SDL_WriteLE32(dst, biClrUsed);
   1.330 +        SDL_WriteLE32(dst, biClrImportant);
   1.331  
   1.332          /* Write the palette (in BGR color order) */
   1.333          if (surface->format->palette) {
   1.334 @@ -466,21 +464,21 @@
   1.335              colors = surface->format->palette->colors;
   1.336              ncolors = surface->format->palette->ncolors;
   1.337              for (i = 0; i < ncolors; ++i) {
   1.338 -                SDL_RWwrite (dst, &colors[i].b, 1, 1);
   1.339 -                SDL_RWwrite (dst, &colors[i].g, 1, 1);
   1.340 -                SDL_RWwrite (dst, &colors[i].r, 1, 1);
   1.341 -                SDL_RWwrite (dst, &colors[i].unused, 1, 1);
   1.342 +                SDL_RWwrite(dst, &colors[i].b, 1, 1);
   1.343 +                SDL_RWwrite(dst, &colors[i].g, 1, 1);
   1.344 +                SDL_RWwrite(dst, &colors[i].r, 1, 1);
   1.345 +                SDL_RWwrite(dst, &colors[i].unused, 1, 1);
   1.346              }
   1.347          }
   1.348  
   1.349          /* Write the bitmap offset */
   1.350 -        bfOffBits = SDL_RWtell (dst) - fp_offset;
   1.351 -        if (SDL_RWseek (dst, fp_offset + 10, RW_SEEK_SET) < 0) {
   1.352 -            SDL_Error (SDL_EFSEEK);
   1.353 +        bfOffBits = SDL_RWtell(dst) - fp_offset;
   1.354 +        if (SDL_RWseek(dst, fp_offset + 10, RW_SEEK_SET) < 0) {
   1.355 +            SDL_Error(SDL_EFSEEK);
   1.356          }
   1.357 -        SDL_WriteLE32 (dst, bfOffBits);
   1.358 -        if (SDL_RWseek (dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
   1.359 -            SDL_Error (SDL_EFSEEK);
   1.360 +        SDL_WriteLE32(dst, bfOffBits);
   1.361 +        if (SDL_RWseek(dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
   1.362 +            SDL_Error(SDL_EFSEEK);
   1.363          }
   1.364  
   1.365          /* Write the bitmap image upside down */
   1.366 @@ -488,39 +486,39 @@
   1.367          pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
   1.368          while (bits > (Uint8 *) surface->pixels) {
   1.369              bits -= surface->pitch;
   1.370 -            if (SDL_RWwrite (dst, bits, 1, bw) != bw) {
   1.371 -                SDL_Error (SDL_EFWRITE);
   1.372 +            if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
   1.373 +                SDL_Error(SDL_EFWRITE);
   1.374                  break;
   1.375              }
   1.376              if (pad) {
   1.377                  const Uint8 padbyte = 0;
   1.378                  for (i = 0; i < pad; ++i) {
   1.379 -                    SDL_RWwrite (dst, &padbyte, 1, 1);
   1.380 +                    SDL_RWwrite(dst, &padbyte, 1, 1);
   1.381                  }
   1.382              }
   1.383          }
   1.384  
   1.385          /* Write the BMP file size */
   1.386 -        bfSize = SDL_RWtell (dst) - fp_offset;
   1.387 -        if (SDL_RWseek (dst, fp_offset + 2, RW_SEEK_SET) < 0) {
   1.388 -            SDL_Error (SDL_EFSEEK);
   1.389 +        bfSize = SDL_RWtell(dst) - fp_offset;
   1.390 +        if (SDL_RWseek(dst, fp_offset + 2, RW_SEEK_SET) < 0) {
   1.391 +            SDL_Error(SDL_EFSEEK);
   1.392          }
   1.393 -        SDL_WriteLE32 (dst, bfSize);
   1.394 -        if (SDL_RWseek (dst, fp_offset + bfSize, RW_SEEK_SET) < 0) {
   1.395 -            SDL_Error (SDL_EFSEEK);
   1.396 +        SDL_WriteLE32(dst, bfSize);
   1.397 +        if (SDL_RWseek(dst, fp_offset + bfSize, RW_SEEK_SET) < 0) {
   1.398 +            SDL_Error(SDL_EFSEEK);
   1.399          }
   1.400  
   1.401          /* Close it up.. */
   1.402 -        SDL_UnlockSurface (surface);
   1.403 +        SDL_UnlockSurface(surface);
   1.404          if (surface != saveme) {
   1.405 -            SDL_FreeSurface (surface);
   1.406 +            SDL_FreeSurface(surface);
   1.407          }
   1.408      }
   1.409  
   1.410      if (freedst && dst) {
   1.411 -        SDL_RWclose (dst);
   1.412 +        SDL_RWclose(dst);
   1.413      }
   1.414 -    return ((SDL_strcmp (SDL_GetError (), "") == 0) ? 0 : -1);
   1.415 +    return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
   1.416  }
   1.417  
   1.418  /* vi: set ts=4 sw=4 expandtab: */