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

PyGame may load palette .png incorrectly, which breaks ngdevkit tools #96

Open
dciabrin opened this issue Jun 16, 2023 · 0 comments
Open
Assignees
Labels

Comments

@dciabrin
Copy link
Owner

dciabrin commented Jun 16, 2023

tiletool / paltool rely on PyGame (which relies on SDL_image) to load input images transparently, without having to care about the image file format. Currently, it expects a palette-based image but works equally well with palette-based png or gif images.

However recent version of SDL_image added support for stb_image as way to load .png files (instead of libpng), and std_image always returns a true-color surface to PyGame, as explained in their code:

// Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.

This breaks tiletool / paltool as this mangles the pixel information from the file, and it removes the palette information from the SDL surface.

Consequently, PyGame returns different information to tiletool / paltool depending on how SDL_image is compiled (with or without stb_image). This is confusing and can't be easily avoided.

@dciabrin dciabrin self-assigned this Jun 19, 2023
@dciabrin dciabrin added the bug label Jun 19, 2023
dciabrin added a commit to dciabrin/ngdevkit-examples that referenced this issue Jun 22, 2023
When PyGame is built with support for stb_image, the latter
automatically translates paletted png to full color surfaces,
thus losing palette and pixel data.

Move all the png assets to gif, to ensure that PyGame will
always be able to load images, no matter how it is compiled
in the environment.

Ref dciabrin/ngdevkit#96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant