Image casting, downsampling, and pygfx texture reuse#60
Image casting, downsampling, and pygfx texture reuse#60gselzer merged 16 commits intopyapp-kit:mainfrom
Conversation
The dimensions were inverted, and I just had no tests that were checking for situations where image width was not equal to image height
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #60 +/- ##
==========================================
+ Coverage 88.13% 88.33% +0.19%
==========================================
Files 62 62
Lines 2950 3060 +110
==========================================
+ Hits 2600 2703 +103
- Misses 350 357 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR improves image/volume handling for GPU backends (primarily pygfx, with parallel updates for vispy) by coercing texture inputs to backend-compatible shapes/dtypes, downsampling oversized textures, and reusing textures where possible.
Changes:
- Add dtype downcasting and max-texture-size downsampling paths for vispy and pygfx adaptors.
- Add pygfx texture reuse on same-shape/dtype updates (and recreate on incompatible changes).
- Update model bounding box/transform expectations and expand tests to cover new behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/scenex/model/_nodes/image.py |
Updates bounding box computation to align with (Y, X) image axis conventions. |
src/scenex/model/_nodes/volume.py |
Removes custom bounding box override and adjusts volume ray intersection shape unpacking. |
src/scenex/adaptors/_vispy/_image.py |
Introduces _coerce_data (downcast/downsample) and transform compensation for downsampled uploads. |
src/scenex/adaptors/_vispy/_volume.py |
Uses _coerce_data for volume uploads and adds transform compensation factors. |
src/scenex/adaptors/_pygfx/_image.py |
Adds _coerce_data, downsampling, and texture reuse logic for images. |
src/scenex/adaptors/_pygfx/_volume.py |
Adds _coerce_data, downsampling, and texture reuse logic for volumes. |
tests/model/_nodes/test_image.py |
Updates image bounding box test for non-square (Y, X) data. |
tests/model/_nodes/test_volume.py |
Updates volume bounding box test for non-square (Z, Y, X) data. |
tests/adaptors/_vispy/test_image.py |
Adds tests for oversize downsampling and dtype downcasting. |
tests/adaptors/_vispy/test_volume.py |
Adds tests for oversize downsampling and dtype downcasting. |
tests/adaptors/_pygfx/test_image.py |
Adds tests for oversize downsampling and texture reuse/recreation behavior. |
tests/adaptors/_pygfx/test_volume.py |
Adds tests for oversize downsampling and texture reuse/recreation behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Allows for better handling of RGB images
And don't do it in the vispy node ctor :)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This should better match user intent. If you have negative data, you probably don't want it clamped to zero or wrapped around. You probably still want it to show up as the same/lighter than zero on the canvas.
This PR adds a couple features targeted at improving the pygfx backend.