Skip to content

Commit

Permalink
Fixed bug 4785 - SDL_CreateRGBSurface creates 1-bit surfaces with zer…
Browse files Browse the repository at this point in the history
…o pitch

Sylvain

Seems to be a regression in this commit: https://hg.libsdl.org/SDL/rev/7fdbffd47c0e
SDL_CalculatePitch() was using format->BytesPerPixel, now it uses SDL_BYTESPERPIXEL().

The underlying issue is that "surface->format->BytesPerPixel" is *not* always the same as SDL_BYTESPERPIXEL(format);
BytesPerPixel defined as format->BytesPerPixel = (bpp + 7) / 8;
vs
#define SDL_BYTESPERPIXEL(format)  ... (format & 0xff)

Because of SDL_pixels.h format definitions, one is giving a BytesPP 1, the other 0.
  • Loading branch information
slouken committed Oct 16, 2019
1 parent ed7483f commit 1b4de45
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/video/SDL_surface.c
Expand Up @@ -42,19 +42,12 @@ SDL_CalculatePitch(Uint32 format, int width)
{
int pitch;

/* Surface should be 4-byte aligned for speed */
pitch = width * SDL_BYTESPERPIXEL(format);
switch (SDL_BITSPERPIXEL(format)) {
case 1:
pitch = (pitch + 7) / 8;
break;
case 4:
pitch = (pitch + 1) / 2;
break;
default:
break;
}
pitch = (pitch + 3) & ~3; /* 4-byte aligning */
if (SDL_ISPIXELFORMAT_FOURCC(format) || SDL_BITSPERPIXEL(format) >= 8) {
pitch = (width * SDL_BYTESPERPIXEL(format));
} else {
pitch = ((width * SDL_BITSPERPIXEL(format)) + 7) / 8;
}
pitch = (pitch + 3) & ~3; /* 4-byte aligning for speed */
return pitch;
}

Expand Down

0 comments on commit 1b4de45

Please sign in to comment.