Skip to content

Use stb_image_write to save PNG screenshots#289

Closed
oznogon wants to merge 2 commits into
daid:masterfrom
oznogon:screenshot-stb
Closed

Use stb_image_write to save PNG screenshots#289
oznogon wants to merge 2 commits into
daid:masterfrom
oznogon:screenshot-stb

Conversation

@oznogon

@oznogon oznogon commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Add the stb_image_write header-only library to write a screenshot to a PNG file on a background thread. Add Window::saveScreenshotToFile(w,h) function and screenshot_key keybinding.

This allows for a few advantages over OS screenshot capabilities:

  • Works when rendering via KMSDRM
  • No OS chrome, drop shadows, etc. in screenshots; this saves only what's in the framebuffer
  • Should work per-window, but no multi-monitor setup to test behavior on

If the additional vendored lib is undesirable, this could be implemented without stb_image_write to save uncompressed TGA or BMP screenshots, but the sizes of them would be dramatically larger (about 9MB on a display of 2.7k pixels vs. ~700-900kb PNG).

stb_image_write is monkey patched to avoid CI failing on -Wextra warnings from nothings/stb#1099.

nothings comment from 2021 on issue 1099:

Our general rule has been that it's not generally worth fixing stuff that only shows up with -Wextra, but that's because fixes aren't always straightforward and can even conflict. In this case, since there's a straightforward way to fix it, and given that it seems unlikely clang is going to change it's mind about warning for this, I would accept a PR fixing it.

Upstream PR nothings/stb#1311 (2022, still open) implements this change.

Add the stb_image_write header-only library to write a screenshot
to a PNG file on a background thread. Add
Window::saveScreenshotToFile(w,h) function and screenshot_key
keybinding.

This allows for a few advantages over OS screenshot capabilities:

- Works when rendering via KMSDRM
- No OS chrome, drop shadows, etc. in screenshots; this saves
  only what's in the framebuffer
- Should work per-window, but no multi-monitor setup to test
  behavior on

If the additional vendored lib is undesirable, this could be
implemented without stb_image_write to save uncompressed TGA or
BMP screenshots, but the sizes of them would be dramatically
larger (about 9MB on a display of 2.7k pixels vs. ~700-900kb PNG).
@daid

daid commented Mar 19, 2026

Copy link
Copy Markdown
Owner

I'm wondering if I'm fine with this or rather have it as part of the Image class as in SP2: https://github.com/daid/SeriousProton2/blob/master/src/graphics/image.cpp#L132

@oznogon oznogon closed this Apr 12, 2026
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