[SDL] Extra bytes at the end of rows on surfaces
Christian Walther
cwalther at gmx.ch
Sun Jan 14 01:57:00 PST 2007
Mike Powell wrote:
>
> uint32 srcPixel =
> *(uint32*)((uint8*)surf->pixels+(i*surf->format->BytesPerPixel));
>
> ...
>
> However, I remain rather confused why this extra byte is appearing
> there. I've used SDL_Image to load images for a lot of projects in
> the past, and I've experienced this padding before. Does anybody know
> what could cause that?
Usually rows are padded to a multiple of 4 bytes because 4-byte-aligned
stuff is what the usual 32-bit processors can access most efficiently.
But don't rely on that number, rows may be padded to any length. The
proper way to deal with this is to use the "pitch" field: Pixel (x,y) is
located at (Uint8*)surf->pixels + y*surf->pitch +
x*surf->format->bytesPerPixel.
-Christian
More information about the SDL
mailing list