Skip to content

Support both stb_image_resize.h and stb_image_resize2.h#2130

Open
taylorhoward92 wants to merge 1 commit into
ValveSoftware:masterfrom
taylorhoward92:stb-image-resize2-compat
Open

Support both stb_image_resize.h and stb_image_resize2.h#2130
taylorhoward92 wants to merge 1 commit into
ValveSoftware:masterfrom
taylorhoward92:stb-image-resize2-compat

Conversation

@taylorhoward92
Copy link
Copy Markdown

@taylorhoward92 taylorhoward92 commented Apr 7, 2026

Uses __has_include to detect which stb image resize header is available and conditionally use the appropriate API. This allows building against both old stb (which provides stb_image_resize.h) and new stb (which replaced it with stb_image_resize2.h).

The newer versions of the nothings/stb repository moved stb_image_resize.h to deprecated/ and replaced it with stb_image_resize2.h. This change adds compatibility so gamescope can build against either version.

This is intended to be used in combination with #1846 when needed by Linux distributions (e.g. NixOS) that use a system-level stb package rather than the vendored subproject.

API mapping:

  • stbir_resize_uint8stbir_resize_uint8_linear (the non-gamma-corrected variant; stbir_resize_uint8_srgb is the gamma-aware one)
  • stbir_resize_uint8_srgb parameters (num_channels=4, alpha_channel=3, STBIR_FLAG_ALPHA_PREMULTIPLIED) → single stbir_pixel_layout enum STBIR_RGBA_PM

Use __has_include to detect which stb image resize header is available
and conditionally use the appropriate API. This allows building against
both old stb (which provides stb_image_resize.h) and new stb (which
replaced it with stb_image_resize2.h).

API mapping:
- stbir_resize_uint8 -> stbir_resize_uint8_linear (non-gamma-corrected)
- stbir_resize_uint8_srgb params (num_channels, alpha_channel, flags)
  collapsed into single stbir_pixel_layout enum (e.g. STBIR_RGBA_PM)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
taylorhoward92 pushed a commit to taylorhoward92/nixpkgs that referenced this pull request Apr 7, 2026
Pulls in a pending upstream patch (ValveSoftware/gamescope#2130) that
supports both the old stb_image_resize.h and the new stb_image_resize2.h
using __has_include for compile-time detection. This prepares gamescope
for the upcoming stb update (NixOS#491159) which removes
stb_image_resize.h in favor of stb_image_resize2.h.

Tested against both old stb (0-unstable-2023-01-29) and new stb
(0-unstable-2025-10-25) on x86_64-linux and aarch64-linux.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@taylorhoward92 taylorhoward92 marked this pull request as ready for review April 7, 2026 19:20
@oSoMoN
Copy link
Copy Markdown

oSoMoN commented Apr 29, 2026

@misyltoad is there a reason for not bumping the stb subproject to a more recent commit instead, and include only the new header?

It is currently pointing to nothings/stb@5736b15, which is 3 years old, so presumably a newer version wouldn't hurt.

samestep pushed a commit to samestep/nixpkgs that referenced this pull request May 15, 2026
Pulls in a pending upstream patch (ValveSoftware/gamescope#2130) that
supports both the old stb_image_resize.h and the new stb_image_resize2.h
using __has_include for compile-time detection. This prepares gamescope
for the upcoming stb update (NixOS#491159) which removes
stb_image_resize.h in favor of stb_image_resize2.h.

Tested against both old stb (0-unstable-2023-01-29) and new stb
(0-unstable-2025-10-25) on x86_64-linux and aarch64-linux.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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