Skip to content

SDL2_image: use libjpeg and libpng instead of stb_image - #462

Closed
s09bQ5 wants to merge 1 commit into
flathub:masterfrom
s09bQ5:sdl2-image-no-stb
Closed

s09bQ5 wants to merge 1 commit into
flathub:masterfrom
s09bQ5:sdl2-image-no-stb

Conversation

@s09bQ5

@s09bQ5 s09bQ5 commented May 10, 2026

Copy link
Copy Markdown

stb_image is a public domain implementation of several image decoders in a single C header file. SDL2_image includes a copy of it and uses it by default for JPEG and PNG. A comment in stb_image says

"Primarily of interest to game developers and other people who can
avoid problematic images and only need the trivial interface"

Since the flatpak runtimes generally do include libjpeg and libpng, there is no reason to use a possibly limited implementation. It probably also receives less security testing than the de-facto standard libraries.

stb_image is a public domain implementation of several image decoders in
a single C header file. SDL2_image includes a copy of it and uses it by
default for JPEG and PNG. A comment in stb_image says

  "Primarily of interest to game developers and other people who can
   avoid problematic images and only need the trivial interface"

Since the flatpak runtimes generally do include libjpeg and libpng, there
is no reason to use a possibly limited implementation. It probably also
receives less security testing than the de-facto standard libraries.
@tothxa

tothxa commented May 11, 2026

Copy link
Copy Markdown
Collaborator

I don't really know what to think about this. Maybe I'm too old, but "limited implementation with trivial interface" sounds like the essence of security to me. (but I can't judge the actual code myself)

As for its limits: We use somewhat esoteric PNGs to save space (indexed colours with separate full alpha) that most image editors can't edit and save properly, but they work just fine with the current SDL2-image builds.

And SDL itself is "Primarily of interest to game developers". :)

@tothxa

tothxa commented May 11, 2026 •

Copy link
Copy Markdown
Collaborator

@s09bQ5 I've just read your linked comment. Have you tried building UltraStarDeluxe with including the current manifest? If so, are you aware of any actual image files that didn't work with that build?

@s09bQ5

s09bQ5 commented May 12, 2026

Copy link
Copy Markdown
Author

Our game requires users to add content, so we don't have any control over the images.

@LaxentaInc

This comment was marked as spam.

@orowith2os

Copy link
Copy Markdown
Member

Reopen/ask to reopen if this is still relevant. The linked PR that this was made for seems to vendor SDL2_image now, and is quite possibly an exception to the use case here?

@orowith2os orowith2os closed this Oct 21, 2026
@user1-github

user1-github commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Recently I've been researching this myself, so it seems the only benefit in using stb_image over native libjpeg and libpng is simply convenience and if someone just wants to minimize reliance on external libraries. For example, it might be useful for proprietary games that bundle their own version of SDL2_image.

Otherwise, using native libjpeg and libpng will only give you technical advantages, not only due to security, but also due to improved performance, as they're faster than stb_image, so games might experience some improvements in loading times when loading large amount of images for example.

Besides, I've also seen more upstream bug reports with stb_image usage and all major distros disable it in their SDL2_image package.

So I think it wouldn't hurt to re-open and merge this.

@tothxa

tothxa commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Could you please provide some links? Especially the mentioned bug reports, but also about the performance and distro package definitions, and if available, about the reasons why they do it. (I guess debian and redhat/fedora may do it at least in part because of their policy against vendoring.)

I'm not against this, I'd just like to make an informed decision.

@user1-github

user1-github commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

I researched it about 2 weeks ago, so I don't have most of the links with me from which I acquired this info, as it was in various places. I'll share whatever I have now or have recently found:

As for bug reports, here is one: libsdl-org/SDL_image#294.
Github has this annoying issue when issues and PRs randomly disappear from repos, so can't find the others.
But you shouldn't worry about the stb_image bug reports, as they were fixed from what I remember, I just mentioned them because I found only 1 bug report regarding usage of SDL2_image with libpng.

Here is another issue asking why stb_image is the default: libsdl-org/SDL_image#302 mentioning some of the downsides that I mentioned, plus the fact that it supports less formats.

Here are some benchmarks showing that libjpeg and libpng are mostly faster: https://gudoshnikovn.github.io/libphash/benchmarks/2026-10-04-decoders-vs-stb

And here are the distro packages:
OpenSUSE: https://build.opensuse.org/projects/openSUSE:Factory/packages/SDL2_image/files/SDL2_image.spec
Fedora: https://src.fedoraproject.org/rpms/SDL2_image/blob/rawhide/f/SDL2_image.spec#_51
Debian: https://salsa.debian.org/sdl-team/libsdl2-image/-/blob/debian/latest/debian/rules?ref_type=heads#L21
Arch: https://gitlab.archlinux.org/archlinux/packaging/packages/sdl2_image/-/blob/main/PKGBUILD?ref_type=heads#L22

I haven't found any info about distro decision making regarding adding --disable-stb-image.

P.S, here is another bug report for NixOS, requesting disabling stb_image. It's about SDL3_image, but it mentions the downsides of stb_image: NixOS/nixpkgs#400074

@orowith2os

orowith2os commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

I can merge a PR to ues libjpeg and libpng if somebody makes one. (given author here has not responded yet)

@user1-github

user1-github commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Opened a new PR. I should be able to merge this myself, as I'm also a SDL2 codeowner, though I'll first see how @tothxa (the other codeowner) will respond. It seems they also need to approve the new PR.

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.

5 participants