Repository navigation
fix: honor mask/alpha bands and mask RGB nodata only when all bands match - #16
Merged
Merged
Conversation
…atch - RGB: a pixel is nodata only when all three bands equal the nodata value (tag or override). One band that happens to equal it -- pure red, deep shadow -- is data. NaN in any band still masks. - RGB and single-band: honor a per-dataset mask band or alpha band (GDAL internal masks, GIS exports). Nodata tags are still handled as before, so a nodata override keeps replacing the tag. - RGB stretch: zero masked pixels before the uint8 cast so NaN never reaches it (was undefined behavior, hidden by alpha). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
_process_rgbtreats a pixel as nodata when any of its three bands equals the nodata value. In a file taggednodata=0, that punches holes in valid pixels that happen to have one zero channel: pure red (255, 0, 0), deep shadows, saturated composites. A fill value fills every band, so the rule should require all three.Neither
_process_rgbnor_process_singlebandreads the file's mask band or alpha band. Only the nodata tag and NaN are used, so GeoTIFFs that mark empty pixels with a GDAL internal mask or an alpha band (common in GIS exports) draw those pixels opaque.Changes
nodataoverride). NaN in any band still masks, since that pixel has no color to draw.read_masks. Nodata tags are handled exactly as before, so anodataoverride still replaces the tag. Files without a mask render as they did.astype(np.uint8)(undefined behavior, hidden by the alpha channel, but it raisedRuntimeWarning: invalid value encountered in cast).Behavior change to note: a file that has both a nodata tag and a mask band now hides the union of the two.
Testing
server/tests/test_geotiff_masking.py(7 tests): pure red and shadow pixels stay opaque undernodata=0, all-zero fill is hidden, the override uses the same rule, NaN in one band masks, internal mask and alpha band are honored, and a file with no tag or mask is fully opaque. 5 of the 7 fail on currentmain.mainlocally: most tests error withStreamableHTTPSessionManager .run() can only be called once per instancefrom the MCP test fixtures, which is unrelated to this change. No existing test coversgeotiff_service.py.🤖 Generated with Claude Code