Repository navigation
fix(data, map, tiles, engine): see-through cells are left out of colour statistics and Change Detection (#1810) #1874
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
Changes from all commits
751b295
0801276
5eadd91
e6e518f
ef68f88
d7a6890
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -884,6 +884,19 @@ pub(crate) fn change_work(s: &Session, p: &Value) -> Result<super::workflows::Wo | |
| Ok(Box::new(move || { | ||
| let av = &a.bands.get(band).ok_or("no such band")?.data; | ||
| let bv = rasterops::resample_to(&bfr, band, &a)?; | ||
| // A cell either raster draws see-through has no colour to compare (#1810): the first's by | ||
| // its alpha band, the second's by its alpha band resampled onto the first's grid as its | ||
| // band is (a cell outside it, or of no alpha value, is see-through). | ||
| let a_hidden = a.see_through_cells(band); | ||
| let b_alpha = match bfr.color.alpha(bfr.band_count()) { | ||
| Some((alpha, colour)) if colour.contains(&band) => Some(rasterops::resample_to(&bfr, alpha, &a)?), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance (medium confidence): when the second raster has an alpha band and the bands are on different grids,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only when the grids differ. On one grid, |
||
| _ => None, | ||
| }; | ||
| let b_opaque = raster::alpha_max(&bfr.data_type); | ||
| let hidden = |i: usize| { | ||
| a_hidden.as_ref().is_some_and(|h| h(i)) | ||
| || b_alpha.as_ref().is_some_and(|al| al.get(i).is_none_or(|&v| raster::see_through(v, bfr.is_valid(v), b_opaque))) | ||
| }; | ||
| let n = a.width as usize * a.height as usize; | ||
| let out = rasterops::per_index( | ||
| n, | ||
|
|
@@ -892,7 +905,7 @@ pub(crate) fn change_work(s: &Session, p: &Value) -> Result<super::workflows::Wo | |
| || (), | ||
| |_, i| { | ||
| let (Some(x), Some(y)) = (av.get(i).copied(), bv.get(i).copied()) else { return NODATA }; | ||
| if !a.is_valid(x) || y == NODATA { | ||
| if !a.is_valid(x) || y == NODATA || hidden(i) { | ||
| return NODATA; | ||
| } | ||
| let v = match method.as_str() { | ||
|
|
||
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.
Performance (medium-low confidence, about 50%): the earlier concern about scanning when
whole_bytesis false is fixed by the closure. The remaining cost is for bands that do pass the cheap tests, such as Float32 colour bands whose visible values are whole bytes. Each such band is scanned in full by everyfits_bytescall, and a write calls it several times per band (plan'ssample_of, thebytesclosure atgeotiff.rs:1719, theall(...)checks atgeotiff.rs:1789and:1818, andcogwrite.rs:118). On a 100-million-cell RGBA, that is several full passes with a closure per cell.The verdict depends only on the band, so it could be worked out once: for example, a flag beside the statistics, computed in the same pass as
BandStats(where the see-through cells are already visited), sofits_bytesreads it. Not a blocker, since the output is correct.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.
Right: a Float32 colour band whose shown values are whole bytes is scanned once per
fits_bytescall, and a write makes a few of them. The output is correct, and the scan only runs for a colour band of a raster with alpha that passes the cheap tests. A flag worked out withBandStatsin the one pass would changeBand's fields, which every reader and writer builds. I've left it for the release quality pass.