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_image + libpng load some PNGs incorrectly #460

Closed
Starbuck5 opened this issue Aug 5, 2024 · 4 comments
Closed

SDL_image + libpng load some PNGs incorrectly #460

Starbuck5 opened this issue Aug 5, 2024 · 4 comments

Comments

@Starbuck5
Copy link
Contributor

Starbuck5 commented Aug 5, 2024

Hello, I'm one of the maintainers of pygame-ce. One of our users reported a png file loading incorrectly in their program.

The image:
2_img_broken

image
It should look like the left, but instead loads as the right.

This only seems to be an issue when SDL_image is built with libpng (as we do for distribution with pygame-ce). I tested on an SDL_image prebuilt for Windows (built with stb-image instead), and didn't see this bad output.

I looked into how this might be solved in the libpng code, but the libpng code is extremely difficult to understand. Checking the libpng docs I see that they have a "simplified API" for reading and writing, so I spent 2 days hacking on it and have a draft of using the libpng simple API instead of the older API in SDL2_image: https://github.com/pygame-community/SDL_image/blob/a89d6d9b7069e851bdfeecb15e8cc0de6b4542c6/src/IMG_png.c#L233-L367. That branch is still WIP right now, but wanted to float the idea of potentially moving over to that strategy for libpng. It seems a lot simpler than the other libpng code or even the stb-image code. (And it fixes this issue too)

pygame-ce issue: pygame-community/pygame-ce#3036

@slouken
Copy link
Collaborator

slouken commented Aug 5, 2024

Yes, this looks good to me!

@slouken slouken closed this as completed in 39c8ebb Aug 5, 2024
slouken added a commit that referenced this issue Aug 5, 2024
@slouken
Copy link
Collaborator

slouken commented Aug 5, 2024

Also, I fixed the underlying problem in IMG_png.c

@Starbuck5
Copy link
Contributor Author

Thanks @slouken!

Gave it a run through the pygame-ce test suite and on that image, all worked as expected.

@slouken
Copy link
Collaborator

slouken commented Aug 6, 2024

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants