-
-
Notifications
You must be signed in to change notification settings - Fork 201
Fix failing tests on non-libpng backends #3570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughAdds a post-load vendor fix to preserve opaque alpha for color-key entries on indexed surfaces, adds an environment-driven skip flag for two PNG save tests, and relaxes a palette equality assertion to compare only the first two entries. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Py as image_load_ext
participant IMG as SDL_image loader
participant S as SDL_Surface
Note over Py: Load image into SDL_Surface
Py->>IMG: IMG_Load(path/bytes)
IMG-->>Py: SDL_Surface* (S)
alt Surface format is indexed
Py->>S: Get color key (SDL_GetSurfaceColorKey / SDL_GetColorKey)
alt valid color key and palette exists
Py->>S: Get palette (SDL_GetPaletteColors / similar)
Note right of Py: Clone palette entry at index, set .a = SDL_ALPHA_OPAQUE
Py->>S: SDL_SetPaletteColors(updated entry)
else no valid color key or no palette
Note over Py: No palette alpha fix
end
else Non-indexed format
Note over Py: No post-fix applied
end
Py-->>Py: Wrap SDL_Surface into Python object
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
test/surface_test.py (1)
1231-1235
: LGTM; reduce brittleness across PNG backendsRelaxing to the first two palette entries makes this test portable with non-libpng loaders. Consider adding a brief comment to document the rationale.
Apply this diff to add clarity:
im2 = pygame.image.load(example_path(os.path.join("data", "brick.png"))) - - self.assertEqual( + # Only validate the first two entries; remaining palette entries can + # vary across PNG backends (e.g., system SDL_image vs. libpng). + self.assertEqual( im.get_palette()[:2], ((0, 0, 0, 255), (255, 255, 255, 255)) ) self.assertEqual(im2.get_palette()[:2], ((0, 0, 0, 255), (0, 0, 0, 255)))test/image_test.py (2)
206-210
: LGTM; skip PNG24 save test with system deps to avoid non-libpng discrepanciesThis aligns the suite with environments where SDL_image may use a different PNG backend.
Optional: introduce a module-level flag to avoid repeating the env check:
@@ _sdl_image_ver = pygame.image.get_sdl_image_version() @@ sdl_image_svg_jpeg_save_bug = ( _sdl_image_ver <= (2, 0, 5) and pygame.get_sdl_byteorder() == pygame.BIG_ENDIAN ) +USING_SYSTEM_DEPS = "PG_DEPS_FROM_SYSTEM" in os.environ @@ -@unittest.skipIf( - "PG_DEPS_FROM_SYSTEM" in os.environ, +@unittest.skipIf( + USING_SYSTEM_DEPS, "If we are using system dependencies, we don't know the backend used " "for PNG saving, and this test only works with libpng.", )For changes outside this hunk (adding USING_SYSTEM_DEPS), insert:
USING_SYSTEM_DEPS = "PG_DEPS_FROM_SYSTEM" in os.environnear the other module-level feature flags.
246-250
: LGTM; skip PNG8 save test with system deps for the same reasonConsistent with PNG24 handling and existing PaletteAsPNG8 skip below.
If you add USING_SYSTEM_DEPS as suggested above, mirror it here:
-@unittest.skipIf( - "PG_DEPS_FROM_SYSTEM" in os.environ, +@unittest.skipIf( + USING_SYSTEM_DEPS, "If we are using system dependencies, we don't know the backend used " "for PNG saving, and this test only works with libpng.", )
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
src_c/imageext.c
(1 hunks)test/image_test.py
(2 hunks)test/surface_test.py
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src_c/imageext.c (1)
src_c/_pygame.h (1)
PG_GetSurfacePalette
(249-253)
test/surface_test.py (1)
buildconfig/stubs/pygame/surface.pyi (1)
get_palette
(588-598)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: x86_64
- GitHub Check: arm64
- GitHub Check: Debian (Bookworm - 12) [s390x]
- GitHub Check: Debian (Bookworm - 12) [armv7]
- GitHub Check: Debian (Bookworm - 12) [ppc64le]
- GitHub Check: Debian (Bookworm - 12) [armv6]
- GitHub Check: debug_coverage (ubuntu-24.04, 3.9.23)
- GitHub Check: msys2 (mingw64, x86_64)
- GitHub Check: debug_coverage (ubuntu-24.04, 3.14.0rc1)
- GitHub Check: i686
- GitHub Check: x86_64
- GitHub Check: aarch64
- GitHub Check: msys2 (clang64, clang-x86_64)
- GitHub Check: msys2 (ucrt64, ucrt-x86_64)
- GitHub Check: AMD64
- GitHub Check: debug_coverage (ubuntu-24.04, 3.13.5)
- GitHub Check: x86
- GitHub Check: build (ubuntu-24.04)
- GitHub Check: build (ubuntu-22.04)
- GitHub Check: dev-check
b46fa7d
to
570bd98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested or anything, but the code makes sense.
These changes are relevant for when SDL_image isn't using the libpng backend (so not really relevant for our release builds, but useful for when we compiled against system SDL_image on some linux distro like fedora)
precursor to #3562 and SDL3 runtime support work considering we don't use libpng backend on those builds as of now.