Mercurial > sdl-ios-xcode
comparison src/video/SDL_bmp.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children | eef792d31de8 |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
44 #define BI_BITFIELDS 3 | 44 #define BI_BITFIELDS 3 |
45 #endif | 45 #endif |
46 | 46 |
47 | 47 |
48 SDL_Surface * | 48 SDL_Surface * |
49 SDL_LoadBMP_RW (SDL_RWops * src, int freesrc) | 49 SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) |
50 { | 50 { |
51 int was_error; | 51 int was_error; |
52 long fp_offset; | 52 long fp_offset; |
53 int bmpPitch; | 53 int bmpPitch; |
54 int i, pad; | 54 int i, pad; |
87 was_error = 1; | 87 was_error = 1; |
88 goto done; | 88 goto done; |
89 } | 89 } |
90 | 90 |
91 /* Read in the BMP file header */ | 91 /* Read in the BMP file header */ |
92 fp_offset = SDL_RWtell (src); | 92 fp_offset = SDL_RWtell(src); |
93 SDL_ClearError (); | 93 SDL_ClearError(); |
94 if (SDL_RWread (src, magic, 1, 2) != 2) { | 94 if (SDL_RWread(src, magic, 1, 2) != 2) { |
95 SDL_Error (SDL_EFREAD); | 95 SDL_Error(SDL_EFREAD); |
96 was_error = 1; | 96 was_error = 1; |
97 goto done; | 97 goto done; |
98 } | 98 } |
99 if (SDL_strncmp (magic, "BM", 2) != 0) { | 99 if (SDL_strncmp(magic, "BM", 2) != 0) { |
100 SDL_SetError ("File is not a Windows BMP file"); | 100 SDL_SetError("File is not a Windows BMP file"); |
101 was_error = 1; | 101 was_error = 1; |
102 goto done; | 102 goto done; |
103 } | 103 } |
104 bfSize = SDL_ReadLE32 (src); | 104 bfSize = SDL_ReadLE32(src); |
105 bfReserved1 = SDL_ReadLE16 (src); | 105 bfReserved1 = SDL_ReadLE16(src); |
106 bfReserved2 = SDL_ReadLE16 (src); | 106 bfReserved2 = SDL_ReadLE16(src); |
107 bfOffBits = SDL_ReadLE32 (src); | 107 bfOffBits = SDL_ReadLE32(src); |
108 | 108 |
109 /* Read the Win32 BITMAPINFOHEADER */ | 109 /* Read the Win32 BITMAPINFOHEADER */ |
110 biSize = SDL_ReadLE32 (src); | 110 biSize = SDL_ReadLE32(src); |
111 if (biSize == 12) { | 111 if (biSize == 12) { |
112 biWidth = (Uint32) SDL_ReadLE16 (src); | 112 biWidth = (Uint32) SDL_ReadLE16(src); |
113 biHeight = (Uint32) SDL_ReadLE16 (src); | 113 biHeight = (Uint32) SDL_ReadLE16(src); |
114 biPlanes = SDL_ReadLE16 (src); | 114 biPlanes = SDL_ReadLE16(src); |
115 biBitCount = SDL_ReadLE16 (src); | 115 biBitCount = SDL_ReadLE16(src); |
116 biCompression = BI_RGB; | 116 biCompression = BI_RGB; |
117 biSizeImage = 0; | 117 biSizeImage = 0; |
118 biXPelsPerMeter = 0; | 118 biXPelsPerMeter = 0; |
119 biYPelsPerMeter = 0; | 119 biYPelsPerMeter = 0; |
120 biClrUsed = 0; | 120 biClrUsed = 0; |
121 biClrImportant = 0; | 121 biClrImportant = 0; |
122 } else { | 122 } else { |
123 biWidth = SDL_ReadLE32 (src); | 123 biWidth = SDL_ReadLE32(src); |
124 biHeight = SDL_ReadLE32 (src); | 124 biHeight = SDL_ReadLE32(src); |
125 biPlanes = SDL_ReadLE16 (src); | 125 biPlanes = SDL_ReadLE16(src); |
126 biBitCount = SDL_ReadLE16 (src); | 126 biBitCount = SDL_ReadLE16(src); |
127 biCompression = SDL_ReadLE32 (src); | 127 biCompression = SDL_ReadLE32(src); |
128 biSizeImage = SDL_ReadLE32 (src); | 128 biSizeImage = SDL_ReadLE32(src); |
129 biXPelsPerMeter = SDL_ReadLE32 (src); | 129 biXPelsPerMeter = SDL_ReadLE32(src); |
130 biYPelsPerMeter = SDL_ReadLE32 (src); | 130 biYPelsPerMeter = SDL_ReadLE32(src); |
131 biClrUsed = SDL_ReadLE32 (src); | 131 biClrUsed = SDL_ReadLE32(src); |
132 biClrImportant = SDL_ReadLE32 (src); | 132 biClrImportant = SDL_ReadLE32(src); |
133 } | 133 } |
134 | 134 |
135 /* Check for read error */ | 135 /* Check for read error */ |
136 if (SDL_strcmp (SDL_GetError (), "") != 0) { | 136 if (SDL_strcmp(SDL_GetError(), "") != 0) { |
137 was_error = 1; | 137 was_error = 1; |
138 goto done; | 138 goto done; |
139 } | 139 } |
140 | 140 |
141 /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */ | 141 /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */ |
186 case BI_BITFIELDS: | 186 case BI_BITFIELDS: |
187 switch (biBitCount) { | 187 switch (biBitCount) { |
188 case 15: | 188 case 15: |
189 case 16: | 189 case 16: |
190 case 32: | 190 case 32: |
191 Rmask = SDL_ReadLE32 (src); | 191 Rmask = SDL_ReadLE32(src); |
192 Gmask = SDL_ReadLE32 (src); | 192 Gmask = SDL_ReadLE32(src); |
193 Bmask = SDL_ReadLE32 (src); | 193 Bmask = SDL_ReadLE32(src); |
194 break; | 194 break; |
195 default: | 195 default: |
196 break; | 196 break; |
197 } | 197 } |
198 break; | 198 break; |
199 default: | 199 default: |
200 SDL_SetError ("Compressed BMP files not supported"); | 200 SDL_SetError("Compressed BMP files not supported"); |
201 was_error = 1; | 201 was_error = 1; |
202 goto done; | 202 goto done; |
203 } | 203 } |
204 | 204 |
205 /* Create a compatible surface, note that the colors are RGB ordered */ | 205 /* Create a compatible surface, note that the colors are RGB ordered */ |
206 surface = SDL_CreateRGBSurface (SDL_SWSURFACE, | 206 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, |
207 biWidth, biHeight, biBitCount, Rmask, | 207 biWidth, biHeight, biBitCount, Rmask, |
208 Gmask, Bmask, 0); | 208 Gmask, Bmask, 0); |
209 if (surface == NULL) { | 209 if (surface == NULL) { |
210 was_error = 1; | 210 was_error = 1; |
211 goto done; | 211 goto done; |
212 } | 212 } |
213 | 213 |
217 if (biClrUsed == 0) { | 217 if (biClrUsed == 0) { |
218 biClrUsed = 1 << biBitCount; | 218 biClrUsed = 1 << biBitCount; |
219 } | 219 } |
220 if (biSize == 12) { | 220 if (biSize == 12) { |
221 for (i = 0; i < (int) biClrUsed; ++i) { | 221 for (i = 0; i < (int) biClrUsed; ++i) { |
222 SDL_RWread (src, &palette->colors[i].b, 1, 1); | 222 SDL_RWread(src, &palette->colors[i].b, 1, 1); |
223 SDL_RWread (src, &palette->colors[i].g, 1, 1); | 223 SDL_RWread(src, &palette->colors[i].g, 1, 1); |
224 SDL_RWread (src, &palette->colors[i].r, 1, 1); | 224 SDL_RWread(src, &palette->colors[i].r, 1, 1); |
225 palette->colors[i].unused = 0; | 225 palette->colors[i].unused = 0; |
226 } | 226 } |
227 } else { | 227 } else { |
228 for (i = 0; i < (int) biClrUsed; ++i) { | 228 for (i = 0; i < (int) biClrUsed; ++i) { |
229 SDL_RWread (src, &palette->colors[i].b, 1, 1); | 229 SDL_RWread(src, &palette->colors[i].b, 1, 1); |
230 SDL_RWread (src, &palette->colors[i].g, 1, 1); | 230 SDL_RWread(src, &palette->colors[i].g, 1, 1); |
231 SDL_RWread (src, &palette->colors[i].r, 1, 1); | 231 SDL_RWread(src, &palette->colors[i].r, 1, 1); |
232 SDL_RWread (src, &palette->colors[i].unused, 1, 1); | 232 SDL_RWread(src, &palette->colors[i].unused, 1, 1); |
233 } | 233 } |
234 } | 234 } |
235 palette->ncolors = biClrUsed; | 235 palette->ncolors = biClrUsed; |
236 } | 236 } |
237 | 237 |
238 /* Read the surface pixels. Note that the bmp image is upside down */ | 238 /* Read the surface pixels. Note that the bmp image is upside down */ |
239 if (SDL_RWseek (src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) { | 239 if (SDL_RWseek(src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) { |
240 SDL_Error (SDL_EFSEEK); | 240 SDL_Error(SDL_EFSEEK); |
241 was_error = 1; | 241 was_error = 1; |
242 goto done; | 242 goto done; |
243 } | 243 } |
244 bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch); | 244 bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch); |
245 switch (ExpandBMP) { | 245 switch (ExpandBMP) { |
263 { | 263 { |
264 Uint8 pixel = 0; | 264 Uint8 pixel = 0; |
265 int shift = (8 - ExpandBMP); | 265 int shift = (8 - ExpandBMP); |
266 for (i = 0; i < surface->w; ++i) { | 266 for (i = 0; i < surface->w; ++i) { |
267 if (i % (8 / ExpandBMP) == 0) { | 267 if (i % (8 / ExpandBMP) == 0) { |
268 if (!SDL_RWread (src, &pixel, 1, 1)) { | 268 if (!SDL_RWread(src, &pixel, 1, 1)) { |
269 SDL_SetError ("Error reading from BMP"); | 269 SDL_SetError("Error reading from BMP"); |
270 was_error = 1; | 270 was_error = 1; |
271 goto done; | 271 goto done; |
272 } | 272 } |
273 } | 273 } |
274 *(bits + i) = (pixel >> shift); | 274 *(bits + i) = (pixel >> shift); |
276 } | 276 } |
277 } | 277 } |
278 break; | 278 break; |
279 | 279 |
280 default: | 280 default: |
281 if (SDL_RWread (src, bits, 1, surface->pitch) | 281 if (SDL_RWread(src, bits, 1, surface->pitch) |
282 != surface->pitch) { | 282 != surface->pitch) { |
283 SDL_Error (SDL_EFREAD); | 283 SDL_Error(SDL_EFREAD); |
284 was_error = 1; | 284 was_error = 1; |
285 goto done; | 285 goto done; |
286 } | 286 } |
287 #if SDL_BYTEORDER == SDL_BIG_ENDIAN | 287 #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
288 /* Byte-swap the pixels if needed. Note that the 24bpp | 288 /* Byte-swap the pixels if needed. Note that the 24bpp |
291 case 15: | 291 case 15: |
292 case 16: | 292 case 16: |
293 { | 293 { |
294 Uint16 *pix = (Uint16 *) bits; | 294 Uint16 *pix = (Uint16 *) bits; |
295 for (i = 0; i < surface->w; i++) | 295 for (i = 0; i < surface->w; i++) |
296 pix[i] = SDL_Swap16 (pix[i]); | 296 pix[i] = SDL_Swap16(pix[i]); |
297 break; | 297 break; |
298 } | 298 } |
299 | 299 |
300 case 32: | 300 case 32: |
301 { | 301 { |
302 Uint32 *pix = (Uint32 *) bits; | 302 Uint32 *pix = (Uint32 *) bits; |
303 for (i = 0; i < surface->w; i++) | 303 for (i = 0; i < surface->w; i++) |
304 pix[i] = SDL_Swap32 (pix[i]); | 304 pix[i] = SDL_Swap32(pix[i]); |
305 break; | 305 break; |
306 } | 306 } |
307 } | 307 } |
308 #endif | 308 #endif |
309 break; | 309 break; |
310 } | 310 } |
311 /* Skip padding bytes, ugh */ | 311 /* Skip padding bytes, ugh */ |
312 if (pad) { | 312 if (pad) { |
313 Uint8 padbyte; | 313 Uint8 padbyte; |
314 for (i = 0; i < pad; ++i) { | 314 for (i = 0; i < pad; ++i) { |
315 SDL_RWread (src, &padbyte, 1, 1); | 315 SDL_RWread(src, &padbyte, 1, 1); |
316 } | 316 } |
317 } | 317 } |
318 } | 318 } |
319 done: | 319 done: |
320 if (was_error) { | 320 if (was_error) { |
321 if (src) { | 321 if (src) { |
322 SDL_RWseek (src, fp_offset, RW_SEEK_SET); | 322 SDL_RWseek(src, fp_offset, RW_SEEK_SET); |
323 } | 323 } |
324 if (surface) { | 324 if (surface) { |
325 SDL_FreeSurface (surface); | 325 SDL_FreeSurface(surface); |
326 } | 326 } |
327 surface = NULL; | 327 surface = NULL; |
328 } | 328 } |
329 if (freesrc && src) { | 329 if (freesrc && src) { |
330 SDL_RWclose (src); | 330 SDL_RWclose(src); |
331 } | 331 } |
332 return (surface); | 332 return (surface); |
333 } | 333 } |
334 | 334 |
335 int | 335 int |
336 SDL_SaveBMP_RW (SDL_Surface * saveme, SDL_RWops * dst, int freedst) | 336 SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst) |
337 { | 337 { |
338 long fp_offset; | 338 long fp_offset; |
339 int i, pad; | 339 int i, pad; |
340 SDL_Surface *surface; | 340 SDL_Surface *surface; |
341 Uint8 *bits; | 341 Uint8 *bits; |
365 if (dst) { | 365 if (dst) { |
366 if (saveme->format->palette) { | 366 if (saveme->format->palette) { |
367 if (saveme->format->BitsPerPixel == 8) { | 367 if (saveme->format->BitsPerPixel == 8) { |
368 surface = saveme; | 368 surface = saveme; |
369 } else { | 369 } else { |
370 SDL_SetError ("%d bpp BMP files not supported", | 370 SDL_SetError("%d bpp BMP files not supported", |
371 saveme->format->BitsPerPixel); | 371 saveme->format->BitsPerPixel); |
372 } | 372 } |
373 } else if ((saveme->format->BitsPerPixel == 24) && | 373 } else if ((saveme->format->BitsPerPixel == 24) && |
374 #if SDL_BYTEORDER == SDL_LIL_ENDIAN | 374 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
375 (saveme->format->Rmask == 0x00FF0000) && | 375 (saveme->format->Rmask == 0x00FF0000) && |
376 (saveme->format->Gmask == 0x0000FF00) && | 376 (saveme->format->Gmask == 0x0000FF00) && |
384 surface = saveme; | 384 surface = saveme; |
385 } else { | 385 } else { |
386 SDL_Rect bounds; | 386 SDL_Rect bounds; |
387 | 387 |
388 /* Convert to 24 bits per pixel */ | 388 /* Convert to 24 bits per pixel */ |
389 surface = SDL_CreateRGBSurface (SDL_SWSURFACE, | 389 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, |
390 saveme->w, saveme->h, 24, | 390 saveme->w, saveme->h, 24, |
391 #if SDL_BYTEORDER == SDL_LIL_ENDIAN | 391 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
392 0x00FF0000, 0x0000FF00, | 392 0x00FF0000, 0x0000FF00, 0x000000FF, |
393 0x000000FF, | |
394 #else | 393 #else |
395 0x000000FF, 0x0000FF00, | 394 0x000000FF, 0x0000FF00, 0x00FF0000, |
396 0x00FF0000, | |
397 #endif | 395 #endif |
398 0); | 396 0); |
399 if (surface != NULL) { | 397 if (surface != NULL) { |
400 bounds.x = 0; | 398 bounds.x = 0; |
401 bounds.y = 0; | 399 bounds.y = 0; |
402 bounds.w = saveme->w; | 400 bounds.w = saveme->w; |
403 bounds.h = saveme->h; | 401 bounds.h = saveme->h; |
404 if (SDL_LowerBlit (saveme, &bounds, surface, &bounds) < 0) { | 402 if (SDL_LowerBlit(saveme, &bounds, surface, &bounds) < 0) { |
405 SDL_FreeSurface (surface); | 403 SDL_FreeSurface(surface); |
406 SDL_SetError ("Couldn't convert image to 24 bpp"); | 404 SDL_SetError("Couldn't convert image to 24 bpp"); |
407 surface = NULL; | 405 surface = NULL; |
408 } | 406 } |
409 } | 407 } |
410 } | 408 } |
411 } | 409 } |
412 | 410 |
413 if (surface && (SDL_LockSurface (surface) == 0)) { | 411 if (surface && (SDL_LockSurface(surface) == 0)) { |
414 const int bw = surface->w * surface->format->BytesPerPixel; | 412 const int bw = surface->w * surface->format->BytesPerPixel; |
415 | 413 |
416 /* Set the BMP file header values */ | 414 /* Set the BMP file header values */ |
417 bfSize = 0; /* We'll write this when we're done */ | 415 bfSize = 0; /* We'll write this when we're done */ |
418 bfReserved1 = 0; | 416 bfReserved1 = 0; |
419 bfReserved2 = 0; | 417 bfReserved2 = 0; |
420 bfOffBits = 0; /* We'll write this when we're done */ | 418 bfOffBits = 0; /* We'll write this when we're done */ |
421 | 419 |
422 /* Write the BMP file header values */ | 420 /* Write the BMP file header values */ |
423 fp_offset = SDL_RWtell (dst); | 421 fp_offset = SDL_RWtell(dst); |
424 SDL_ClearError (); | 422 SDL_ClearError(); |
425 SDL_RWwrite (dst, magic, 2, 1); | 423 SDL_RWwrite(dst, magic, 2, 1); |
426 SDL_WriteLE32 (dst, bfSize); | 424 SDL_WriteLE32(dst, bfSize); |
427 SDL_WriteLE16 (dst, bfReserved1); | 425 SDL_WriteLE16(dst, bfReserved1); |
428 SDL_WriteLE16 (dst, bfReserved2); | 426 SDL_WriteLE16(dst, bfReserved2); |
429 SDL_WriteLE32 (dst, bfOffBits); | 427 SDL_WriteLE32(dst, bfOffBits); |
430 | 428 |
431 /* Set the BMP info values */ | 429 /* Set the BMP info values */ |
432 biSize = 40; | 430 biSize = 40; |
433 biWidth = surface->w; | 431 biWidth = surface->w; |
434 biHeight = surface->h; | 432 biHeight = surface->h; |
444 biClrUsed = 0; | 442 biClrUsed = 0; |
445 } | 443 } |
446 biClrImportant = 0; | 444 biClrImportant = 0; |
447 | 445 |
448 /* Write the BMP info values */ | 446 /* Write the BMP info values */ |
449 SDL_WriteLE32 (dst, biSize); | 447 SDL_WriteLE32(dst, biSize); |
450 SDL_WriteLE32 (dst, biWidth); | 448 SDL_WriteLE32(dst, biWidth); |
451 SDL_WriteLE32 (dst, biHeight); | 449 SDL_WriteLE32(dst, biHeight); |
452 SDL_WriteLE16 (dst, biPlanes); | 450 SDL_WriteLE16(dst, biPlanes); |
453 SDL_WriteLE16 (dst, biBitCount); | 451 SDL_WriteLE16(dst, biBitCount); |
454 SDL_WriteLE32 (dst, biCompression); | 452 SDL_WriteLE32(dst, biCompression); |
455 SDL_WriteLE32 (dst, biSizeImage); | 453 SDL_WriteLE32(dst, biSizeImage); |
456 SDL_WriteLE32 (dst, biXPelsPerMeter); | 454 SDL_WriteLE32(dst, biXPelsPerMeter); |
457 SDL_WriteLE32 (dst, biYPelsPerMeter); | 455 SDL_WriteLE32(dst, biYPelsPerMeter); |
458 SDL_WriteLE32 (dst, biClrUsed); | 456 SDL_WriteLE32(dst, biClrUsed); |
459 SDL_WriteLE32 (dst, biClrImportant); | 457 SDL_WriteLE32(dst, biClrImportant); |
460 | 458 |
461 /* Write the palette (in BGR color order) */ | 459 /* Write the palette (in BGR color order) */ |
462 if (surface->format->palette) { | 460 if (surface->format->palette) { |
463 SDL_Color *colors; | 461 SDL_Color *colors; |
464 int ncolors; | 462 int ncolors; |
465 | 463 |
466 colors = surface->format->palette->colors; | 464 colors = surface->format->palette->colors; |
467 ncolors = surface->format->palette->ncolors; | 465 ncolors = surface->format->palette->ncolors; |
468 for (i = 0; i < ncolors; ++i) { | 466 for (i = 0; i < ncolors; ++i) { |
469 SDL_RWwrite (dst, &colors[i].b, 1, 1); | 467 SDL_RWwrite(dst, &colors[i].b, 1, 1); |
470 SDL_RWwrite (dst, &colors[i].g, 1, 1); | 468 SDL_RWwrite(dst, &colors[i].g, 1, 1); |
471 SDL_RWwrite (dst, &colors[i].r, 1, 1); | 469 SDL_RWwrite(dst, &colors[i].r, 1, 1); |
472 SDL_RWwrite (dst, &colors[i].unused, 1, 1); | 470 SDL_RWwrite(dst, &colors[i].unused, 1, 1); |
473 } | 471 } |
474 } | 472 } |
475 | 473 |
476 /* Write the bitmap offset */ | 474 /* Write the bitmap offset */ |
477 bfOffBits = SDL_RWtell (dst) - fp_offset; | 475 bfOffBits = SDL_RWtell(dst) - fp_offset; |
478 if (SDL_RWseek (dst, fp_offset + 10, RW_SEEK_SET) < 0) { | 476 if (SDL_RWseek(dst, fp_offset + 10, RW_SEEK_SET) < 0) { |
479 SDL_Error (SDL_EFSEEK); | 477 SDL_Error(SDL_EFSEEK); |
480 } | 478 } |
481 SDL_WriteLE32 (dst, bfOffBits); | 479 SDL_WriteLE32(dst, bfOffBits); |
482 if (SDL_RWseek (dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) { | 480 if (SDL_RWseek(dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) { |
483 SDL_Error (SDL_EFSEEK); | 481 SDL_Error(SDL_EFSEEK); |
484 } | 482 } |
485 | 483 |
486 /* Write the bitmap image upside down */ | 484 /* Write the bitmap image upside down */ |
487 bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch); | 485 bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch); |
488 pad = ((bw % 4) ? (4 - (bw % 4)) : 0); | 486 pad = ((bw % 4) ? (4 - (bw % 4)) : 0); |
489 while (bits > (Uint8 *) surface->pixels) { | 487 while (bits > (Uint8 *) surface->pixels) { |
490 bits -= surface->pitch; | 488 bits -= surface->pitch; |
491 if (SDL_RWwrite (dst, bits, 1, bw) != bw) { | 489 if (SDL_RWwrite(dst, bits, 1, bw) != bw) { |
492 SDL_Error (SDL_EFWRITE); | 490 SDL_Error(SDL_EFWRITE); |
493 break; | 491 break; |
494 } | 492 } |
495 if (pad) { | 493 if (pad) { |
496 const Uint8 padbyte = 0; | 494 const Uint8 padbyte = 0; |
497 for (i = 0; i < pad; ++i) { | 495 for (i = 0; i < pad; ++i) { |
498 SDL_RWwrite (dst, &padbyte, 1, 1); | 496 SDL_RWwrite(dst, &padbyte, 1, 1); |
499 } | 497 } |
500 } | 498 } |
501 } | 499 } |
502 | 500 |
503 /* Write the BMP file size */ | 501 /* Write the BMP file size */ |
504 bfSize = SDL_RWtell (dst) - fp_offset; | 502 bfSize = SDL_RWtell(dst) - fp_offset; |
505 if (SDL_RWseek (dst, fp_offset + 2, RW_SEEK_SET) < 0) { | 503 if (SDL_RWseek(dst, fp_offset + 2, RW_SEEK_SET) < 0) { |
506 SDL_Error (SDL_EFSEEK); | 504 SDL_Error(SDL_EFSEEK); |
507 } | 505 } |
508 SDL_WriteLE32 (dst, bfSize); | 506 SDL_WriteLE32(dst, bfSize); |
509 if (SDL_RWseek (dst, fp_offset + bfSize, RW_SEEK_SET) < 0) { | 507 if (SDL_RWseek(dst, fp_offset + bfSize, RW_SEEK_SET) < 0) { |
510 SDL_Error (SDL_EFSEEK); | 508 SDL_Error(SDL_EFSEEK); |
511 } | 509 } |
512 | 510 |
513 /* Close it up.. */ | 511 /* Close it up.. */ |
514 SDL_UnlockSurface (surface); | 512 SDL_UnlockSurface(surface); |
515 if (surface != saveme) { | 513 if (surface != saveme) { |
516 SDL_FreeSurface (surface); | 514 SDL_FreeSurface(surface); |
517 } | 515 } |
518 } | 516 } |
519 | 517 |
520 if (freedst && dst) { | 518 if (freedst && dst) { |
521 SDL_RWclose (dst); | 519 SDL_RWclose(dst); |
522 } | 520 } |
523 return ((SDL_strcmp (SDL_GetError (), "") == 0) ? 0 : -1); | 521 return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1); |
524 } | 522 } |
525 | 523 |
526 /* vi: set ts=4 sw=4 expandtab: */ | 524 /* vi: set ts=4 sw=4 expandtab: */ |