Skip to content

Conversation

@bobtista
Copy link

@bobtista bobtista commented Nov 3, 2025

Summary

Implements compressed JPEG screenshots (F11) that don't stall the game, addressing issues with the current F12 BMP screenshot functionality.

Closes #1555

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

  • F11 - New compressed JPEG screenshot (no stalling, ~600KB files)
  • F12 - Original BMP screenshot (still works if lossless needed)

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 compression and disk I/O
  • Uses std::shared_ptr for safe memory management across threads
  • JPEG quality set to 90 (excellent quality, 10x compression)
  • Works for both Generals and Zero Hour

Testing

  • Screenshots save correctly with both F11(jpg) and F12(original bmp)
  • No game stalling during screenshot with F11
  • Files appear in correct directory with sequential numbering
    sshot003

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

Stubbjax commented Nov 3, 2025

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
Copy link

xezon commented Nov 3, 2025

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
Copy link

xezon commented Nov 3, 2025

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
Copy link
Author

bobtista commented Nov 3, 2025

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 2 times, most recently from 15c379c to 3535e1e Compare November 3, 2025 17:38
@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch from 3535e1e to efc773f Compare November 3, 2025 17:45
}
}
{
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_TAKE_SCREENSHOT_PNG);

Choose a reason for hiding this comment

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

Will this cause a key conflict as F12 is already in use.
Or is it the intention to take both JPG and PNG screenshots?

Copy link
Author

Choose a reason for hiding this comment

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

The intention is to use ctrl + f12 for png and f12 for jpg, though to your point, maybe the regular f12 should be png as it's lossless?

Copy link

Choose a reason for hiding this comment

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

Regular F12 for PNG would be more in line with lossless BMP, HOWEVER, most players will want to take JPG screenshots first because these will compress much smaller and are far better for archiving and sending around the internet.

PNG screenshots are more for artists that want to create artwork and similar.

Copy link
Author

Choose a reason for hiding this comment

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

Ok I went with F12: JPG and CTRL+F12: PNG

@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch from ead7d4e to 977a6dc Compare November 3, 2025 23:03
@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch from 977a6dc to f8162f3 Compare November 3, 2025 23:07
cmake/stb.cmake Outdated
FetchContent_Declare(
stb
GIT_REPOSITORY https://github.com/nothings/stb.git
GIT_TAG master # Could pin to specific commit for stability

Choose a reason for hiding this comment

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

I think pinning to a specific tag or commit is the way forward, otherwise you risk changes to upstream breaking the build, supply chain attacks and such.

Some efforts have been made to move dependencies to vcpkg which might be a better approach. At the very least I'd suggest adding a find command to try and find the module first (from vcpkg or alternatively package managers), then fall back on the fetch content method if not found?

Copy link
Author

Choose a reason for hiding this comment

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

Done

@bobtista bobtista force-pushed the bobtista/compressed-screenshot-f11 branch from d7e8a8d to d197bdd Compare November 5, 2025 18:04
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

6 participants