Skip to content

feat(screenshot): Add threaded JPEG/PNG screenshots without game stalls#1785

Open
bobtista wants to merge 37 commits into
TheSuperHackers:mainfrom
bobtista:bobtista/compressed-screenshot-f11
Open

feat(screenshot): Add threaded JPEG/PNG screenshots without game stalls#1785
bobtista wants to merge 37 commits into
TheSuperHackers:mainfrom
bobtista:bobtista/compressed-screenshot-f11

Conversation

@bobtista

@bobtista bobtista commented Nov 3, 2025

Copy link
Copy Markdown

Summary

Replaces the old BMP screenshot with compressed JPEG screenshots that don't stall the game, and adds PNG support.

Closes #1555
Closes #106 ... sort of

Adds a new screenshot function using the stb_image_write library with background threading:

  • F12 - Compressed JPEG screenshot (no stalling, ~600KB files)
  • Ctrl+F12 - Lossless PNG screenshot

Notes

  • stb_image-write is public domain licensed, single-header, zero compilation needed
  • Captures frame buffer on main thread (~1-2ms)
  • Spawns detached thread for JPEG/PNG compression and disk I/O
  • JPEG quality configurable via Options.ini (default 80)
  • Works for both Generals and Zero Hour

Testing

  • Screenshots save correctly with F12 (jpg) and Ctrl+F12 (png)
  • No game stalling during screenshot
  • Files appear in correct directory with sequential numbering
    sshot003

@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch 4 times, most recently from 20a3df1 to 37bd840 Compare November 3, 2025 04:32
@Stubbjax

Stubbjax commented Nov 3, 2025

Copy link
Copy Markdown

Some initial thoughts:

  • Keep variants of the same function to a single hotkey; instead toggle image format via a new setting in Options.ini
  • Apply image compression / quality via a new setting in Options.ini
  • Can we consolidate this logic in core instead of repeating the implementation twice?

@xezon

xezon commented Nov 3, 2025

Copy link
Copy Markdown

Agree with Stubbjax.

JPG 90 is big file. Better make it default 80.

Replace BMP screenshot with PNG screenshot. PNG is lossless compressed and always better than BMP.

Make F12 take JPG 80 screenshot. Make CTRL+F12 take PNG screenshot. Make JPG Quality adjustable.

Remove the old BMP code(s) and only use the new code for screenshot.

@xezon

xezon commented Nov 3, 2025

Copy link
Copy Markdown

Regarding Github formatting:

When you write

Addresses #1555

Then it will not close this report when this is merged.

Please read up on it here:
https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#closing-multiple-issues

@xezon xezon added Enhancement Is new feature or request Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour labels Nov 3, 2025
@L3-M L3-M added this to the GenTool features replication milestone Nov 3, 2025
@L3-M L3-M added the Input label Nov 3, 2025
@bobtista

bobtista commented Nov 3, 2025

Copy link
Copy Markdown
Author

Some initial thoughts:

  • Keep variants of the same function to a single hotkey; instead toggle image format via a new setting in Options.ini
  • Apply image compression / quality via a new setting in Options.ini
  • Can we consolidate this logic in core instead of repeating the implementation twice?

RE moving logic to core, I moved what I could to core - but there are a lot more files that need to be moved to core before this can be moved there eg WWVegas/WW3D2/*

@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch 3 times, most recently from 3535e1e to efc773f Compare November 3, 2025 17:45
Comment thread Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h Outdated
Comment thread Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch 2 times, most recently from 977a6dc to f8162f3 Compare November 3, 2025 23:07
Comment thread cmake/stb.cmake Outdated
@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch from d7e8a8d to d197bdd Compare November 5, 2025 18:04
@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch from d197bdd to 9669966 Compare November 11, 2025 21:27
@xezon

xezon commented Nov 22, 2025

Copy link
Copy Markdown

Needs rebase.

@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch from 9669966 to 4897b0b Compare November 22, 2025 18:10
@bobtista

Copy link
Copy Markdown
Author

Needs rebase.

Done

Comment thread Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DScreenshot.h Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp
Comment thread Generals/Code/GameEngine/Include/Common/MessageStream.h Outdated
Comment thread Generals/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp Outdated
Comment thread Generals/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp Outdated
Comment thread GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h Outdated
Comment thread Generals/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp Outdated
Skyaero42
Skyaero42 previously approved these changes Nov 22, 2025

@Skyaero42 Skyaero42 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch from 9c99306 to de35e57 Compare December 3, 2025 16:48
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Generals/Code/GameEngine/Include/Common/MessageStream.h Outdated
Comment thread Core/GameEngine/Source/Common/OptionPreferences.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Core/GameEngine/Source/Common/OptionPreferences.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Core/GameEngine/Source/Common/OptionPreferences.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread cmake/stb.cmake
Comment thread cmake/stb.cmake
@xezon

xezon commented Jul 13, 2026

Copy link
Copy Markdown

There are still comments left.

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a bit of effort to unslopify the AI generation 🥲


Int OptionPreferences::getJPEGQuality() const
{
OptionPreferences::const_iterator it = find("JPEGQuality");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find it written in Options Menu.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially I think it needs writing in Options Menu like our other new options. Otherwise the user has no default value written.

Comment thread Core/GameEngine/Source/Common/OptionPreferences.cpp Outdated
Comment thread Core/GameEngine/Source/Common/OptionPreferences.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking solid. The bot has a complaint.

virtual void preloadTextureAssets( AsciiString texture ) = 0; ///< preload texture asset

virtual void takeScreenShot() = 0; ///< saves screenshot to a file
virtual void takeScreenShot(ScreenshotFormat format, Int jpegQuality = 80) = 0; ///< saves screenshot in specified format

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also use DEFAULT_JPEG_QUALITY here


Int OptionPreferences::getJPEGQuality() const
{
OptionPreferences::const_iterator it = find("JPEGQuality");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially I think it needs writing in Options Menu like our other new options. Otherwise the user has no default value written.


surfaceCopy->Unlock();
surfaceCopy->Release_Ref();
surfaceCopy = nullptr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Maybe move this block below strlcpy(threadData->leafname ... so that all writes to threadData sit tightly together.

…ons save, and reuse the default quality constant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Is new feature or request Gen Relates to Generals Input Major Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add JPG/PNG Screenshot with no stalls BMP Screenshot taken with F12 can stall game significantly

9 participants