Skip to content

Image casting, downsampling, and pygfx texture reuse#60

Merged
gselzer merged 16 commits intopyapp-kit:mainfrom
gselzer:pygfx-image-improvements
Apr 9, 2026
Merged

Image casting, downsampling, and pygfx texture reuse#60
gselzer merged 16 commits intopyapp-kit:mainfrom
gselzer:pygfx-image-improvements

Conversation

@gselzer
Copy link
Copy Markdown
Collaborator

@gselzer gselzer commented Mar 24, 2026

This PR adds a couple features targeted at improving the pygfx backend.

  1. Texture Downsampling - solves Displaying oversized textures #59
  2. Texture reuse - this was something we did in ndv but didn't make it here.

gselzer added 3 commits March 19, 2026 15:36
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
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 94.44444% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.33%. Comparing base (a21f6ae) to head (00cfae9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/scenex/adaptors/_pygfx/_image.py 92.72% 4 Missing ⚠️
src/scenex/adaptors/_pygfx/_volume.py 92.00% 2 Missing ⚠️
src/scenex/adaptors/_vispy/_image.py 96.36% 2 Missing ⚠️
src/scenex/model/_nodes/volume.py 90.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

gselzer and others added 6 commits April 9, 2026 15:40
@gselzer gselzer changed the title Pygfx image improvements Image casting, downsampling, and pygfx texture reuse Apr 9, 2026
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.
@gselzer gselzer linked an issue Apr 9, 2026 that may be closed by this pull request
@gselzer gselzer merged commit fb0957f into pyapp-kit:main Apr 9, 2026
36 checks passed
@gselzer gselzer deleted the pygfx-image-improvements branch April 9, 2026 21:49
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.

Displaying oversized textures

2 participants