comparison src/video/SDL_bmp.c @ 1012:f14e3059e138

Date: Mon, 13 Dec 2004 21:28:18 -0500 From: Jonathan Atkins Subject: [SDL] SDL_SaveBMP width bugfix this fixes the pitch versus width difference that can happen (especially for 8bit and 24bit (with the exact RGBAmasks) surfaces) when you use SDL_SaveBMP. The problem was the pitch was used instead of the width, which in some cases is much wider than the screen area you really want to save...making for ugly crud on the saved image borders. This code has been tested with & without pitch overhangs...and with the right masks for 24 bit surfaces. I tested 8,15,16,24,32-0RGB,32-RGBA(with no SDL_SRCALPHA flag).
author Sam Lantinga <slouken@libsdl.org>
date Tue, 14 Dec 2004 06:20:49 +0000
parents b8d311d90021
children c9b51268668f
comparison
equal deleted inserted replaced
1011:4095d9ca23f2 1012:f14e3059e138
411 } 411 }
412 } 412 }
413 } 413 }
414 414
415 if ( surface && (SDL_LockSurface(surface) == 0) ) { 415 if ( surface && (SDL_LockSurface(surface) == 0) ) {
416 const int bw = surface->w*surface->format->BytesPerPixel;
417
416 /* Set the BMP file header values */ 418 /* Set the BMP file header values */
417 bfSize = 0; /* We'll write this when we're done */ 419 bfSize = 0; /* We'll write this when we're done */
418 bfReserved1 = 0; 420 bfReserved1 = 0;
419 bfReserved2 = 0; 421 bfReserved2 = 0;
420 bfOffBits = 0; /* We'll write this when we're done */ 422 bfOffBits = 0; /* We'll write this when we're done */
483 SDL_Error(SDL_EFSEEK); 485 SDL_Error(SDL_EFSEEK);
484 } 486 }
485 487
486 /* Write the bitmap image upside down */ 488 /* Write the bitmap image upside down */
487 bits = (Uint8 *)surface->pixels+(surface->h*surface->pitch); 489 bits = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
488 pad = ((surface->pitch%4) ? (4-(surface->pitch%4)) : 0); 490 pad = ((bw%4) ? (4-(bw%4)) : 0);
489 while ( bits > (Uint8 *)surface->pixels ) { 491 while ( bits > (Uint8 *)surface->pixels ) {
490 bits -= surface->pitch; 492 bits -= surface->pitch;
491 if ( SDL_RWwrite(dst, bits, 1, surface->pitch) 493 if ( SDL_RWwrite(dst, bits, 1, bw) != bw) {
492 != surface->pitch) {
493 SDL_Error(SDL_EFWRITE); 494 SDL_Error(SDL_EFWRITE);
494 break; 495 break;
495 } 496 }
496 if ( pad ) { 497 if ( pad ) {
497 const Uint8 padbyte = 0; 498 const Uint8 padbyte = 0;