set_overlay_mask was unusable in tile mode — no mask shape could be drawn - #56
Merged
Conversation
In tile mode NO mask shape could be drawn. The renderer sizes the overlay
against `base_width || image_width` -- the OVERVIEW grid -- but `enable_tile`
sets `image_width`/`image_height` to the FULL native frame, and the shape check
compared only against those. So:
* an overview-sized mask (what the renderer wants) raised ValueError here;
* a full-resolution mask was accepted, encoded, and then silently discarded
by the renderer (`mBytes.length===iw*ih` else `maskCache=null` -- no error,
no overlay, nothing in any log).
Measured on a 4096x4096 tiled plot: the first raised, the second shipped 22.4 MB
of base64 the renderer dropped on the floor. A caller could not get this right,
because there was no right answer.
Both shapes are now accepted and a full-resolution mask is reduced to the
overview grid before encoding, so the same call works tiled or not and ships
1.4 MB instead of 22.4 MB.
The reduction is a block ANY (`_reduce_mask_any`), never a subsample: a mask
marks WHERE OBJECTS ARE, and objects a few pixels across must not vanish
because the sampled pixel missed them -- striding 4096 -> 1024 keeps one pixel
in sixteen. The uneven tail rows/columns fold into the last block rather than
being cropped, so an object at the right or bottom edge survives too.
Two tests, both asserting the bytes that actually SHIP rather than the array
handed in: either input shape ships exactly `base_width*base_height` bytes and
stays non-empty, and a single lit pixel off a block boundary survives the
reduction.
2002 passed, 58 skipped.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56 +/- ##
==========================================
- Coverage 90.77% 90.74% -0.04%
==========================================
Files 40 40
Lines 4500 4526 +26
==========================================
+ Hits 4085 4107 +22
- Misses 415 419 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In tile mode there was no mask shape that worked. The renderer sizes the
overlay against
base_width || image_width— the OVERVIEW grid — butenable_tilesetsimage_width/image_heightto the FULL native frame, andthe shape check compared only against those:
ValueErrorhere;by the renderer —
mBytes.length===iw*ihelsemaskCache=null. No error, nooverlay, nothing in any log.
A caller could not get this right, because there was no right answer.
Measured, on a 4096×4096 tiled plot
Both shapes are accepted now, and a full-resolution mask is reduced to the
overview grid before encoding — so the same call works tiled or not, and ships
1.4 MB instead of 22.4 MB.
Why block ANY and not a subsample
A mask marks where objects are. Objects a few pixels across must not vanish
because the sampled pixel missed them, and striding 4096 → 1024 keeps one pixel
in sixteen.
_reduce_mask_anyfolds the uneven tail rows/columns into the lastblock rather than cropping them, so an object at the right or bottom edge
survives too.
What it looks like
Found via SpyDE, whose segmentation overlay is a mask on a tiled 4096² frame.
Before, the overlay simply never appeared — the preview reports thousands of
instances and the figure shows none of them:
Tests
Two, both asserting the bytes that actually ship rather than the array
handed in — which is the shape of assertion that would have caught this:
base_width*base_heightbytes and thereduced mask is non-empty;
(a subsample would drop it).
2002 passed, 58 skippedon the full suite.Note for downstream
SpyDE's
_set_raster_overlaydid its own overview reduction to work aroundthis and got the
ValueErrorfor its trouble. It now hands over the nativemask and lets this own the arithmetic, so there is one owner and it cannot
disagree with the shape check beside it. That companion change is in
CSSFrancis/spyde
feat/drift-particles.