Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_CalculatePitch() too small #562

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

SDL_CalculatePitch() too small #562

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Labels
wontfix This will not be worked on

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 1.2.13
Reported for operating system, platform: Linux, x86

Comments on the original bug report:

On 2010-04-21 00:27:20 +0000, wrote:

SDL_CalculatePitch() switches surface.format->BitsPerPixel.

  1. SDL doesn't allow BitsPerPixel smaller than 8 and cases are 1 and 4, which will never be matched

  2. as surface.pitch is a multiple of 8 bits,1 byte respectively , 1 and 4 BitsPerPixel both result in 1 BytesPerPixel (see SDL_AllocFormat()) and therefore it doesn't make sense to treat them differently considering the byte aligning

  3. to access single pixels via surface.pixels you use at least multiples sizeof(char), so that for a given surface.w insufficient memory is allocated at surface creation: (pitch+7)/8, (pitch+1)/2 (surface.w = 5, 1 BitsPerPixel, 1 BytesPerPixel produces pitch=1 (4 aligned) instead of pitch=5 (8 aligned))

On 2010-04-21 00:30:45 +0000, wrote:

Already mentioned by Sylvain Hellegouarch[1] in 2003, who got poor answers.

[1]http://lists.libsdl.org/pipermail/sdl-libsdl.org/2003-April/034932.html

On 2010-04-23 02:04:30 +0000, Sam Lantinga wrote:

Do you have a specific example of where this is a problem?

The places where I've seen bitmap data used, the pixels are packed in as tightly as possible and the final scanline is aligned on a byte or 4 byte boundary.

To access single pixels, you unpack the bits out of the scanline in order.

For an example, look at the "Bitmap data" section in the BMP file format:
http://en.wikipedia.org/wiki/BMP_file_format

I think what you're talking about is an 8 bpp image with a limited palette.

On 2010-04-24 04:46:56 +0000, wrote:

See example above: when using a 5 pixel-broad surface with 1 bit per pixel 4 bytes instead of 8 are allocated. If you try to manipulate the last $SURFACE_HEIGHT pixels you will run into memory violation, because no memory was allocated for them. With color depth other than 1 and 4 there is no problem (both not allowed by SDL, so that nobody really runs into problems, but the implementation is incorrect nevertheless)

On 2012-01-02 00:09:38 +0000, Sam Lantinga wrote:

If this is actually a problem for someone, please reopen this bug. For now, I'll close it, since I have lots of other things I need to do.

@SDLBugzilla SDLBugzilla added bug wontfix This will not be worked on labels Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant