Skip to content

Conversation

ankith26
Copy link
Contributor

@ankith26 ankith26 commented Jun 3, 2025

fixes libsdl-org/sdl2-compat#492

While I was investigating that issue I realised that this must actually be fixed on the SDL_image end and not sdl2-compat end as I initially assumed.

This PR makes the stbimage backend path more like the libpng backend:

  • If a colorkey is set along with a palette, the colorkey entry shouldn't have redundant pixel alpha of 0 as that messes up the SDL_MapRGB logic.
  • The stbimage backend always gives 256 entries in the palette, even if less entries are required. It seems like stb image does not expose this information in its API. I have put a bit of a hacky solution to this issue. It's certainly not very efficient but is the easiest approach I could think of.

@ankith26
Copy link
Contributor Author

ankith26 commented Jun 3, 2025

If this PR is accepted I can remake this PR against main/SDL3

@slouken
Copy link
Collaborator

slouken commented Aug 1, 2025

Iterating over all the pixels to find the highest index is relatively expensive. Is there a change to stb_image that we can make, to retain the correct palette size?

@ankith26
Copy link
Contributor Author

ankith26 commented Aug 2, 2025

Is there a change to stb_image that we can make, to retain the correct palette size?

I'm not aware how to do this rn. My assumption here is that its very unlikely to have an 8 bit image that is also very large, so I think the added complexity should be okay-ish.

@ankith26 ankith26 force-pushed the ankith26-stb-palette branch from a9cda7b to f69c0ec Compare August 28, 2025 04:23
@slouken slouken merged commit 071d724 into libsdl-org:SDL2 Aug 28, 2025
8 checks passed
@slouken
Copy link
Collaborator

slouken commented Aug 28, 2025

Merged, thanks!

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

Successfully merging this pull request may close these issues.

2 participants