summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2004-12-14 06:20:49 +0000
committerSam Lantinga <slouken@libsdl.org>2004-12-14 06:20:49 +0000
commitdcb2b7a7ae86d42ff4ea67dad9e342c821e82e06 (patch)
tree0515622687c4ebf4064deae7d8247267c2c29e36
parent5df19e723b0dfeb7ffd321fd955e56f9f9202fbf (diff)
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).
-rw-r--r--src/video/SDL_bmp.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index ea87af5715..59d032aa14 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -413,6 +413,8 @@ int SDL_SaveBMP_RW (SDL_Surface *saveme, SDL_RWops *dst, int freedst)
}
if ( surface && (SDL_LockSurface(surface) == 0) ) {
+ const int bw = surface->w*surface->format->BytesPerPixel;
+
/* Set the BMP file header values */
bfSize = 0; /* We'll write this when we're done */
bfReserved1 = 0;
@@ -485,11 +487,10 @@ int SDL_SaveBMP_RW (SDL_Surface *saveme, SDL_RWops *dst, int freedst)
/* Write the bitmap image upside down */
bits = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
- pad = ((surface->pitch%4) ? (4-(surface->pitch%4)) : 0);
+ pad = ((bw%4) ? (4-(bw%4)) : 0);
while ( bits > (Uint8 *)surface->pixels ) {
bits -= surface->pitch;
- if ( SDL_RWwrite(dst, bits, 1, surface->pitch)
- != surface->pitch) {
+ if ( SDL_RWwrite(dst, bits, 1, bw) != bw) {
SDL_Error(SDL_EFWRITE);
break;
}